Class: BoundingBox

BoundingBox

Represents an axis-aligned rectangular bounding box that can be wrapped tightly around geometric elements. The box is defined by two opposite vertices (low and high corners) and provides a comprehensive set of utility methods for manipulating and analyzing bounding boxes.


new BoundingBox( [options])

Creates a new BoundingBox instance.

Parameters:
Name Type Argument Description
options Object <optional>

Configuration options for the bounding box

Properties
Name Type Argument Default Description
xLow number <optional>
1e20

X coordinate of the lower corner

yLow number <optional>
1e20

Y coordinate of the lower corner

xHigh number <optional>
-1e20

X coordinate of the upper corner

yHigh number <optional>
-1e20

Y coordinate of the upper corner

Source:

Methods


center()

Calculates the center point of the bounding box.

Source:
Returns:

The coordinates of the center point

Type
Object

corner(i)

Gets the coordinates of a specific corner of the bounding box.

Parameters:
Name Type Description
i number

Corner index (0: bottom-left, 1: bottom-right, 2: top-left, 3: top-right)

Source:
Returns:

The coordinates of the specified corner

Type
Object

fromArray(x)

Initializes the bounding box from an array of coordinates.

Parameters:
Name Type Description
x Array.<number>

Array containing coordinates in order [xLow, yLow, xHigh, yHigh]

Source:

height()

Calculates the height of the bounding box.

Source:
Returns:

The difference between yHigh and yLow

Type
number

intersects(box)

Checks if this bounding box intersects with another bounding box.

Parameters:
Name Type Description
box BoundingBox

The other bounding box to check intersection with

Source:
Returns:

True if the boxes intersect, false otherwise

Type
boolean

isEmpty()

Checks if the bounding box is empty (has no valid area). A box is considered empty if its low corner coordinates are greater than its high corner coordinates.

Source:
Returns:

True if the box is empty, false otherwise

Type
boolean

mergeBox(box)

Enlarges this bounding box to include another bounding box. If this box is empty, it will adopt the dimensions of the input box. If the input box is null, no changes are made.

Parameters:
Name Type Description
box BoundingBox | null

The bounding box to merge with this one

Source:

mergePoint(p)

Enlarges this bounding box to include a point.

Parameters:
Name Type Description
p Object

The point to include in the bounding box

Source:

print()

Prints the bounding box coordinates to the console in a formatted string. Output format: "BOX=xLow, yLow, xHigh, yHigh" with values rounded to 2 decimal places

Source:

quantize(side)

Quantizes the bounding box coordinates by dividing by a specified value and rounding down. This creates a grid-aligned bounding box.

Parameters:
Name Type Description
side number

The value to divide coordinates by

Source:

shift(dx, dy)

Moves the bounding box by the specified displacement.

Parameters:
Name Type Description
dx number

Displacement along the x-axis

dy number

Displacement along the y-axis

Source:

toArray()

Converts the bounding box coordinates to an array.

Source:
Returns:

Array of coordinates in order [xLow, yLow, xHigh, yHigh]

Type
Array.<number>

toEmpty()

Resets the bounding box to an empty state by setting coordinates to extreme values.

Source:

toString()

Creates a space-separated string representation of the bounding box coordinates.

Source:
Returns:

String in format "xLow yLow xHigh yHigh"

Type
string

width()

Calculates the width of the bounding box.

Source:
Returns:

The difference between xHigh and xLow

Type
number