@@ -52,14 +52,14 @@ impl Aabb {
52
52
///
53
53
/// This method corresponds to the [`get_area`] GDScript method.
54
54
///
55
- /// [get_area]: https://docs.godotengine.org/en/stable/classes/class_aabb.html#class-aabb-method-get-area
55
+ /// [` get_area` ]: https://docs.godotengine.org/en/stable/classes/class_aabb.html#class-aabb-method-get-area
56
56
#[ inline]
57
- pub fn get_volume ( self ) -> f32 {
57
+ pub fn volume ( self ) -> f32 {
58
58
self . size . x * self . size . y * self . size . z
59
59
}
60
60
61
61
/// Returns true if the bounding box is flat or empty. See also
62
- /// [`get_volume `][Self::get_volume ].
62
+ /// [`volume `][Self::volume ].
63
63
///
64
64
/// This method corresponds to the [`has_no_area`] GDScript method.
65
65
///
@@ -118,46 +118,40 @@ impl Aabb {
118
118
}
119
119
}
120
120
121
- /// Returns the normalized longest axis of the bounding box.
122
- #[ inline]
123
- pub fn get_longest_axis ( self ) -> Vector3 {
124
- self . size . max_axis ( ) . to_unit_vector ( )
125
- }
126
-
127
- /// Returns the index of the longest axis of the bounding box.
121
+ /// Returns the longest side of this AABB as an axis index and its length.
128
122
///
129
- /// If multiple axes have the same length, then the first in order X, Y, Z is returned.
130
- #[ inline]
131
- pub fn get_longest_axis_index ( self ) -> Axis {
132
- self . size . max_axis ( )
133
- }
134
-
135
- /// Returns the scalar length of the longest axis of the bounding box.
123
+ /// If multiple axes have the same length, then the first in order X, Y, Z is returned.
124
+ /// To get the unit vector along the axis, use [`Axis::to_unit_vector()`].
125
+ ///
126
+ /// If you want to emulate the separate GDScript methods, you can do this:
127
+ /// ```no_run
128
+ /// # let aabb: gdnative::core_types::Aabb = todo!();
129
+ /// let (index, size) = aabb.longest_axis();
130
+ /// let axis = index.to_unit_vector();
131
+ /// ```
136
132
#[ inline]
137
- pub fn get_longest_axis_size ( self ) -> f32 {
133
+ pub fn longest_axis ( self ) -> ( Axis , f32 ) {
138
134
let Vector3 { x, y, z } = self . size ;
139
- x. max ( y) . max ( z)
140
- }
141
135
142
- /// Returns the normalized shortest axis of the bounding box.
143
- #[ inline]
144
- pub fn get_shortest_axis ( self ) -> Vector3 {
145
- self . size . min_axis ( ) . to_unit_vector ( )
136
+ ( self . size . max_axis ( ) , x. max ( y) . max ( z) )
146
137
}
147
138
148
- /// Returns the index of the shortest axis of the bounding box .
139
+ /// Returns the shortest side of this AABB as an axis index and its length .
149
140
///
150
- /// If multiple axes have the same length, then the first in order X, Y, Z is returned.
151
- #[ inline]
152
- pub fn get_shortest_axis_index ( self ) -> Axis {
153
- self . size . min_axis ( )
154
- }
155
-
156
- /// Returns the scalar length of the shortest axis of the bounding box.
141
+ /// If multiple axes have the same length, then the first in order X, Y, Z is returned.
142
+ /// To get the unit vector along the axis, use [`Axis::to_unit_vector()`].
143
+ ///
144
+ /// If you want to emulate the separate GDScript methods, you can do this:
145
+ /// ```no_run
146
+ /// # let aabb: gdnative::core_types::Aabb = todo!();
147
+ /// let (index, size) = aabb.shortest_axis();
148
+ /// let axis = index.to_unit_vector();
149
+ /// ```
157
150
#[ inline]
158
- pub fn get_shortest_axis_size ( self ) -> f32 {
151
+ pub fn shortest_axis ( self ) -> ( Axis , f32 ) {
159
152
let Vector3 { x, y, z } = self . size ;
160
- x. min ( y) . min ( z)
153
+
154
+ ( self . size . min_axis ( ) , x. min ( y) . min ( z) )
161
155
}
162
156
163
157
/// Returns the support point in a given direction. This is useful for collision detection
@@ -382,15 +376,22 @@ mod tests {
382
376
}
383
377
384
378
#[ test]
385
- fn test_get_axis ( ) {
379
+ fn test_longest_shortest_axis ( ) {
386
380
let aabb = Aabb :: new ( Vector3 :: ZERO , Vector3 :: new ( 1.0 , 2.0 , 3.0 ) ) ;
387
- assert ! ( aabb. get_longest_axis( ) . is_equal_approx( Vector3 :: BACK ) ) ;
388
- assert_eq ! ( aabb. get_longest_axis_index( ) , Axis :: Z ) ;
389
- assert ! ( aabb. get_longest_axis_size( ) . is_equal_approx( 3.0 ) ) ;
390
381
391
- assert ! ( aabb. get_shortest_axis( ) . is_equal_approx( Vector3 :: RIGHT ) ) ;
392
- assert_eq ! ( aabb. get_shortest_axis_index( ) , Axis :: X ) ;
393
- assert ! ( aabb. get_shortest_axis_size( ) . is_equal_approx( 1.0 ) ) ;
382
+ let ( longest_axis, longest_size) = aabb. longest_axis ( ) ;
383
+ let longest_vector = longest_axis. to_unit_vector ( ) ;
384
+
385
+ assert ! ( longest_vector. is_equal_approx( Vector3 :: BACK ) ) ;
386
+ assert_eq ! ( longest_axis, Axis :: Z ) ;
387
+ assert ! ( longest_size. is_equal_approx( 3.0 ) ) ;
388
+
389
+ let ( shortest_axis, shortest_size) = aabb. shortest_axis ( ) ;
390
+ let shortest_vector = shortest_axis. to_unit_vector ( ) ;
391
+
392
+ assert ! ( shortest_vector. is_equal_approx( Vector3 :: RIGHT ) ) ;
393
+ assert_eq ! ( shortest_axis, Axis :: X ) ;
394
+ assert ! ( shortest_size. is_equal_approx( 1.0 ) ) ;
394
395
}
395
396
396
397
#[ test]
0 commit comments