Class BoundingBox

Class BoundingBox

Package: @aspose/3d (v24.12.0)

BoundingBox represents an axis-aligned bounding box (AABB) in 3D space. It stores a minimum corner and a maximum corner as plain objects with x, y, z fields. A newly constructed BoundingBox() with no arguments is in the “null” state — minimum returns +Infinity and maximum returns -Infinity — and expands correctly when points are added via merge(). BoundingBox is exported from the @aspose/3d/utilities sub-path.

export class BoundingBox
import { BoundingBox } from '@aspose/3d/utilities';

Examples

Compute a bounding box for a set of points.

import { BoundingBox, Vector3 } from '@aspose/3d/utilities';

const points = [
  new Vector3(-1, 0, -1),
  new Vector3(1, 2, 1),
  new Vector3(0, -0.5, 0),
];

const bbox = new BoundingBox();
for (const p of points) {
  bbox.merge(p);
}

console.log(`Min: (${bbox.minimum.x}, ${bbox.minimum.y}, ${bbox.minimum.z})`);
// Min: (-1, -0.5, -1)
console.log(`Max: (${bbox.maximum.x}, ${bbox.maximum.y}, ${bbox.maximum.z})`);
// Max: (1, 2, 1)

const c = bbox.center;
console.log(`Center: (${c.x}, ${c.y.toFixed(3)}, ${c.z})`);
// Center: (0, 0.750, 0)

Constructors

SignatureDescription
new BoundingBox()Creates a null bounding box. Expands when merge() is called.
new BoundingBox(minimum, maximum)Creates a box from two {x, y, z} corner objects.
new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ)Creates a box from six scalar components.

Static Properties

PropertyTypeDescription
BoundingBox.nullBoundingBoxA null bounding box (no extent, not initialized).
BoundingBox.infiniteBoundingBoxA box spanning the entire number range from -Infinity to +Infinity.

Properties

Important naming: BoundingBox uses minimum and maximum — not min and max.

PropertyTypeDescription
minimum{x: number, y: number, z: number} (read-only)The corner with the smallest x, y, z values. Returns +Infinity on each axis when the box is null.
maximum{x: number, y: number, z: number} (read-only)The corner with the largest x, y, z values. Returns -Infinity on each axis when the box is null.
center{x: number, y: number, z: number} (read-only)The geometric center, computed as (minimum + maximum) / 2. Returns (0, 0, 0) when null.
size{x: number, y: number, z: number} (read-only)The dimensions of the box: maximum - minimum per axis.
extentBoundingBoxExtent (read-only)Half-extents along each axis. Each field is Math.abs(size / 2).

Methods

merge(point)

Expands the bounding box to include a point. Accepts a {x, y, z} object, a Vector3, an array of 3 numbers, or three separate (x, y, z) arguments.

merge(point: Vector3 | {x: number, y: number, z: number}): void
merge(x: number, y: number, z: number): void

Examples

import { BoundingBox, Vector3 } from '@aspose/3d/utilities';

const bb = new BoundingBox();
bb.merge(new Vector3(2, 3, 4));
bb.merge(-1, 0, 0);
console.log(`Min X: ${bb.minimum.x}`); // Min X: -1
console.log(`Max Y: ${bb.maximum.y}`); // Max Y: 3

contains(arg)

Returns true if the given point or bounding box is fully inside this box. Accepts a {x, y, z} point object, a Vector3, or another BoundingBox.

contains(arg: Vector3 | {x: number, y: number, z: number} | BoundingBox): boolean

Examples

import { BoundingBox, Vector3 } from '@aspose/3d/utilities';

const bb = new BoundingBox(-1, -1, -1, 1, 1, 1);
console.log(bb.contains(new Vector3(0, 0, 0)));  // true
console.log(bb.contains(new Vector3(2, 0, 0)));  // false

overlapsWith(box)

Returns true if this bounding box overlaps with another BoundingBox (touching edges count as overlapping).

overlapsWith(box: BoundingBox): boolean

scale()

Returns the maximum absolute coordinate value across all corners, representing the dominant scale of the bounding box. Returns 0 when the box is null.

scale(): number

BoundingBoxExtent

BoundingBoxExtent is a companion class returned by BoundingBox.extent. It stores half-extents along each axis.

PropertyTypeDescription
extentXnumberHalf-width along X.
extentYnumberHalf-height along Y.
extentZnumberHalf-depth along Z.