@@ -174,10 +174,10 @@ impl Aabb {
174
174
175
175
/// Returns the intersection between two AABBs.
176
176
///
177
- /// # Panics
177
+ /// # Panics (Debug)
178
178
/// If `self.size` is negative.
179
179
#[ inline]
180
- pub fn intersection ( self , b : Aabb ) -> Option < Self > {
180
+ pub fn intersect ( self , b : Aabb ) -> Option < Self > {
181
181
self . assert_nonnegative ( ) ;
182
182
183
183
if !self . intersects ( b) {
@@ -194,6 +194,11 @@ impl Aabb {
194
194
Some ( rect)
195
195
}
196
196
197
+ #[ deprecated = "Renamed to `intersect()`" ]
198
+ pub fn intersection ( self , b : Aabb ) -> Option < Self > {
199
+ self . intersect ( b)
200
+ }
201
+
197
202
/// Returns `true` if this AABB is finite, by calling `@GlobalScope.is_finite` on each component.
198
203
#[ inline]
199
204
pub fn is_finite ( self ) -> bool {
@@ -434,6 +439,7 @@ impl Aabb {
434
439
///
435
440
/// Most functions will fail to give a correct result if the size is negative.
436
441
#[ inline]
442
+ /// TODO(v0.3): make private, change to debug_assert().
437
443
pub fn assert_nonnegative ( self ) {
438
444
assert ! (
439
445
self . size. x >= 0.0 && self . size. y >= 0.0 && self . size. z >= 0.0 ,
@@ -529,27 +535,27 @@ mod test {
529
535
size : Vector3 :: new ( 1.0 , 1.0 , 1.0 ) ,
530
536
} ;
531
537
532
- // Check for intersection including border
538
+ // Check for intersection including border.
533
539
assert ! ( aabb1. intersects( aabb2) ) ;
534
540
assert ! ( aabb2. intersects( aabb1) ) ;
535
541
536
- // Check for non-intersection including border
542
+ // Check for non-intersection including border.
537
543
assert ! ( !aabb1. intersects( aabb3) ) ;
538
544
assert ! ( !aabb3. intersects( aabb1) ) ;
539
545
540
- // Check for intersection excluding border
546
+ // Check for intersection excluding border.
541
547
assert ! ( aabb1. intersects_exclude_borders( aabb2) ) ;
542
548
assert ! ( aabb2. intersects_exclude_borders( aabb1) ) ;
543
549
544
- // Check for non-intersection excluding border
550
+ // Check for non-intersection excluding border.
545
551
assert ! ( !aabb1. intersects_exclude_borders( aabb3) ) ;
546
552
assert ! ( !aabb3. intersects_exclude_borders( aabb1) ) ;
547
553
548
- // Check for non-intersection excluding border
554
+ // Check for non-intersection excluding border.
549
555
assert ! ( !aabb1. intersects_exclude_borders( aabb4) ) ;
550
556
assert ! ( !aabb4. intersects_exclude_borders( aabb1) ) ;
551
557
552
- // Check for intersection with same AABB including border
558
+ // Check for intersection with same AABB including border.
553
559
assert ! ( aabb1. intersects( aabb1) ) ;
554
560
}
555
561
@@ -576,19 +582,18 @@ mod test {
576
582
size : Vector3 :: new ( 1.0 , 1.0 , 1.0 ) ,
577
583
} ;
578
584
579
- // Test cases
580
585
assert_eq ! (
581
- aabb1. intersection ( aabb2) ,
586
+ aabb1. intersect ( aabb2) ,
582
587
Some ( Aabb {
583
588
position: Vector3 :: new( 1.0 , 1.0 , 1.0 ) ,
584
589
size: Vector3 :: new( 1.0 , 1.0 , 1.0 ) ,
585
590
} )
586
591
) ;
587
592
588
- assert_eq ! ( aabb1. intersection ( aabb3) , None ) ;
593
+ assert_eq ! ( aabb1. intersect ( aabb3) , None ) ;
589
594
590
595
assert_eq ! (
591
- aabb1. intersection ( aabb4) ,
596
+ aabb1. intersect ( aabb4) ,
592
597
Some ( Aabb {
593
598
position: Vector3 :: new( 0.0 , 0.0 , 0.0 ) ,
594
599
size: Vector3 :: new( 0.0 , 0.0 , 0.0 ) ,
@@ -598,7 +603,7 @@ mod test {
598
603
599
604
#[ test]
600
605
fn test_intersects_ray ( ) {
601
- // Test case 1: Ray intersects the AABB
606
+ // Test case 1: Ray intersects the AABB.
602
607
let aabb1 = Aabb {
603
608
position : Vector3 :: new ( 0.0 , 0.0 , 0.0 ) ,
604
609
size : Vector3 :: new ( 2.0 , 2.0 , 2.0 ) ,
@@ -608,7 +613,7 @@ mod test {
608
613
609
614
assert ! ( aabb1. intersects_ray( from1, dir1) ) ;
610
615
611
- // Test case 2: Ray misses the AABB
616
+ // Test case 2: Ray misses the AABB.
612
617
let aabb2 = Aabb {
613
618
position : Vector3 :: new ( 0.0 , 0.0 , 0.0 ) ,
614
619
size : Vector3 :: new ( 2.0 , 2.0 , 2.0 ) ,
@@ -617,7 +622,7 @@ mod test {
617
622
let dir2 = Vector3 :: new ( 0.0 , 0.0 , 1.0 ) ;
618
623
assert ! ( !aabb2. intersects_ray( from2, dir2) ) ;
619
624
620
- // Test case 3: Ray starts inside the AABB
625
+ // Test case 3: Ray starts inside the AABB.
621
626
let aabb3 = Aabb {
622
627
position : Vector3 :: new ( 0.0 , 0.0 , 0.0 ) ,
623
628
size : Vector3 :: new ( 2.0 , 2.0 , 2.0 ) ,
@@ -626,7 +631,7 @@ mod test {
626
631
let dir3 = Vector3 :: new ( 0.0 , 0.0 , 1.0 ) ;
627
632
assert ! ( aabb3. intersects_ray( from3, dir3) ) ;
628
633
629
- // Test case 4: Ray direction parallel to AABB
634
+ // Test case 4: Ray direction parallel to AABB.
630
635
let aabb4 = Aabb {
631
636
position : Vector3 :: new ( 0.0 , 0.0 , 0.0 ) ,
632
637
size : Vector3 :: new ( 2.0 , 2.0 , 2.0 ) ,
@@ -635,7 +640,7 @@ mod test {
635
640
let dir4 = Vector3 :: new ( 1.0 , 0.0 , 0.0 ) ;
636
641
assert ! ( aabb4. intersects_ray( from4, dir4) ) ;
637
642
638
- // Test case 5: Ray direction diagonal through the AABB
643
+ // Test case 5: Ray direction diagonal through the AABB.
639
644
let aabb5 = Aabb {
640
645
position : Vector3 :: new ( 0.0 , 0.0 , 0.0 ) ,
641
646
size : Vector3 :: new ( 2.0 , 2.0 , 2.0 ) ,
@@ -644,7 +649,7 @@ mod test {
644
649
let dir5 = Vector3 :: new ( 1.0 , 1.0 , 1.0 ) ;
645
650
assert ! ( aabb5. intersects_ray( from5, dir5) ) ;
646
651
647
- // Test case 6: Ray origin on an AABB face
652
+ // Test case 6: Ray origin on an AABB face.
648
653
let aabb6 = Aabb {
649
654
position : Vector3 :: new ( 0.0 , 0.0 , 0.0 ) ,
650
655
size : Vector3 :: new ( 2.0 , 2.0 , 2.0 ) ,
@@ -745,10 +750,10 @@ mod test {
745
750
position : Vector3 :: new ( -1.5 , 2.0 , -2.5 ) ,
746
751
size : Vector3 :: ONE ,
747
752
} ;
748
- let inter = aabb_big. intersection ( aabb_small) ;
753
+ let inter = aabb_big. intersect ( aabb_small) ;
749
754
assert ! (
750
755
inter. unwrap( ) . approx_eq( & aabb_small) ,
751
- "intersection () with fully contained AABB should return the smaller AABB."
756
+ "intersect () with fully contained AABB should return the smaller AABB."
752
757
) ;
753
758
754
759
let aabb_small = Aabb {
@@ -759,7 +764,7 @@ mod test {
759
764
position : Vector3 :: new ( 0.5 , 2.0 , -2.0 ) ,
760
765
size : Vector3 :: new ( 1.0 , 0.5 , 1.0 ) ,
761
766
} ;
762
- let inter = aabb_big. intersection ( aabb_small) ;
767
+ let inter = aabb_big. intersect ( aabb_small) ;
763
768
assert ! (
764
769
inter. unwrap( ) . approx_eq( & expected) ,
765
770
"intersect() with partially contained AABB (overflowing on Y axis) should match expected."
@@ -769,7 +774,7 @@ mod test {
769
774
position : Vector3 :: new ( 10.0 , -10.0 , -10.0 ) ,
770
775
size : Vector3 :: ONE ,
771
776
} ;
772
- let inter = aabb_big. intersection ( aabb_small) ;
777
+ let inter = aabb_big. intersect ( aabb_small) ;
773
778
assert ! (
774
779
inter. is_none( ) ,
775
780
"intersect() with non-contained AABB should return None."
0 commit comments