@@ -38,14 +38,12 @@ impl Aabb {
38
38
/// Create a new `Aabb` with the first corner at `position` and opposite corner at `end`.
39
39
#[ inline]
40
40
pub fn from_corners ( position : Vector3 , end : Vector3 ) -> Self {
41
- Self {
42
- position,
43
- size : position + end,
44
- }
41
+ // Cannot use floating point arithmetic in const functions.
42
+ Self :: new ( position, end - position)
45
43
}
46
44
47
- /// Returns an AABB with equivalent position and size,
48
- /// modified so that the most-negative corner is the origin and the size is positive.
45
+ /// Returns an AABB with the same geometry, with most-negative corner as ` position` and non-negative ` size`.
46
+ # [ inline ]
49
47
pub fn abs ( & self ) -> Self {
50
48
Aabb {
51
49
position : self . position + self . size . coord_min ( Vector3 :: ZERO ) ,
@@ -141,6 +139,7 @@ impl Aabb {
141
139
}
142
140
143
141
/// Returns true if the AABB has a volume, and false if the AABB is flat, linear, empty, or has a negative size.
142
+ #[ inline]
144
143
pub fn has_volume ( & self ) -> bool {
145
144
self . size . x > 0.0 && self . size . y > 0.0 && self . size . z > 0.0
146
145
}
@@ -168,6 +167,7 @@ impl Aabb {
168
167
}
169
168
170
169
/// Returns `true` if this AABB is finite, by calling `@GlobalScope.is_finite` on each component.
170
+ #[ inline]
171
171
pub fn is_finite ( & self ) -> bool {
172
172
self . position . is_finite ( ) && self . size . is_finite ( )
173
173
}
@@ -187,6 +187,7 @@ impl Aabb {
187
187
}
188
188
189
189
/// Returns the normalized longest axis of the AABB.
190
+ #[ inline]
190
191
pub fn longest_axis ( & self ) -> Vector3 {
191
192
match self . longest_axis_index ( ) {
192
193
Vector3Axis :: X => Vector3 :: RIGHT ,
@@ -196,16 +197,19 @@ impl Aabb {
196
197
}
197
198
198
199
/// Returns the index of the longest axis of the AABB (according to Vector3's AXIS_* constants).
200
+ #[ inline]
199
201
pub fn longest_axis_index ( & self ) -> Vector3Axis {
200
202
self . size . max_axis_index ( )
201
203
}
202
204
203
205
/// Returns the scalar length of the longest axis of the AABB.
206
+ #[ inline]
204
207
pub fn longest_axis_size ( & self ) -> real {
205
208
self . size . x . max ( self . size . y . max ( self . size . z ) )
206
209
}
207
210
208
211
/// Returns the normalized shortest axis of the AABB.
212
+ #[ inline]
209
213
pub fn shortest_axis ( & self ) -> Vector3 {
210
214
match self . shortest_axis_index ( ) {
211
215
Vector3Axis :: X => Vector3 :: RIGHT ,
@@ -215,16 +219,19 @@ impl Aabb {
215
219
}
216
220
217
221
/// Returns the index of the shortest axis of the AABB (according to Vector3::AXIS* enum).
222
+ #[ inline]
218
223
pub fn shortest_axis_index ( & self ) -> Vector3Axis {
219
224
self . size . min_axis_index ( )
220
225
}
221
226
222
227
/// Returns the scalar length of the shortest axis of the AABB.
228
+ #[ inline]
223
229
pub fn shortest_axis_size ( & self ) -> real {
224
230
self . size . x . min ( self . size . y . min ( self . size . z ) )
225
231
}
226
232
227
233
/// Returns the support point in a given direction. This is useful for collision detection algorithms.
234
+ #[ inline]
228
235
pub fn support ( & self , dir : Vector3 ) -> Vector3 {
229
236
let half_extents = self . size * 0.5 ;
230
237
let relative_center_point = self . position + half_extents;
@@ -238,9 +245,12 @@ impl Aabb {
238
245
half_extents * signs + relative_center_point
239
246
}
240
247
241
- /// Returns `true` if the AABB overlaps with `b` (i.e. they have at least one point in common) .
248
+ /// Checks whether two AABBs have at least one point in common.
242
249
///
243
- /// _Godot equivalent: `AABB.intersects(AABB b, bool include_borders = false)`_
250
+ /// Also returns `true` if the AABBs only touch each other (share a point/edge/face).
251
+ /// See [`intersects_exclude_borders`][Self::intersects_exclude_borders] if you want to return `false` in that case.
252
+ ///
253
+ /// _Godot equivalent: `AABB.intersects(AABB b, bool include_borders = true)`_
244
254
#[ inline]
245
255
pub fn intersects ( & self , b : & Aabb ) -> bool {
246
256
let end = self . end ( ) ;
@@ -253,9 +263,13 @@ impl Aabb {
253
263
&& self . position . z <= end_b. z
254
264
}
255
265
256
- /// Returns `true` if the AABB overlaps with `b` (i.e. they have at least one inner point in common).
266
+ /// Checks whether two AABBs have at least one _inner_ point in common (not on the borders ).
257
267
///
258
- /// _Godot equivalent: `AABB.intersects(AABB b, bool include_borders = true)`_
268
+ /// Returns `false` if the AABBs only touch each other (share a point/edge/face).
269
+ /// See [`intersects`][Self::intersects] if you want to return `true` in that case.
270
+ ///
271
+ /// _Godot equivalent: `AABB.intersects(AABB b, bool include_borders = false)`_
272
+ #[ inline]
259
273
pub fn intersects_exclude_borders ( & self , & b: & Aabb ) -> bool {
260
274
let end = self . end ( ) ;
261
275
let end_b = b. end ( ) ;
@@ -269,6 +283,7 @@ impl Aabb {
269
283
}
270
284
271
285
/// Returns `true` if the AABB is on both sides of a plane.
286
+ #[ inline]
272
287
pub fn intersects_plane ( & self , plane : & Plane ) -> bool {
273
288
// The set of the edges of the AABB.
274
289
let points = [
@@ -301,6 +316,7 @@ impl Aabb {
301
316
///
302
317
/// # Panics
303
318
/// If `self.size` is negative.
319
+ #[ inline]
304
320
pub fn intersects_ray ( & self , from : Vector3 , dir : Vector3 ) -> bool {
305
321
self . assert_nonnegative ( ) ;
306
322
@@ -320,6 +336,7 @@ impl Aabb {
320
336
///
321
337
/// # Panics
322
338
/// If `self.size` is negative.
339
+ #[ inline]
323
340
pub fn intersects_segment ( & self , from : Vector3 , to : Vector3 ) -> bool {
324
341
self . assert_nonnegative ( ) ;
325
342
0 commit comments