Table of Contents

Struct Aabb

Namespace
Godot
Assembly
GodotSharp.dll

Axis-Aligned Bounding Box. AABB consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

public struct Aabb : IEquatable<Aabb>
Implements
Inherited Members

Constructors

Aabb(Vector3, Vector3)

Constructs an Aabb from a position and size.

public Aabb(Vector3 position, Vector3 size)

Parameters

position Vector3

The position.

size Vector3

The size, typically positive.

Aabb(Vector3, float, float, float)

Constructs an Aabb from a position, width, height, and depth.

public Aabb(Vector3 position, float width, float height, float depth)

Parameters

position Vector3

The position.

width float

The width, typically positive.

height float

The height, typically positive.

depth float

The depth, typically positive.

Aabb(float, float, float, Vector3)

Constructs an Aabb from x, y, z, and size.

public Aabb(float x, float y, float z, Vector3 size)

Parameters

x float

The position's X coordinate.

y float

The position's Y coordinate.

z float

The position's Z coordinate.

size Vector3

The size, typically positive.

Aabb(float, float, float, float, float, float)

Constructs an Aabb from x, y, z, width, height, and depth.

public Aabb(float x, float y, float z, float width, float height, float depth)

Parameters

x float

The position's X coordinate.

y float

The position's Y coordinate.

z float

The position's Z coordinate.

width float

The width, typically positive.

height float

The height, typically positive.

depth float

The depth, typically positive.

Properties

End

Ending corner. This is calculated as Position plus Size. Setting this value will change the size.

public Vector3 End { readonly get; set; }

Property Value

Vector3

Getting is equivalent to value = Position + Size, setting is equivalent to Size = value - Position

Position

Beginning corner. Typically has values lower than End.

public Vector3 Position { readonly get; set; }

Property Value

Vector3

Directly uses a private field.

Size

Size from Position to End. Typically all components are positive. If the size is negative, you can use Abs() to fix it.

public Vector3 Size { readonly get; set; }

Property Value

Vector3

Directly uses a private field.

Volume

The volume of this Aabb. See also HasVolume().

public readonly float Volume { get; }

Property Value

float

Methods

Abs()

Returns an Aabb with equivalent position and size, modified so that the most-negative corner is the origin and the size is positive.

public readonly Aabb Abs()

Returns

Aabb

The modified Aabb.

Encloses(Aabb)

Returns true if this Aabb completely encloses another one.

public readonly bool Encloses(Aabb with)

Parameters

with Aabb

The other Aabb that may be enclosed.

Returns

bool

A bool for whether or not this Aabb encloses with.

Equals(Aabb)

Returns true if the AABBs are exactly equal. Note: Due to floating-point precision errors, consider using IsEqualApprox(Aabb) instead, which is more reliable.

public readonly bool Equals(Aabb other)

Parameters

other Aabb

The other AABB.

Returns

bool

Whether or not the AABBs are exactly equal.

Equals(object)

Returns true if the AABB is exactly equal to the given object (obj). Note: Due to floating-point precision errors, consider using IsEqualApprox(Aabb) instead, which is more reliable.

public override readonly bool Equals(object obj)

Parameters

obj object

The object to compare with.

Returns

bool

Whether or not the AABB and the object are equal.

Expand(Vector3)

Returns this Aabb expanded to include a given point.

public readonly Aabb Expand(Vector3 point)

Parameters

point Vector3

The point to include.

Returns

Aabb

The expanded Aabb.

GetCenter()

Returns the center of the Aabb, which is equal to Position + (Size / 2).

public readonly Vector3 GetCenter()

Returns

Vector3

The center.

GetEndpoint(int)

Gets the position of one of the 8 endpoints of the Aabb.

public readonly Vector3 GetEndpoint(int idx)

Parameters

idx int

Which endpoint to get.

Returns

Vector3

An endpoint of the Aabb.

Exceptions

ArgumentOutOfRangeException

idx is less than 0 or greater than 7.

GetHashCode()

Serves as the hash function for Aabb.

public override readonly int GetHashCode()

Returns

int

A hash code for this AABB.

GetLongestAxis()

Returns the normalized longest axis of the Aabb.

public readonly Vector3 GetLongestAxis()

Returns

Vector3

A vector representing the normalized longest axis of the Aabb.

GetLongestAxisIndex()

Returns the Vector3.Axis index of the longest axis of the Aabb.

public readonly Vector3.Axis GetLongestAxisIndex()

Returns

Vector3.Axis

A Vector3.Axis index for which axis is longest.

GetLongestAxisSize()

Returns the scalar length of the longest axis of the Aabb.

public readonly float GetLongestAxisSize()

Returns

float

The scalar length of the longest axis of the Aabb.

GetShortestAxis()

Returns the normalized shortest axis of the Aabb.

public readonly Vector3 GetShortestAxis()

Returns

Vector3

A vector representing the normalized shortest axis of the Aabb.

GetShortestAxisIndex()

Returns the Vector3.Axis index of the shortest axis of the Aabb.

public readonly Vector3.Axis GetShortestAxisIndex()

Returns

Vector3.Axis

A Vector3.Axis index for which axis is shortest.

GetShortestAxisSize()

Returns the scalar length of the shortest axis of the Aabb.

public readonly float GetShortestAxisSize()

Returns

float

The scalar length of the shortest axis of the Aabb.

GetSupport(Vector3)

Returns the support point in a given direction. This is useful for collision detection algorithms.

public readonly Vector3 GetSupport(Vector3 dir)

Parameters

dir Vector3

The direction to find support for.

Returns

Vector3

A vector representing the support.

Grow(float)

Returns a copy of the Aabb grown a given amount of units towards all the sides.

public readonly Aabb Grow(float by)

Parameters

by float

The amount to grow by.

Returns

Aabb

The grown Aabb.

HasPoint(Vector3)

Returns true if the Aabb contains a point, or false otherwise.

public readonly bool HasPoint(Vector3 point)

Parameters

point Vector3

The point to check.

Returns

bool

A bool for whether or not the Aabb contains point.

HasSurface()

Returns true if the Aabb has a surface or a length, and false if the Aabb is empty (all components of Size are zero or negative).

public readonly bool HasSurface()

Returns

bool

A bool for whether or not the Aabb has surface.

HasVolume()

Returns true if the Aabb has area, and false if the Aabb is linear, empty, or has a negative Size. See also Volume.

public readonly bool HasVolume()

Returns

bool

A bool for whether or not the Aabb has volume.

Intersection(Aabb)

Returns the intersection of this Aabb and with.

public readonly Aabb Intersection(Aabb with)

Parameters

with Aabb

The other Aabb.

Returns

Aabb

The clipped Aabb.

Intersects(Aabb)

Returns true if the Aabb overlaps with with (i.e. they have at least one point in common).

public readonly bool Intersects(Aabb with)

Parameters

with Aabb

The other Aabb to check for intersections with.

Returns

bool

A bool for whether or not they are intersecting.

IntersectsPlane(Plane)

Returns true if the Aabb is on both sides of plane.

public readonly bool IntersectsPlane(Plane plane)

Parameters

plane Plane

The Plane to check for intersection.

Returns

bool

A bool for whether or not the Aabb intersects the Plane.

IntersectsSegment(Vector3, Vector3)

Returns true if the Aabb intersects the line segment between from and to.

public readonly bool IntersectsSegment(Vector3 from, Vector3 to)

Parameters

from Vector3

The start of the line segment.

to Vector3

The end of the line segment.

Returns

bool

A bool for whether or not the Aabb intersects the line segment.

IsEqualApprox(Aabb)

Returns true if this AABB and other are approximately equal, by running IsEqualApprox(Vector3) on each component.

public readonly bool IsEqualApprox(Aabb other)

Parameters

other Aabb

The other AABB to compare.

Returns

bool

Whether or not the AABBs structures are approximately equal.

IsFinite()

Returns true if this Aabb is finite, by calling IsFinite(float) on each component.

public readonly bool IsFinite()

Returns

bool

Whether this vector is finite or not.

Merge(Aabb)

Returns a larger Aabb that contains this Aabb and with.

public readonly Aabb Merge(Aabb with)

Parameters

with Aabb

The other Aabb.

Returns

Aabb

The merged Aabb.

ToString()

Converts this Aabb to a string.

public override readonly string ToString()

Returns

string

A string representation of this AABB.

ToString(string)

Converts this Aabb to a string with the given format.

public readonly string ToString(string format)

Parameters

format string

Returns

string

A string representation of this AABB.

Operators

operator ==(Aabb, Aabb)

Returns true if the AABBs are exactly equal. Note: Due to floating-point precision errors, consider using IsEqualApprox(Aabb) instead, which is more reliable.

public static bool operator ==(Aabb left, Aabb right)

Parameters

left Aabb

The left AABB.

right Aabb

The right AABB.

Returns

bool

Whether or not the AABBs are exactly equal.

operator !=(Aabb, Aabb)

Returns true if the AABBs are not equal. Note: Due to floating-point precision errors, consider using IsEqualApprox(Aabb) instead, which is more reliable.

public static bool operator !=(Aabb left, Aabb right)

Parameters

left Aabb

The left AABB.

right Aabb

The right AABB.

Returns

bool

Whether or not the AABBs are not equal.