@@ -322,4 +322,127 @@ mod test_point_optimizations {
322322 assert ! ( results[ 0 ] != 999 ) ;
323323 assert ! ( results[ 1 ] != 888 ) ;
324324 }
325+
326+ /// Test get_point() convenience method
327+ #[ test]
328+ fn test_get_point_method ( ) {
329+ let mut tree = AABB :: with_capacity ( 4 ) ;
330+ tree. add_point ( 0.0 , 0.0 ) ;
331+ tree. add_point ( 1.5 , 2.5 ) ;
332+ tree. add_point ( 3.0 , 4.0 ) ;
333+ tree. add_point ( -1.0 , -1.0 ) ;
334+ tree. build ( ) ;
335+
336+ // Verify get_point returns correct coordinates
337+ assert_eq ! ( tree. get_point( 0 ) , Some ( ( 0.0 , 0.0 ) ) ) ;
338+ assert_eq ! ( tree. get_point( 1 ) , Some ( ( 1.5 , 2.5 ) ) ) ;
339+ assert_eq ! ( tree. get_point( 2 ) , Some ( ( 3.0 , 4.0 ) ) ) ;
340+ assert_eq ! ( tree. get_point( 3 ) , Some ( ( -1.0 , -1.0 ) ) ) ;
341+
342+ // Out of bounds should return None
343+ assert_eq ! ( tree. get_point( 4 ) , None ) ;
344+ }
345+
346+ /// Test that get_point works before build
347+ #[ test]
348+ fn test_get_point_before_build ( ) {
349+ let mut tree = AABB :: with_capacity ( 2 ) ;
350+ tree. add_point ( 1.0 , 2.0 ) ;
351+ tree. add_point ( 3.0 , 4.0 ) ;
352+
353+ // Should work even before build()
354+ assert_eq ! ( tree. get_point( 0 ) , Some ( ( 1.0 , 2.0 ) ) ) ;
355+ assert_eq ! ( tree. get_point( 1 ) , Some ( ( 3.0 , 4.0 ) ) ) ;
356+ }
357+
358+ /// Test query with very small radius (1e-9) - critical for exact point matching
359+ #[ test]
360+ fn test_query_circle_points_very_small_radius ( ) {
361+ let mut tree = AABB :: with_capacity ( 5 ) ;
362+ tree. add_point ( 0.0 , 0.0 ) ;
363+ tree. add_point ( 1.0 , 0.0 ) ;
364+ tree. add_point ( 0.0 , 1.0 ) ;
365+ tree. add_point ( 1.0 , 1.0 ) ;
366+ tree. add_point ( 0.5 , 0.5 ) ;
367+ tree. build ( ) ;
368+
369+ // Query with radius 1e-9 should only return exact point
370+ let mut results = Vec :: new ( ) ;
371+ tree. query_circle_points ( 0.0 , 0.0 , 1e-9 , & mut results) ;
372+ assert_eq ! ( results, vec![ 0 ] , "Query with radius 1e-9 should only return exact point" ) ;
373+
374+ // Query with radius 1e-6 should still only return exact point
375+ tree. query_circle_points ( 0.0 , 0.0 , 1e-6 , & mut results) ;
376+ assert_eq ! ( results, vec![ 0 ] , "Query with radius 1e-6 should only return exact point" ) ;
377+ }
378+
379+ /// Test point storage correctness after build with Hilbert sorting
380+ #[ test]
381+ fn test_point_storage_after_build ( ) {
382+ let mut tree = AABB :: with_capacity ( 5 ) ;
383+
384+ // Add points in specific order
385+ tree. add_point ( 0.0 , 0.0 ) ;
386+ tree. add_point ( 1.0 , 0.0 ) ;
387+ tree. add_point ( 0.0 , 1.0 ) ;
388+ tree. add_point ( 1.0 , 1.0 ) ;
389+ tree. add_point ( 0.5 , 0.5 ) ;
390+
391+ tree. build ( ) ;
392+
393+ // Verify all points are stored correctly
394+ assert_eq ! ( tree. get_point( 0 ) , Some ( ( 0.0 , 0.0 ) ) ) ;
395+ assert_eq ! ( tree. get_point( 1 ) , Some ( ( 1.0 , 0.0 ) ) ) ;
396+ assert_eq ! ( tree. get_point( 2 ) , Some ( ( 0.0 , 1.0 ) ) ) ;
397+ assert_eq ! ( tree. get_point( 3 ) , Some ( ( 1.0 , 1.0 ) ) ) ;
398+ assert_eq ! ( tree. get_point( 4 ) , Some ( ( 0.5 , 0.5 ) ) ) ;
399+ }
400+
401+ /// Test that add_point stores correct coordinates (not swapped)
402+ #[ test]
403+ fn test_add_point_coordinate_order ( ) {
404+ let mut tree = AABB :: with_capacity ( 3 ) ;
405+
406+ tree. add_point ( 1.5 , 2.5 ) ;
407+ tree. add_point ( 3.0 , 4.0 ) ;
408+ tree. add_point ( -1.0 , -2.0 ) ;
409+
410+ tree. build ( ) ;
411+
412+ // Verify X and Y are not swapped
413+ assert_eq ! ( tree. get_point( 0 ) , Some ( ( 1.5 , 2.5 ) ) ) ;
414+ assert_eq ! ( tree. get_point( 1 ) , Some ( ( 3.0 , 4.0 ) ) ) ;
415+ assert_eq ! ( tree. get_point( 2 ) , Some ( ( -1.0 , -2.0 ) ) ) ;
416+
417+ // Verify via get() as well
418+ assert_eq ! ( tree. get( 0 ) . unwrap( ) , ( 1.5 , 2.5 , 1.5 , 2.5 ) ) ;
419+ assert_eq ! ( tree. get( 1 ) . unwrap( ) , ( 3.0 , 4.0 , 3.0 , 4.0 ) ) ;
420+ assert_eq ! ( tree. get( 2 ) . unwrap( ) , ( -1.0 , -2.0 , -1.0 , -2.0 ) ) ;
421+ }
422+
423+ /// Test consistency between query_circle_points and get_point
424+ #[ test]
425+ fn test_query_circle_points_consistency_with_get_point ( ) {
426+ let mut tree = AABB :: with_capacity ( 10 ) ;
427+
428+ // Create grid of points
429+ for i in 0 ..3 {
430+ for j in 0 ..3 {
431+ tree. add_point ( i as f64 , j as f64 ) ;
432+ }
433+ }
434+ tree. build ( ) ;
435+
436+ // Query for points near (1.0, 1.0) with radius 1.5
437+ let mut results = Vec :: new ( ) ;
438+ tree. query_circle_points ( 1.0 , 1.0 , 1.5 , & mut results) ;
439+
440+ // For each result, verify get_point returns the correct coordinates
441+ for & idx in & results {
442+ if let Some ( ( x, y) ) = tree. get_point ( idx) {
443+ let distance = ( ( x - 1.0 ) . powi ( 2 ) + ( y - 1.0 ) . powi ( 2 ) ) . sqrt ( ) ;
444+ assert ! ( distance <= 1.5 , "Point {} at ({}, {}) has distance {}, exceeds radius 1.5" , idx, x, y, distance) ;
445+ }
446+ }
447+ }
325448}
0 commit comments