-
Notifications
You must be signed in to change notification settings - Fork 0
FEAT-3: change direction labels to use 16-point compass rose directions #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -170,7 +154,7 @@ function generateCurrentConditions(weatherData) { | |||
} | |||
}) | |||
|
|||
const windCompass = compassPoints[Math.round(rawConditions.wind_direction_10m / 11.25)] | |||
const windCompass = compassPoints[Math.round(rawConditions.wind_direction_10m / 22.5)] | |||
currentConditions['wind_compass'] = windCompass[0] | |||
currentConditions['wind_compass_short'] = windCompass[1] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch seems to reduce the points in the compass representation from a 32-point system to a 16-point system. However, this modification introduces potential issues:
- Array Index Out of Bounds: The wind direction calculation is changed from
Math.round(rawConditions.wind_direction_10m / 11.25)
toMath.round(rawConditions.wind_direction_10m / 22.5)
. This changes the scale so it will potentially result in index values higher than the size of the newcompassPoints
array. With the old 32-point scale, you would get index values ranging from 0 up to 31. With the new 16-point scale, the maximum would be around 16 which is out of bounds forcompassPoints
, considering indices range from 0 to 15.
To fix this issue, a careful redesign of the wind direction calculation might be needed, keeping in mind that the wind direction varies from 0-360 degrees. For example, code could use something like Math.floor(rawConditions.wind_direction_10m / 22.5) % 16
.
- Breaking Changes: Besides, it's possible these changes can cause breaking changes elsewhere where other functions or services are expecting the original 32-point compass data and not the new simplified version. This may impact any feature depending on specific compass point callbacks such as 'North by West', etc., which have been removed.
To resolve this, it would be advised to conduct a thorough utilization analysis of the compassPoints
array and its dependent features across the entire codebase.
@@ -170,7 +154,7 @@ function generateCurrentConditions(weatherData) { | |||
} | |||
}) | |||
|
|||
const windCompass = compassPoints[Math.round(rawConditions.wind_direction_10m / 11.25)] | |||
const windCompass = compassPoints[Math.round((rawConditions.wind_direction_10m - 11.25) / 22.5)] | |||
currentConditions['wind_compass'] = windCompass[0] | |||
currentConditions['wind_compass_short'] = windCompass[1] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch reduces the compass points from a 32-point system to a 16-point system—reducing the granularity of wind direction data. Here are the potential issues:
-
Index Out Of Range: The change in lines from
const windCompass = compassPoints[Math.round(rawConditions.wind_direction_10m / 11.25)]
toconst windCompass = compassPoints[Math.round((rawConditions.wind_direction_10m - 11.25) / 22.5)]
may result in an "index out of range" exception or error. This will happen whenrawConditions.wind_direction_10m
is less than 11.25, because the index returned can be-1
, and there's nocompassPoints[-1]
. -
Underflow Error: When
rawConditions.wind_direction_10m
(direction) subtracts 11.25, if the direction is less than 11.25, this could potentially have unintended side effects or even lead to an underflow error. -
Loss of Precision: Reducing the compass points from 32 to 16 results in a loss of precision for determining wind direction.
Suggestions:
- Adding boundary-checking code before attempting to access the array can help avoid exception errors.
- The equation should handle cases where
wind_direction_10m
is less than 11.25 properly. - Stick to the 32-point compass system if that level of precision in wind direction information is needed.
No description provided.