new BoundingBox( [options])
Creates a new BoundingBox instance.
Parameters:
Name | Type | Argument | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Configuration options for the bounding box Properties
|
- Source:
Methods
-
area()
-
Calculates the area of the bounding box.
- Source:
Returns:
The area (width × height)
- Type
- number
-
center()
-
Calculates the center point of the bounding box.
- Source:
Returns:
The coordinates of the center point
- Type
- Object
-
clone()
-
Creates a clone of this bounding box.
- Source:
Returns:
A new BoundingBox instance with the same coordinates
- Type
- BoundingBox
-
containsPoint(p [, epsilon])
-
Checks if a point is contained within this bounding box. A point is considered inside if its coordinates are greater than or equal to the low corner and less than or equal to the high corner.
Parameters:
Name Type Argument Default Description p
Object The point to check
epsilon
number <optional>
0 Optional tolerance value for boundary checks
- Source:
Returns:
True if the point is inside the box, false otherwise
- Type
- boolean
Example
// Check if a point is inside a box const box = new BoundingBox({xLow: 0, yLow: 0, xHigh: 10, yHigh: 10}); const point = {x: 5, y: 5}; const isInside = box.containsPoint(point); // true // Using epsilon tolerance for boundary cases const boundaryPoint = {x: 10.001, y: 10}; const isInsideWithTolerance = box.containsPoint(boundaryPoint, 0.01); // true
-
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
-
intersection(box)
-
Calculates the intersection of this bounding box with another box.
Parameters:
Name Type Description box
BoundingBox The other bounding box
- Source:
Returns:
A new bounding box representing the intersection, or null if there is no intersection
- Type
- BoundingBox | null
-
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