@@ -26,94 +26,44 @@ import kotlin.test.assertEquals
2626import kotlin.test.assertTrue
2727
2828class PlaceDirectionTest {
29-
29+
3030 @Test
3131 fun `test pitch snapping for East direction` () {
3232 val direction = PlaceDirection .East
33-
34- // Calculate expected pitch boundary for East at yaw -90.0
35- val yawRad = Math .toRadians(- 90.0 )
36- val expectedBoundary = Math .toDegrees(atan(abs(sin(yawRad))))
37-
38- // Test rotation outside the area (pitch too high)
39- val rotationOutsideHigh = Rotation (- 90.0 , expectedBoundary + 10.0 )
40- val snappedHigh = direction.snapToArea(rotationOutsideHigh)
41-
42- // Test rotation outside the area (pitch too low)
43- val rotationOutsideLow = Rotation (- 90.0 , - expectedBoundary - 10.0 )
44- val snappedLow = direction.snapToArea(rotationOutsideLow)
45-
33+ val rot = Rotation (- 90.0 , 90.0 )
34+ val snapped = direction.snapToArea(rot)
35+
4636 // Verify that the pitch is snapped to the boundary
47- assertEquals(expectedBoundary, snappedHigh.pitch, 0.001 , " Pitch should be snapped to the upper boundary" )
48- assertEquals(- expectedBoundary, snappedLow.pitch, 0.001 , " Pitch should be snapped to the lower boundary" )
37+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
4938 }
50-
39+
5140 @Test
5241 fun `test pitch snapping for North direction` () {
5342 val direction = PlaceDirection .North
54-
55- // Calculate expected pitch boundary for North at yaw -180.0
56- val yawRad = Math .toRadians(- 180.0 )
57- val expectedBoundary = Math .toDegrees(atan(abs(cos(yawRad))))
58-
59- // Test rotation outside the area (pitch too high)
60- val rotationOutsideHigh = Rotation (- 180.0 , expectedBoundary + 10.0 )
61- val snappedHigh = direction.snapToArea(rotationOutsideHigh)
62-
63- // Test rotation outside the area (pitch too low)
64- val rotationOutsideLow = Rotation (- 180.0 , - expectedBoundary - 10.0 )
65- val snappedLow = direction.snapToArea(rotationOutsideLow)
66-
43+ val rot = Rotation (- 180.0 , 90.0 )
44+ val snapped = direction.snapToArea(rot)
45+
6746 // Verify that the pitch is snapped to the boundary
68- assertEquals(expectedBoundary, snappedHigh.pitch, 0.001 , " Pitch should be snapped to the upper boundary" )
69- assertEquals(- expectedBoundary, snappedLow.pitch, 0.001 , " Pitch should be snapped to the lower boundary" )
47+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
7048 }
71-
49+
7250 @Test
7351 fun `test pitch snapping for UpEast direction` () {
7452 val direction = PlaceDirection .UpEast
75-
76- // Calculate expected pitch boundary for UpEast at yaw -90.0
77- val yawRad = Math .toRadians(- 90.0 )
78- val expectedBoundary = Math .toDegrees(atan(abs(sin(yawRad))))
79-
80- // Test rotation outside the area (pitch too low)
81- val rotationOutside = Rotation (- 90.0 , expectedBoundary - 10.0 )
82- val snapped = direction.snapToArea(rotationOutside)
83-
53+ val rot = Rotation (- 90.0 , 0.0 )
54+ val snapped = direction.snapToArea(rot)
55+
8456 // Verify that the pitch is snapped to the boundary
85- assertEquals(expectedBoundary, snapped.pitch, 0.001 , " Pitch should be snapped to the boundary " )
57+ assertEquals(direction, PlaceDirection .fromRotation( snapped) )
8658 }
87-
59+
8860 @Test
8961 fun `test pitch snapping for DownNorth direction` () {
9062 val direction = PlaceDirection .DownNorth
91-
92- // Calculate expected pitch boundary for DownNorth at yaw -180.0
93- val yawRad = Math .toRadians(- 180.0 )
94- val expectedBoundary = Math .toDegrees(atan(abs(cos(yawRad))))
95-
96- // Test rotation outside the area (pitch too high)
97- val rotationOutside = Rotation (- 180.0 , - expectedBoundary + 10.0 )
98- val snapped = direction.snapToArea(rotationOutside)
99-
63+ val rot = Rotation (- 180.0 , 0.0 )
64+ val snapped = direction.snapToArea(rot)
65+
10066 // Verify that the pitch is snapped to the boundary
101- assertEquals(- expectedBoundary, snapped.pitch, 0.001 , " Pitch should be snapped to the boundary" )
102- }
103-
104- @Test
105- fun `test no snapping when rotation is already in area` () {
106- val direction = PlaceDirection .East
107-
108- // Create a rotation that should be in the East area
109- val rotation = Rotation (- 90.0 , 0.0 )
110-
111- // Verify that the rotation is in the area
112- assertTrue(direction.isInArea(rotation), " Rotation should be in the East area" )
113-
114- // Verify that snapToArea returns the same rotation
115- val snapped = direction.snapToArea(rotation)
116- assertEquals(rotation.yaw, snapped.yaw, 0.001 , " Yaw should not change" )
117- assertEquals(rotation.pitch, snapped.pitch, 0.001 , " Pitch should not change" )
67+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
11868 }
11969}
0 commit comments