Skip to content

Engine → Core → aabb.h

aabb

Syntax

struct CONJURE_API aabb

Variables

AccessNameTypeDefaultDescription
publicmaxvec3vec3(-F32_MAX)
publicminvec3vec3(F32_MAX)

Functions

Public

center

[[nodiscard]] vec3 center() const noexcept;

Midpoint of min and max.

closest_point

[[nodiscard]] vec3 closest_point(
    vec3 point) const noexcept;

The point inside or on the box nearest to point (point itself when inside). An invalid box has no surface and returns point unchanged.

contains

[[nodiscard]] bool contains(
    vec3 point) const noexcept;

True when the point lies inside or on the box. Always false for an invalid box.

[[nodiscard]] bool contains(
    const aabb &other) const noexcept;

True when other lies entirely inside or on this box. False when either box is invalid.

corners

[[nodiscard]] std::array<vec3, 8> corners() const noexcept;

The eight corners, in the order min, +x, +y, +xy, +z, +xz, +yz, max (bit 0 = x at max, bit 1 = y at max, bit 2 = z at max).

distance_squared

[[nodiscard]] f32 distance_squared(
    vec3 point) const noexcept;

Squared distance from point to the box surface, 0 when inside. 0 for an invalid box (like surface_area and volume).

expand

void expand(
    vec3 point) noexcept;

Grows the box to include a point.

void expand(
    const aabb &other) noexcept;

Grows the box to include another box. An invalid other box is ignored.

extents

[[nodiscard]] vec3 extents() const noexcept;

Half the size on each axis.

from_center_extents

[[nodiscard]] static aabb from_center_extents(
    vec3 centerPoint,
    vec3 halfExtents) noexcept;

A box with the given center and half-size on each axis (negative extents are made positive).

from_points

[[nodiscard]] static aabb from_points(
    vec3 a,
    vec3 b) noexcept;

A box from two arbitrary corners (they need not be ordered).

inflated

[[nodiscard]] aabb inflated(
    f32 amount) const noexcept;

Grows the box by amount on every side (shrinks for negative amounts).

intersection

[[nodiscard]] aabb intersection(
    const aabb &other) const noexcept;

The overlap of both boxes; invalid when they do not intersect.

intersects

[[nodiscard]] bool intersects(
    const aabb &other) const noexcept;

True when the boxes overlap or touch. False when either box is invalid.

is_valid

[[nodiscard]] bool is_valid() const noexcept;

True when min <= max on every axis (a point or a degenerate flat box is valid).

size

[[nodiscard]] vec3 size() const noexcept;

max - min.

surface_area

[[nodiscard]] f32 surface_area() const noexcept;

Total area of the six faces; 0 for an invalid box.

transformed

[[nodiscard]] aabb transformed(
    const mat4 &matrix) const noexcept;

The axis-aligned box enclosing all eight transformed corners (conservative under rotation). Affine matrices only: the bottom row is ignored (no perspective divide), so a projection matrix yields a meaningless box; use frustum::corners for view volumes. An invalid box stays invalid.

volume

[[nodiscard]] f32 volume() const noexcept;

Enclosed volume; 0 for an invalid box.

Operator Overloads

Public

operator==

[[nodiscard]] bool operator==(
    const aabb &other) const = default;