Defines a 3D axis-aligned bounding box.
The box is defined via two corners - minCorner and maxCorner
new Box(
corner1
?,corner2
?):Box
Creates a box from 2 points. Minimum corner is determined from the minimum values for each coordinate in the given points. Maximum corner is determined from the maximum values.
Default is infinity box where minimum corner is a point with all coordinates equal to Number.NEGATIVE_INFINITY
and maximum corner is a point with all coordinates equal to Number.POSITIVE_INFINITY
.
First corner.
Second corner.
maxCorner:
Point
minCorner:
Point
get center():
Point
Returns a center point - a middle of the diagonal between minCorner and maxCorner.
get xRange():
number
Returns the length of range along X axis.
number
get yRange():
number
Returns the length of range along Y axis.
number
get zRange():
number
Returns the length of range along Z axis.
number
add(
point
):this
Adjusts the box corners so that it contains point
. Takes into account only finite coordinates of point
.
Added point.
this
add(
box
):this
Adjusts the box corners so that it contains box
.
Added box.
this
clear():
this
Resets the box. Assigns infinite values to the coordinates, so that isInfinity() returns true
.
this
clone():
Box
Creates new Box
object with coordinates same as this
.
copy(
other
):this
Copies the coordinates of the other
box to this
.
Copied object.
this
corner(
index
):Point
Returns one of the box corners:
index
equals 0
index
equals 1
Throws exception if index
is not in range [0, 1]
.
number
Corner index.
enlarge(
x
,y
,z
):this
Enlarge the box dimensions by specified values. Each box extent is shifted by 0.5
of the specified shift value to the negative and positive side along respective axis.
number
Value along X axis.
number
Value along Y axis.
number
Value along Z axis.
this
enlarge(
size
):this
Enlarge the box dimensions by specified value. Each box extent is shifted by 0.5 x size
to the negative and positive side along respective axis.
number
Shift value.
this
enlarged(
x
,y
,z
):Box
Returns new Box
object received by performing an enlarge() operation to this
object.
number
Value along X axis.
number
Value along Y axis.
number
Value along Z axis.
enlarged(
size
):Box
Returns new Box
object received by performing an enlarge() operation to this
object.
number
Shift value.
getRange(
index
):number
Returns the length of range along specified axis:
index
equals 0
index
equals 1
index
equals 2
Throws exception if index
is not in range [0, 2]
.
number
Range index.
number
intersects(
other
):boolean
Returns true
the other box has at least one common point with this box.
Checked box.
boolean
isIn(
point
):boolean
Returns true
if the point lies inside the box.
Checked point.
boolean
isInfinity():
boolean
Returns true
if at least one coordinate is infinite.
boolean
multiplied(
scalar
):Box
Returns new Box
object received by performing a multiply() operation to this
object.
number
Scalar value.
multiply(
scalar
):this
Scales box by scalar value.
number
Scalar value.
this
setRange(
index
,min
,max
):this
Sets one range of the box to the specified values:
index
equals 0
index
equals 1
index
equals 2
Throws exception if index
is not in range [0, 2]
.
number
Range index.
number
Minimum corner coordinate.
number
Maximum corner coordinate.
this
setXRange(
min
,max
):this
Sets the range of box along X axis to the specified values.
number
Minimum corner coordinate.
number
Maximum corner coordinate.
this
setYRange(
min
,max
):this
Sets the range of box along Y axis to the specified values.
number
Minimum corner coordinate.
number
Maximum corner coordinate.
this
setZRange(
min
,max
):this
Sets the range of box along Z axis to the specified values.
number
Minimum corner coordinate.
number
Maximum corner coordinate.
this
transform(
transformation
):this
Transforms the box.
If the transformation does not contain anything besides perhaps a translation, the box dimensions are kept as is and its position is recalculated accordingly.
If rotation or scale are present, all box corners are transformed and a new axis-aligned box containing them is built. If the box was infinite in one of the directions, the new box will also be infinite in the directions that are results of applying the transformation to the original directions. The new box most likely has larger dimensions than the original.
For more accurate results, it's recommended instead to transform the arguments the box was built from and only then calculate the box.
Transformation.
this
transformed(
transformation
):Box
Returns new Box
object received by performing a transform() operation to this
object.
Transformation.