class Geometry · Computations
Boxes
Computations on boxes (axis-parallel rectangles): their sides and corners, size and area, containment and intersection, and boxes made by growing, padding, merging or fitting.
Static methods
areastatic
aspectRatiostatic
static aspectRatio(box: Box | ShapeLike, result?: Real | null): RealComputes the aspect ratio of the box as its width divided by its height.
box- The box to query.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The ratio of the box's width to its height.
bottomstatic
bottomLeftstatic
bottomRightstatic
bottomSidestatic
boxstatic
static box(topLeft: Point | VectorLike, width: Real | NumberLike, height: Real | NumberLike, result?: Box | null): BoxConstructs a box from the top-left point, width, and height.
topLeft- The top-left corner of the box.
width- The width of the box.
height- The height of the box.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns The created box.
centerstatic
centeredBoxstatic
static centeredBox(center: Point | VectorLike, width: Real | NumberLike, height: Real | NumberLike, result?: Box | null): BoxConstructs a box centered at a given point with specified width and height.
center- The center point of the box.
width- The width of the box.
height- The height of the box.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns The created centered box.
circumferencestatic
containsBoxstatic
static containsBox(outer: Box | ShapeLike, inner: Box | ShapeLike, result?: Bool | null): BoolDetermines whether the outer box fully contains the inner box.
outer- The box that may contain the other.
inner- The box that may be contained.
resultoptional- Optional
Boolto write the result into; it is returned. Without it, a newBoolis returned.
Returns True if every point of inner lies within outer; otherwise false.
containsPointstatic
static containsPoint(box: Box | ShapeLike, point: Point | VectorLike, result?: Bool | null): BoolDetermines whether the specified point is contained within the box.
box- The box to test.
point- The point to test for containment.
resultoptional- Optional
Boolto write the result into; it is returned. Without it, a newBoolis returned.
Returns True if the point is inside or on the boundary of the box; otherwise, false.
copystatic
diameterstatic
fitIntoBoxstatic
static fitIntoBox(box1: Box | ShapeLike, box2: Box | ShapeLike, result?: Pin | null): PinComputes a transformation to fit one box into another box.
box1- The box to be fitted.
box2- The target box to fit into.
resultoptional- Optional
Pinto write the result into; it is returned. Without it, a newPinis returned.
Returns A Pin describing the transformation where the position represents the translation vector and the length of the orientation vector represents the scale factor.
framestatic
static frame(box: Box | ShapeLike, minXOffset: Real | NumberLike, minYOffset: Real | NumberLike, maxXOffset: Real | NumberLike, maxYOffset: Real | NumberLike, result?: Rectangle | null): RectangleCreates a rectangle frame around the box with specified offsets on each side.
box- The box to create a frame around.
minXOffset- The offset to apply on the left (minimum X) side.
minYOffset- The offset to apply on the top (minimum Y) side.
maxXOffset- The offset to apply on the right (maximum X) side.
maxYOffset- The offset to apply on the bottom (maximum Y) side.
resultoptional- Optional
Rectangleto write the result into; it is returned. Without it, a newRectangleis returned.
Returns A rectangle representing the frame around the box with the specified offsets.
heightstatic
inflatestatic
static inflate(box: Box | ShapeLike, dx: Real | NumberLike, dy: Real | NumberLike, result?: Box | null): BoxReturns a box expanded horizontally and vertically by the specified amounts on each side.
Shrinking by more than half the width or height is not clamped: the result is inverted (its
minimum corner lies beyond its maximum corner) and isEmpty is true.
box- The box to expand.
dx- The amount to add to the left and right sides. Negative values shrink the box horizontally.
dy- The amount to add to the top and bottom sides. Negative values shrink the box vertically.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns A box expanded by dx on each horizontal side and dy on each vertical side.
inscribeCirclestatic
intersectstatic
static intersect(box: Box | ShapeLike, other: Box | ShapeLike, result?: Box | null): BoxComputes the intersection of two boxes.
For boxes that don't overlap the result has zero size, at the point where their overlap would
begin (the larger of the two minimum corners), and isEmpty is true.
box- The first box.
other- The second box.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns The intersection box.
intersectsstatic
static intersects(a: Box | ShapeLike, b: Box | ShapeLike, result?: Bool | null): BoolDetermines whether two boxes overlap.
a- The first box.
b- The second box.
resultoptional- Optional
Boolto write the result into; it is returned. Without it, a newBoolis returned.
Returns True if the boxes share at least one point; otherwise false.
isEmptystatic
static isEmpty(box: Box | ShapeLike, result?: Bool | null): BoolDetermines whether the box has zero or negative area.
box- The box to query.
resultoptional- Optional
Boolto write the result into; it is returned. Without it, a newBoolis returned.
Returns True if the box's width or height is less than or equal to zero; otherwise false.
isSquarestatic
leftstatic
leftSidestatic
static leftSide(box: Box | ShapeLike, result?: Segment | null): SegmentReturns the left side of the box as a line segment.
box- The box to query.
resultoptional- Optional
Segmentto write the result into; it is returned. Without it, a newSegmentis returned.
Returns The left side of the box as a line segment.
longestSidestatic
mergestatic
static merge(box1: Box | ShapeLike, box2: Box | ShapeLike, result?: Box | null): BoxComputes the smallest box that contains both specified boxes.
box1- The first box.
box2- The second box.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns The smallest box that contains both box1 and box2.
padstatic
static pad(box: Box | ShapeLike, left: Real | NumberLike, top: Real | NumberLike, right: Real | NumberLike, bottom: Real | NumberLike, result?: Box | null): BoxReturns a box expanded by the specified amounts on each individual side.
box- The box to expand.
left- The amount to add to the left side. Negative values shrink the box from the left.
top- The amount to add to the top side. Negative values shrink the box from the top.
right- The amount to add to the right side. Negative values shrink the box from the right.
bottom- The amount to add to the bottom side. Negative values shrink the box from the bottom.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns A box expanded by the specified amount on each side.
rightstatic
rightSidestatic
static rightSide(box: Box | ShapeLike, result?: Segment | null): SegmentReturns the right side of the box as a line segment.
box- The box to query.
resultoptional- Optional
Segmentto write the result into; it is returned. Without it, a newSegmentis returned.
Returns The right side of the box as a line segment.
scalestatic
static scale(box: Box | ShapeLike, sx: Real | NumberLike, sy: Real | NumberLike, result?: Box | null): BoxReturns a box scaled around its center by the specified factors on each axis.
A negative factor mirrors the box at its center: the result is inverted on that axis and
isEmpty is true.
box- The box to scale.
sx- The scale factor applied to the width.
sy- The scale factor applied to the height.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns A box with the same center as box, its width multiplied by sx and its height multiplied by sy.
scaleAroundstatic
static scaleAround(box: Box | ShapeLike, anchor: Point | VectorLike, sx: Real | NumberLike, sy: Real | NumberLike, result?: Box | null): BoxReturns a box scaled around the specified anchor point by the given factors on each axis.
box- The box to scale.
anchor- The fixed point around which the box is scaled.
sx- The scale factor applied along the X axis.
sy- The scale factor applied along the Y axis.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns A box scaled relative to anchor by sx horizontally and sy vertically.
shortestSidestatic
spannedBoxstatic
static spannedBox(p1: Point | VectorLike, p2: Point | VectorLike, result?: Box | null): BoxConstructs a box spanning two points.
p1- The first corner point of the box.
p2- The opposite corner point of the box.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns The box spanned by p1 and p2.
topstatic
topLeftstatic
topRightstatic
topSidestatic
static topSide(box: Box | ShapeLike, result?: Segment | null): SegmentReturns the top side of the box as a line segment.
box- The box to query.
resultoptional- Optional
Segmentto write the result into; it is returned. Without it, a newSegmentis returned.
Returns The top side of the box as a line segment.
translatestatic
static translate(box: Box | ShapeLike, d: Vector | VectorLike, result?: Box | null): BoxReturns the box translated by the specified direction vector.
box- The box to translate.
d- The direction vector to apply.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns A box with both corners shifted by d.
unionstatic
static union(boxes: Iterable<Shape>, result?: Box | null): BoxComputes the smallest box that contains all of the specified boxes.
boxes- The sequence of boxes to combine.
resultoptional- Optional
Boxto write the result into; it is returned. Without it, a newBoxis returned.
Returns The smallest box that contains every box in the sequence.
verticesstatic
static vertices(box: Box | ShapeLike, result?: Sequence<Vector> | null): Sequence<Vector>Returns all four vertices of the box as a sequence of points in clockwise order starting from the top-left corner.
box- The box to query.
resultoptional- Optional output
Sequenceinstance.
Returns A sequence of points representing the four corners of the box in clockwise order.
