Skip to content

Account for values on both size of 360#25

Merged
bsudekum merged 3 commits into
masterfrom
exit-angle
Jan 24, 2017
Merged

Account for values on both size of 360#25
bsudekum merged 3 commits into
masterfrom
exit-angle

Conversation

@bsudekum
Copy link
Copy Markdown
Contributor

Ran into a situation today where the maneuver final heading was 358 degrees and the user heading never crossed from 0 to 35x (the user heading remained around 4 which is an acceptable heading for this example). Thus, the difference between the user heading and the final heading was ~354 degrees.

This change normalizes the difference between the user and final heading further.

@bsudekum bsudekum requested a review from 1ec5 January 24, 2017 01:20
Comment thread MapboxNavigation/RouteController.swift Outdated
let finalHeadingNormalized = wrap(finalHeading, min: 0, max: 360)
let userHeadingNormalized = wrap(location.course, min: 0, max: 360)
courseMatchesManeuverFinalHeading = abs((finalHeadingNormalized - userHeadingNormalized) - 360) <= RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion
courseMatchesManeuverFinalHeading = abs((finalHeadingNormalized - userHeadingNormalized)) <= RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion || abs((finalHeadingNormalized - userHeadingNormalized) - 360) <= RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case where the user heading is zero and the final heading is zero, without this ||, this would be false

Comment thread MapboxNavigation/RouteController.swift Outdated
let finalHeadingNormalized = wrap(finalHeading, min: 0, max: 360)
let userHeadingNormalized = wrap(location.course, min: 0, max: 360)
courseMatchesManeuverFinalHeading = abs(finalHeadingNormalized - userHeadingNormalized) <= RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion
courseMatchesManeuverFinalHeading = abs((finalHeadingNormalized - userHeadingNormalized)) <= RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion || abs((finalHeadingNormalized - userHeadingNormalized) - 360) <= RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion
Copy link
Copy Markdown
Contributor

@1ec5 1ec5 Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually, you want to determine the difference between two angles, then check that difference against a threshold. There are some great solutions in http://stackoverflow.com/questions/1878907/the-smallest-difference-between-2-angles and http://stackoverflow.com/questions/12234574/calculating-if-an-angle-is-between-two-angles that are provably correct. Some use the % operator, while others use trigonometric functions. (If you go the trigonometric route, note that the trigonometric functions in Swift expect arguments in radians, not degrees.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you break this out into a standalone function in Geometry.swift, here’s a test suite you can port to Swift: https://gist.github.com/bradphelan/7fe21ad8ebfcb43696b8.

@bsudekum bsudekum merged commit 08a24b3 into master Jan 24, 2017
@bsudekum bsudekum deleted the exit-angle branch January 24, 2017 17:39
*/
func smallestAngle(alpha: Double, beta: Double) -> Double {
let phi = abs(beta - alpha).truncatingRemainder(dividingBy: 360);
return phi > 180 ? 360 - phi : phi;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lose the semicolons.

/*
Returns the smallest angle between two angles
*/
func smallestAngle(alpha: Double, beta: Double) -> Double {
Copy link
Copy Markdown
Contributor

@1ec5 1ec5 Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name this function differenceBetweenDirections(_:_:). Also, use CLLocationDirection instead of Double, so it’s clear that the function takes degree measurements, not radians.

wishtrip-dev pushed a commit to wishtrip-dev/mapbox-navigation-ios that referenced this pull request Feb 28, 2018
MaximAlien added a commit that referenced this pull request Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants