AABB
A 3D axis-aligned bounding box.
AABB.swift:21struct AABB
The AABB
built-in Variant
type represents an axis-aligned bounding box in a 3D space. It is defined by its position
and size
, which are Vector3
. It is frequently used for fast overlap tests (see intersects(with:)
). Although AABB
itself is axis-aligned, it can be combined with Transform3D
to represent a rotated or skewed bounding box.
It uses floating-point coordinates. The 2D counterpart to AABB
is Rect2
. There is no version of AABB
that uses integer coordinates.
Citizens in SwiftGodot
Conformances
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol SelfVariantRepresentable
Structs and scalar types use their own layout for storage.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
init(
) Constructs an
AABB
with itsposition
andsize
set toVector3.ZERO
.init(from: AABB
) init(position: Vector3, size: Vector3
) Constructs an
AABB
byposition
andsize
.static var godotType: Variant.GType
static func != (lhs: AABB, rhs: AABB
) -> Bool Returns
true
if theposition
orsize
of both bounding boxes are not equal.static func * (lhs: AABB, rhs: Transform3D
) -> AABB Inversely transforms (multiplies) the
AABB
by the givenTransform3D
transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).static func == (lhs: AABB, rhs: AABB
) -> Bool Returns
true
if bothposition
andsize
of the bounding boxes are exactly equal, respectively.
Instance members
var end: Vector3
The ending point. This is usually the corner on the top-right and forward of the bounding box, and is equivalent to
position + size
. Setting this point affects thesize
.var position: Vector3
The origin point. This is usually the corner on the bottom-left and back of the bounding box.
var size: Vector3
The bounding box’s width, height, and depth starting from
position
. Setting this value also affects theend
point.func abs(
) -> AABB Returns an
AABB
equivalent to this bounding box, with its width, height, and depth modified to be non-negative values.func encloses(with: AABB
) -> Bool Returns
true
if this bounding box completely encloses thewith
box. The edges of both boxes are included.func expand(toPoint: Vector3
) -> AABB Returns a copy of this bounding box expanded to align the edges with the given
toPoint
, if necessary.func getCenter(
) -> Vector3 Returns the center point of the bounding box. This is the same as
position + (size / 2.0)
.func getEndpoint(idx: Int64
) -> Vector3 Returns the position of one of the 8 vertices that compose this bounding box. With a
idx
of0
this is the same asposition
, and aidx
of7
is the same asend
.func getLongestAxis(
) -> Vector3 Returns the longest normalized axis of this bounding box’s
size
, as aVector3
(Vector3.RIGHT
,Vector3.UP
, orVector3.BACK
).func getLongestAxisIndex(
) -> Int64 Returns the index to the longest axis of this bounding box’s
size
(seeVector3.AXIS_X
,Vector3.AXIS_Y
, andVector3.AXIS_Z
).func getLongestAxisSize(
) -> Double Returns the longest dimension of this bounding box’s
size
.func getShortestAxis(
) -> Vector3 Returns the shortest normaalized axis of this bounding box’s
size
, as aVector3
(Vector3.RIGHT
,Vector3.UP
, orVector3.BACK
).func getShortestAxisIndex(
) -> Int64 Returns the index to the shortest axis of this bounding box’s
size
(seeVector3.AXIS_X
,Vector3.AXIS_Y
, andVector3.AXIS_Z
).func getShortestAxisSize(
) -> Double Returns the shortest dimension of this bounding box’s
size
.func getSupport(dir: Vector3
) -> Vector3 Returns the vertex’s position of this bounding box that’s the farthest in the given direction. This point is commonly known as the support point in collision detection algorithms.
func getVolume(
) -> Double Returns the bounding box’s volume. This is equivalent to
size.x * size.y * size.z
. See alsohasVolume
.func grow(by: Double
) -> AABB Returns a copy of this bounding box extended on all sides by the given amount
by
. A negative amount shrinks the box instead.func hasPoint(Vector3
) -> Bool Returns
true
if the bounding box contains the givenpoint
. By convention, points exactly on the right, top, and front sides are not included.func hasSurface(
) -> Bool Returns
true
if this bounding box has a surface or a length, that is, at least one component ofsize
is greater than0
. Otherwise, returnsfalse
.func hasVolume(
) -> Bool Returns
true
if this bounding box’s width, height, and depth are all positive. See alsogetVolume
.func intersection(with: AABB
) -> AABB Returns the intersection between this bounding box and
with
. If the boxes do not intersect, returns an emptyAABB
. If the boxes intersect at the edge, returns a flatAABB
with no volume (seehasSurface
andhasVolume
).func intersects(with: AABB
) -> Bool Returns
true
if this bounding box overlaps with the boxwith
. The edges of both boxes are always excluded.func intersectsPlane(Plane
) -> Bool Returns
true
if this bounding box is on both sides of the givenplane
.func intersectsRay(from: Vector3, dir: Vector3
) -> Variant Returns the first point where this bounding box and the given ray intersect, as a
Vector3
. If no intersection occurs, returnsnull
.func intersectsSegment(from: Vector3, to: Vector3
) -> Variant Returns the first point where this bounding box and the given segment intersect, as a
Vector3
. If no intersection occurs, returnsnull
.func isEqualApprox(aabb: AABB
) -> Bool Returns
true
if this bounding box andaabb
are approximately equal, by callingisEqualApprox(to:)
on theposition
and thesize
.func isFinite(
) -> Bool Returns
true
if this bounding box’s values are finite, by callingisFinite
on theposition
and thesize
.func merge(with: AABB
) -> AABB Returns an
AABB
that encloses both this bounding box andwith
around the edges. See alsoencloses(with:)
.
Type features
init?(Variant
) static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant.
static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant. This is useful when you want one method to call that will return the unwrapped Variant, regardless of whether it is a SwiftGodot.Object or not.
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.