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

static area(box: Box | ShapeLike, result?: Real | null): Real

Returns the area of the box.

box
The box to measure.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The area of the box.

aspectRatiostatic

static aspectRatio(box: Box | ShapeLike, result?: Real | null): Real

Computes the aspect ratio of the box as its width divided by its height.

box
The box to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The ratio of the box's width to its height.

bottomstatic

static bottom(box: Box | ShapeLike, result?: Real | null): Real

Returns the Y coordinate of the bottom edge of the box.

box
The box to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The Y coordinate of the bottom edge.

bottomLeftstatic

static bottomLeft(box: Box | ShapeLike, result?: Point | null): Point

Returns the bottom-left corner of the box.

box
The box to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The bottom-left corner point.

bottomRightstatic

static bottomRight(box: Box | ShapeLike, result?: Point | null): Point

Returns the bottom-right corner of the box.

box
The box to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The bottom-right corner point.

bottomSidestatic

static bottomSide(box: Box | ShapeLike, result?: Segment | null): Segment

Returns the bottom side of the box as a line segment.

box
The box to query.
result optional
Optional Segment to write the result into; it is returned. Without it, a new Segment is returned.

Returns The bottom side line segment.

boxstatic

static box(topLeft: Point | VectorLike, width: Real | NumberLike, height: Real | NumberLike, result?: Box | null): Box

Constructs 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.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns The created box.

centerstatic

static center(box: Box | ShapeLike, result?: Point | null): Point

Returns the center point of the box.

box
The box to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The center point of the box.

centeredBoxstatic

static centeredBox(center: Point | VectorLike, width: Real | NumberLike, height: Real | NumberLike, result?: Box | null): Box

Constructs 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.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns The created centered box.

circumferencestatic

static circumference(box: Box | ShapeLike, result?: Real | null): Real

Returns the circumference (perimeter) of the box.

box
The box to measure.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The circumference of the box.

containsBoxstatic

static containsBox(outer: Box | ShapeLike, inner: Box | ShapeLike, result?: Bool | null): Bool

Determines whether the outer box fully contains the inner box.

outer
The box that may contain the other.
inner
The box that may be contained.
result optional
Optional Bool to write the result into; it is returned. Without it, a new Bool is 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): Bool

Determines whether the specified point is contained within the box.

box
The box to test.
point
The point to test for containment.
result optional
Optional Bool to write the result into; it is returned. Without it, a new Bool is returned.

Returns True if the point is inside or on the boundary of the box; otherwise, false.

copystatic

static copy(box: Box | ShapeLike, result?: Box | null): Box

Creates a copy of the specified box.

box
The box to copy.
result optional
Optional box to store the result; if null, a new box is created.

Returns A copy of the specified box.

diameterstatic

static diameter(box: Box | ShapeLike, result?: Real | null): Real

Returns the diameter (diagonal length) of the box.

box
The box to measure.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The diagonal length of the box.

fitIntoBoxstatic

static fitIntoBox(box1: Box | ShapeLike, box2: Box | ShapeLike, result?: Pin | null): Pin

Computes a transformation to fit one box into another box.

box1
The box to be fitted.
box2
The target box to fit into.
result optional
Optional Pin to write the result into; it is returned. Without it, a new Pin is 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): Rectangle

Creates 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.
result optional
Optional Rectangle to write the result into; it is returned. Without it, a new Rectangle is returned.

Returns A rectangle representing the frame around the box with the specified offsets.

heightstatic

static height(box: Box | ShapeLike, result?: Real | null): Real

Returns the height of the box.

box
The box to measure.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The height of the box.

inflatestatic

static inflate(box: Box | ShapeLike, dx: Real | NumberLike, dy: Real | NumberLike, result?: Box | null): Box

Returns 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.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns A box expanded by dx on each horizontal side and dy on each vertical side.

inscribeCirclestatic

static inscribeCircle(box: Box | ShapeLike, result?: Circle | null): Circle

Returns the largest circle that fits inside the box.

box
The box to inscribe into.
result optional
Optional Circle to write the result into; it is returned. Without it, a new Circle is returned.

Returns The inscribed circle.

intersectstatic

static intersect(box: Box | ShapeLike, other: Box | ShapeLike, result?: Box | null): Box

Computes 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.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns The intersection box.

intersectsstatic

static intersects(a: Box | ShapeLike, b: Box | ShapeLike, result?: Bool | null): Bool

Determines whether two boxes overlap.

a
The first box.
b
The second box.
result optional
Optional Bool to write the result into; it is returned. Without it, a new Bool is returned.

Returns True if the boxes share at least one point; otherwise false.

isEmptystatic

static isEmpty(box: Box | ShapeLike, result?: Bool | null): Bool

Determines whether the box has zero or negative area.

box
The box to query.
result optional
Optional Bool to write the result into; it is returned. Without it, a new Bool is returned.

Returns True if the box's width or height is less than or equal to zero; otherwise false.

isSquarestatic

static isSquare(box: Box | ShapeLike, result?: Bool | null): Bool

Determines whether the box is square.

box
The box to query.
result optional
Optional Bool to write the result into; it is returned. Without it, a new Bool is returned.

Returns True if the box's width equals its height; otherwise false.

leftstatic

static left(box: Box | ShapeLike, result?: Real | null): Real

Returns the X coordinate of the left edge of the box.

box
The box to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The X coordinate of the left edge.

leftSidestatic

static leftSide(box: Box | ShapeLike, result?: Segment | null): Segment

Returns the left side of the box as a line segment.

box
The box to query.
result optional
Optional Segment to write the result into; it is returned. Without it, a new Segment is returned.

Returns The left side of the box as a line segment.

longestSidestatic

static longestSide(box: Box | ShapeLike, result?: Real | null): Real

Returns the length of the longer side of the box.

box
The box to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The greater of the box's width and height.

mergestatic

static merge(box1: Box | ShapeLike, box2: Box | ShapeLike, result?: Box | null): Box

Computes the smallest box that contains both specified boxes.

box1
The first box.
box2
The second box.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is 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): Box

Returns 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.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns A box expanded by the specified amount on each side.

rightSidestatic

static rightSide(box: Box | ShapeLike, result?: Segment | null): Segment

Returns the right side of the box as a line segment.

box
The box to query.
result optional
Optional Segment to write the result into; it is returned. Without it, a new Segment is 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): Box

Returns 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.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is 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): Box

Returns 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.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns A box scaled relative to anchor by sx horizontally and sy vertically.

shortestSidestatic

static shortestSide(box: Box | ShapeLike, result?: Real | null): Real

Returns the length of the shorter side of the box.

box
The box to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The lesser of the box's width and height.

spannedBoxstatic

static spannedBox(p1: Point | VectorLike, p2: Point | VectorLike, result?: Box | null): Box

Constructs a box spanning two points.

p1
The first corner point of the box.
p2
The opposite corner point of the box.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns The box spanned by p1 and p2.

topstatic

static top(box: Box | ShapeLike, result?: Real | null): Real

Returns the Y coordinate of the top edge of the box.

box
The box to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The Y coordinate of the top edge.

topLeftstatic

static topLeft(box: Box | ShapeLike, result?: Point | null): Point

Returns the top-left corner of the box.

box
The box to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The top-left corner point of the box.

topRightstatic

static topRight(box: Box | ShapeLike, result?: Point | null): Point

Returns the top-right corner of the box.

box
The box to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The top-right corner point of the box.

topSidestatic

static topSide(box: Box | ShapeLike, result?: Segment | null): Segment

Returns the top side of the box as a line segment.

box
The box to query.
result optional
Optional Segment to write the result into; it is returned. Without it, a new Segment is returned.

Returns The top side of the box as a line segment.

translatestatic

static translate(box: Box | ShapeLike, d: Vector | VectorLike, result?: Box | null): Box

Returns the box translated by the specified direction vector.

box
The box to translate.
d
The direction vector to apply.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns A box with both corners shifted by d.

unionstatic

static union(boxes: Iterable<Shape>, result?: Box | null): Box

Computes the smallest box that contains all of the specified boxes.

boxes
The sequence of boxes to combine.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is 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.
result optional
Optional output Sequence instance.

Returns A sequence of points representing the four corners of the box in clockwise order.

widthstatic

static width(box: Box | ShapeLike, result?: Real | null): Real

Returns the width of the box.

box
The box to measure.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The width of the box.