BoundingBox2D

View source

Represents a 2D axis-aligned bounds value for rectangular regions.

Use BoundingBox2D as a standalone geometry value when an API needs a box-shaped region.

Use the static helpers to copy, translate, or combine boxes without changing the source values. The deprecated instance wrappers remain for compatibility but log warnings when called.

Examples

import { BoundingBox2D } from '@wimaengine/geometry'

const local = new BoundingBox2D(-1, -1, 1, 1)
const search = BoundingBox2D.translate(local, 10, 0)
// `search` is a translated box with coordinates from 9 to 11 on x.

Constructor


constructor(minX?: number, minY?: number, maxX?: number, maxY?: number)

View source

Creates a 2D axis-aligned bounding box.

The constructor stores the supplied coordinates directly: minX and minY initialize BoundingBox2D#min, while maxX and maxY initialize BoundingBox2D#max. All four coordinates default to 0; the constructor does not reorder them or enforce that min is below max.

Parameters

NameDescriptionDefault
minX?

Lower x coordinate.

0
minY?

Lower y coordinate.

0
maxX?

Upper x coordinate.

0
maxY?

Upper y coordinate.

0

Properties


type: number

View source

Identifies this bound as a 2D axis-aligned box.

Default: BoundType.Box2D

max: Vector2

View source

The upper coordinate on each axis.

min: Vector2

View source

The lower limit of the bounding box.

Methods


translate(x: number, y: number): BoundingBox2D

View source

Translates this box in place.

Prefer the static BoundingBox2D.translate helper. This deprecated wrapper logs a deprecation warning and returns this box after applying the offset.

Parameters

NameDescriptionDefault
x

Offset on the x axis.

—
y

Offset on the y axis.

—

Returns

This box after translation.

  • @deprecated Use BoundingBox2D.translate.

clone(): BoundingBox2D

View source

Creates a deep copy of this box.

Prefer BoundingBox2D.copy. This deprecated wrapper logs a deprecation warning and returns a new box with copied min and max vectors.

Returns

A new box with the same coordinates.

  • @deprecated Use BoundingBox2D.copy.

copy(bounds: BoundingBox2D): void

View source

Copies another box into this box in place.

Prefer BoundingBox2D.copy. This deprecated wrapper logs a deprecation warning and returns undefined.

Parameters

NameDescriptionDefault
bounds

Source box.

—
  • @deprecated Use BoundingBox2D.copy.

staticcopy(bound: BoundingBox2D, out?: BoundingBox2D): BoundingBox2D

View source

Copies the coordinates of a box into an output box.

Only the min and max coordinates are copied. The source is not modified, and out defaults to a new BoundingBox2D.

Parameters

NameDescriptionDefault
bound

Source box.

—
out?

Output box to mutate.

...

Returns

The output box.

staticserialize(value: BoundingBox2D): BoundingBox2DSerial

View source

Serializes a box to its plain coordinate representation.

The result contains max and min vector data. It does not include the runtime type field.

Parameters

NameDescriptionDefault
value

Box to serialize.

—

Returns

Serialized coordinate data.

staticdeserialize(value: BoundingBox2DSerial, out?: BoundingBox2D): BoundingBox2D

View source

Restores box coordinates from serialized data.

max and min are written into the supplied output, or into a new box when out is omitted. Any serialized type property is ignored.

Parameters

NameDescriptionDefault
value

Serialized coordinate data.

—
out?

Output box to mutate.

...

Returns

The restored output box.

staticvalidateSerial(value: unknown): value is BoundingBox2DSerial

View source

Checks whether a value contains valid serialized box coordinates.

The check requires an object with valid max and min vector data. It does not validate a type field, coordinate ordering, or extra fields.

Parameters

NameDescriptionDefault
value

Value to validate.

—

Returns

Whether the value is valid.

statictranslate(bound: BoundingBox2D, x: number, y: number, out?: BoundingBox2D): BoundingBox2D

View source

Translates a box by an x/y offset.

The source is not modified unless it is also supplied as out. All four coordinates are written to out, which defaults to a new box.

Parameters

NameDescriptionDefault
bound

Source box.

—
x

Offset on the x axis.

—
y

Offset on the y axis.

—
out?

Output box to mutate.

...

Returns

The translated output box.

staticunion(bound1: BoundingBox2D, bound2: BoundingBox2D, out?: BoundingBox2D): BoundingBox2D

View source

Combines two bounds to create a new one that covers the previous two.

The output takes the component-wise minimum of the two min vectors and the component-wise maximum of the two max vectors. Inputs are not modified, and out defaults to a new box.

Parameters

NameDescriptionDefault
bound1

First source box.

—
bound2

Second source box.

—
out?

Output box to mutate.

...

Returns

The union output box.