Create a bounding box from two intervals.
The dimensions of the bounding box along the environment's x-axis (Vector.xAxis). The box will be from xRange.min to xRange.max.
The dimensions of the bounding box along the environment's y-axis.
Gets the area of the bounding box.
Gets the point at the center of the bounding box.
Gets the corner of the bounding box that has the largest x and y values.
Gets the corner of the bounding box that has the smallest x and y values.
Gets the position of the bounding box along the environment's x-axis (Vector.xAxis).
Gets the position of the bounding box along the environment's x-axis (Vector.xAxis).
Creates a bounding box from two corner points.
One corner of the bounding box.
The opposite corner of the bounding box.
Returns the smallest bounding box that contains all the points.
The points to encapsulate in a bounding box.
Finds the overlapping portion of two bounding boxes and returns it as a new bounding box.
The first bounding box to intersect
The second bounding box to intersect
Returns the smallest bounding box that contains two other bounding boxes.
The first bounding box to encapsulate.
The second bounding box to encapsulate.
Finds the closest point on the bounding box and returns the point.
Target to get closest to.
If true, the closest point can be within the bounding box. If false, the closest point can only be on the bounding box's outer edge.
Checks whether a point is inside the bounding box.
Point to test for containment
If true, the point needs to be entirely inside the bounding box and can't be coincident with the edge.
The distance the point can be outside the box and still considered inside.
Gets one of the bounding box's four corners.
If true, point will be at the min x value. If false, it will be at max.
If true, point will be at the min y value. If false, it will be at max.
The bounding box to compare against.
Gets the four corners of the bounding box. The order is: [[minX, minY], [minX, maxY], [maxX, maxY], [maxX, minY]].
Gets the four edges of the bounding box. Follows the order in getCorners.
Evenly increases the size of the bounding box in all directions. Returns the enlarged bounding box.
The amount to inflate each side of the bounding box.
Checks whether the bounding box overlaps another. Returns true if it does.
The box to check for overlap.
Remaps a point from the u-v space of the bounding box to the global coordinate system. This is the opposite of remapToBox.
The normalized distance along the x-axis of the bounding box.
The normalized distance along the y-axis of the bounding box.
The uvPoint remapped to the global coordinate system.
Remaps a point from the u-v space of the bounding box to the global coordinate system. This is the opposite of remapToBox.
A point in the u-v coordinates of the bounding box. The point's x value is the normalized distance along the x-axis of the bounding box (u-direction). The point's y value is the normalized distance along the y-axis of the bounding box (v-direction).
The uvPoint remapped to the global coordinate system.
Gets the edge of the bounding box as a closed polyline.
Gets the bounding box as a string in the format: [xRange,yRange]
.
Creates a copy of the bounding box with a different xRange.
The xRange of the new bounding box.
Creates a copy of the bounding box with a different yRange.
The yRange of the new bounding box.
Translates the geometry from one coordinate system to another while keeping
the geometry in the same position. In other words, if the geometry is currently
described relative to planeFrom
, after changeBasis,
it will be in the same position but described relative to planeTo
.
The coordinate system the geometry is currently described relative to.
The coordinate system to describe the geometry relative to.
The geometry in the new coordinate system.
Rotates the geometry about (0,0).
Angle to rotate the geometry (in radians). The direction is counter-clockwise.
Rotates the geometry about a point.
Angle to rotate the geometry (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.
Point to pivot the geometry about.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x- and y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry about a point and returns the resized geometry.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Center of scaling. Everything will shrink or expand away from this point.
Transforms the bounding box by a transform matrix and returns the result.
import { BoundingBox, IntervalSorted, Transform } from 'shapetypes';
// Create bounding box
const bb = new BoundingBox(new IntervalSorted(0, 10), new IntervalSorted(5, 25));
console.log(bb.area);
// => 200
// Scale using a transform matrix
const matrix = Transform.scale(2);
const scaled = bb.transform(matrix);
console.log(scaled.area);
// => 800
// Scale using the direct method
const otherScaled = bb.scale(2);
console.log(otherScaled.area);
// => 800
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction and distance to move the geometry.
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction to move the geometry.
The distance to move the geometry.
Generated using TypeDoc
A rectangle aligned to the environment's x- and y-axis (Vector.xAxis. A bounding box is defined by two IntervalSorteds, which give the dimensions of the rectangle along the x- and y-axis.
Example
import { BoundingBox, IntervalSorted, Point } from 'shapetypes'; // Create a new bounding box const bb = new BoundingBox(new IntervalSorted(0, 10), new IntervalSorted(5, 25)); // Get properties of the bounding box console.log(bb.area); // => 200 console.log(bb.center.toString()); // => '(5,15)' // Test for containment console.log(bb.contains(new Point(5, 15))); // => True // Change the bounding box's xRange const shifted = bb.withXRange(new IntervalSorted(0, 20)); console.log(shifted.area); // => 400 // Scale the bounding box const scaled = bb.scale(2); console.log(scaled.area); // => 800