@@ -20,11 +20,19 @@ import com.lambda.interaction.request.rotation.visibilty.PlaceDirection
2020import kotlin.math.abs
2121import kotlin.math.atan
2222import kotlin.math.cos
23+ import kotlin.math.sin
2324import kotlin.test.Test
2425import kotlin.test.assertEquals
26+ import kotlin.test.assertTrue
27+ import kotlin.test.assertFalse
2528
29+ /* *
30+ * Tests for the PlaceDirection class
31+ */
2632class PlaceDirectionTest {
2733
34+ // Tests for snapToArea method - Horizontal directions
35+
2836 @Test
2937 fun `test pitch snapping for East direction` () {
3038 val direction = PlaceDirection .East
@@ -35,6 +43,16 @@ class PlaceDirectionTest {
3543 assertEquals(direction, PlaceDirection .fromRotation(snapped))
3644 }
3745
46+ @Test
47+ fun `test pitch snapping for West direction` () {
48+ val direction = PlaceDirection .West
49+ val rot = Rotation (90.0 , 90.0 )
50+ val snapped = direction.snapToArea(rot)
51+
52+ // Verify that the pitch is snapped to the boundary
53+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
54+ }
55+
3856 @Test
3957 fun `test pitch snapping for North direction` () {
4058 val direction = PlaceDirection .North
@@ -45,6 +63,18 @@ class PlaceDirectionTest {
4563 assertEquals(direction, PlaceDirection .fromRotation(snapped))
4664 }
4765
66+ @Test
67+ fun `test pitch snapping for South direction` () {
68+ val direction = PlaceDirection .South
69+ val rot = Rotation (0.0 , 90.0 )
70+ val snapped = direction.snapToArea(rot)
71+
72+ // Verify that the pitch is snapped to the boundary
73+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
74+ }
75+
76+ // Tests for snapToArea method - Up directions
77+
4878 @Test
4979 fun `test pitch snapping for UpEast direction` () {
5080 val direction = PlaceDirection .UpEast
@@ -55,19 +85,168 @@ class PlaceDirectionTest {
5585 assertEquals(direction, PlaceDirection .fromRotation(snapped))
5686 }
5787
88+ @Test
89+ fun `test pitch snapping for UpWest direction` () {
90+ val direction = PlaceDirection .UpWest
91+ val rot = Rotation (90.0 , 0.0 )
92+ val snapped = direction.snapToArea(rot)
93+
94+ // Verify that the pitch is snapped to the boundary
95+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
96+ }
97+
98+ @Test
99+ fun `test pitch snapping for UpNorth direction` () {
100+ val direction = PlaceDirection .UpNorth
101+ val rot = Rotation (- 180.0 , 0.0 )
102+ val snapped = direction.snapToArea(rot)
103+
104+ // Verify that the pitch is snapped to the boundary
105+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
106+ }
107+
108+ @Test
109+ fun `test pitch snapping for UpSouth direction` () {
110+ val direction = PlaceDirection .UpSouth
111+ val rot = Rotation (0.0 , 0.0 )
112+ val snapped = direction.snapToArea(rot)
113+
114+ // Verify that the pitch is snapped to the boundary
115+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
116+ }
117+
118+ // Tests for snapToArea method - Down directions
119+
120+ @Test
121+ fun `test pitch snapping for DownEast direction` () {
122+ val direction = PlaceDirection .DownEast
123+ val rot = Rotation (- 90.0 , 0.0 )
124+ val snapped = direction.snapToArea(rot)
125+
126+ // Verify that the pitch is snapped to the boundary
127+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
128+ }
129+
130+ @Test
131+ fun `test pitch snapping for DownWest direction` () {
132+ val direction = PlaceDirection .DownWest
133+ val rot = Rotation (90.0 , 0.0 )
134+ val snapped = direction.snapToArea(rot)
135+
136+ // Verify that the pitch is snapped to the boundary
137+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
138+ }
139+
58140 @Test
59141 fun `test pitch snapping for DownNorth direction` () {
60142 val direction = PlaceDirection .DownNorth
61-
62- // Calculate expected pitch boundary for DownNorth at yaw -180.0
63- val yawRad = Math .toRadians(- 180.0 )
64- val expectedBoundary = Math .toDegrees(atan(abs(cos(yawRad))))
65-
66- // Test rotation outside the area (pitch too high)
67- val rotationOutside = Rotation (- 180.0 , - expectedBoundary + 10.0 )
68- val snapped = direction.snapToArea(rotationOutside)
69-
143+ val rot = Rotation (- 180.0 , 0.0 )
144+ val snapped = direction.snapToArea(rot)
145+
146+ // Verify that the pitch is snapped to the boundary
147+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
148+ }
149+
150+ @Test
151+ fun `test pitch snapping for DownSouth direction` () {
152+ val direction = PlaceDirection .DownSouth
153+ val rot = Rotation (0.0 , 0.0 )
154+ val snapped = direction.snapToArea(rot)
155+
156+ // Verify that the pitch is snapped to the boundary
157+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
158+ }
159+
160+ // Tests for snapToArea method - Pure Up/Down directions
161+
162+ @Test
163+ fun `test pitch snapping for UpSouth direction with extreme pitch` () {
164+ val direction = PlaceDirection .UpSouth
165+ val rot = Rotation (0.0 , - 45.0 )
166+ val snapped = direction.snapToArea(rot)
167+
168+ // Verify that the pitch is snapped to the boundary
169+ assertEquals(direction, PlaceDirection .fromRotation(snapped))
170+ }
171+
172+ @Test
173+ fun `test pitch snapping for DownSouth direction with extreme pitch` () {
174+ val direction = PlaceDirection .DownSouth
175+ val rot = Rotation (0.0 , 45.0 )
176+ val snapped = direction.snapToArea(rot)
177+
70178 // Verify that the pitch is snapped to the boundary
71179 assertEquals(direction, PlaceDirection .fromRotation(snapped))
72180 }
73- }
181+
182+ // Tests for when rotation is already in the area
183+
184+ @Test
185+ fun `test no snapping when rotation is already in area` () {
186+ val direction = PlaceDirection .East
187+ // Create a rotation that's already in the East area
188+ val rot = Rotation (- 90.0 , 0.0 )
189+
190+ // Verify it's already in the area
191+ assertEquals(direction, PlaceDirection .fromRotation(rot))
192+
193+ val snapped = direction.snapToArea(rot)
194+
195+ // Verify that the rotation is unchanged
196+ assertEquals(rot, snapped)
197+ }
198+
199+ // Tests for isInArea method
200+
201+ @Test
202+ fun `test isInArea method` () {
203+ val eastRot = Rotation (- 90.0 , 0.0 )
204+ val northRot = Rotation (- 180.0 , 0.0 )
205+
206+ assertTrue(PlaceDirection .East .isInArea(eastRot))
207+ assertFalse(PlaceDirection .East .isInArea(northRot))
208+
209+ assertTrue(PlaceDirection .North .isInArea(northRot))
210+ assertFalse(PlaceDirection .North .isInArea(eastRot))
211+ }
212+
213+ // Tests for fromRotation method
214+
215+ @Test
216+ fun `test fromRotation for horizontal directions` () {
217+ assertEquals(PlaceDirection .East , PlaceDirection .fromRotation(Rotation (- 90.0 , 0.0 )))
218+ assertEquals(PlaceDirection .West , PlaceDirection .fromRotation(Rotation (90.0 , 0.0 )))
219+ assertEquals(PlaceDirection .North , PlaceDirection .fromRotation(Rotation (- 180.0 , 0.0 )))
220+ assertEquals(PlaceDirection .South , PlaceDirection .fromRotation(Rotation (0.0 , 0.0 )))
221+ }
222+
223+ @Test
224+ fun `test fromRotation for up directions` () {
225+ assertEquals(PlaceDirection .UpEast , PlaceDirection .fromRotation(Rotation (- 90.0 , - 60.0 )))
226+ assertEquals(PlaceDirection .UpWest , PlaceDirection .fromRotation(Rotation (90.0 , - 60.0 )))
227+ assertEquals(PlaceDirection .UpNorth , PlaceDirection .fromRotation(Rotation (- 180.0 , - 60.0 )))
228+ assertEquals(PlaceDirection .UpSouth , PlaceDirection .fromRotation(Rotation (0.0 , - 60.0 )))
229+ }
230+
231+ @Test
232+ fun `test fromRotation for down directions` () {
233+ assertEquals(PlaceDirection .DownEast , PlaceDirection .fromRotation(Rotation (- 90.0 , 60.0 )))
234+ assertEquals(PlaceDirection .DownWest , PlaceDirection .fromRotation(Rotation (90.0 , 60.0 )))
235+ assertEquals(PlaceDirection .DownNorth , PlaceDirection .fromRotation(Rotation (- 180.0 , 60.0 )))
236+ assertEquals(PlaceDirection .DownSouth , PlaceDirection .fromRotation(Rotation (0.0 , 60.0 )))
237+ }
238+
239+ // Edge case tests
240+
241+ @Test
242+ fun `test edge case with yaw at boundaries` () {
243+ // Test with yaw at the boundaries between directions
244+ val boundaryYaw = - 135.0 // Boundary between North and East
245+
246+ // Slightly to the East side
247+ assertEquals(PlaceDirection .East , PlaceDirection .fromRotation(Rotation (boundaryYaw + 0.1 , 0.0 )))
248+
249+ // Slightly to the North side
250+ assertEquals(PlaceDirection .North , PlaceDirection .fromRotation(Rotation (boundaryYaw - 0.1 , 0.0 )))
251+ }
252+ }
0 commit comments