Skip to content

Commit

Permalink
Fix issue with map spinning when setting destBearing and sourceBearin…
Browse files Browse the repository at this point in the history
…g to 102 (#1793) (#1828)

Co-authored-by: Niwaka <61189782+NiwakaDev@users.noreply.github.com>
  • Loading branch information
pjleonard37 and NiwakaDev committed Jan 17, 2023
1 parent 6fba662 commit b142b50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Sources/MapboxMaps/Foundation/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ internal struct Utils {

if fabs(angle - (Double.pi * 2) - anchorAngle) < diff {
angle -= (Double.pi * 2)
}

if fabs(angle + (Double.pi * 2) - anchorAngle) < diff {
} else if fabs(angle + (Double.pi * 2) - anchorAngle) < diff {
angle += (Double.pi * 2)
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/MapboxMapsTests/Foundation/UtilsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ class UtilsTests: XCTestCase {
XCTAssert(wrappedValue == 45.0)
}

func testNormalizeWithSameDegree() throws {
for bearing in (0..<361).map({Double($0)}) {
let destBearing = -Utils.normalize(angle: -bearing.toRadians(), anchorAngle: CLLocationDirection(floatLiteral: bearing).toRadians()).toDegrees()
let sourceBearing = Utils.normalize(angle: CLLocationDirection(floatLiteral: bearing).toRadians(), anchorAngle: destBearing.toRadians()).toDegrees()
let epsilon = 0.0001
XCTAssertEqual(destBearing, sourceBearing, accuracy: epsilon, "bearing: "+bearing.description)
}
}
}

0 comments on commit b142b50

Please sign in to comment.