class Geometry · Computations

Shapes

Transforms any shape: copy, reverse, flip, mirror, move, rotate, scale, cycle the start point, and bounding box and centroid.

Static methods

boundingBoxstatic

static boundingBox(shape: Shape | ShapeLike, result?: Box | null): Box

Computes the axis-aligned bounding box of a shape.

shape
The shape to enclose in a bounding box.
result optional
Optional output Box instance.

Returns The smallest axis-aligned box that fully contains shape.

boundingBoxOfShapesstatic

static boundingBoxOfShapes(shapes: Iterable<Shape>, result?: Box | null): Box

Computes the axis-aligned bounding box that contains all shapes in the collection.

shapes
The shapes to enclose.
result optional
Optional output Box instance.

Returns The smallest axis-aligned box that fully contains every shape in shapes.

centroidstatic

static centroid(shape: Shape | ShapeLike, result?: Point | null): Point

Computes the centroid (arithmetic mean position) of all vertices in the shape.

shape
The shape whose centroid to compute.
result optional
Optional output Point instance.

Returns The centroid of shape, or the origin if the shape has no vertices.

copystatic

static copy(shape: Shape | ShapeLike, result?: Shape | null): Shape

Creates a copy of the given shape.

shape
The source shape to copy.
result optional
Optional output Shape instance to populate with the copied data.

Returns A new Shape instance that is a structural copy of shape.

cycleBystatic

static cycleBy(shape: Shape | ShapeLike, offset: number, result?: Shape | null): Shape

Cyclically shifts the vertices of a shape by the specified offset.

shape
The shape whose vertices to cycle.
offset
The number of positions to shift. The vertex at index offset becomes the first vertex (index 0), i.e. a positive value moves every vertex offset positions towards the start. A negative value shifts in the opposite direction. The offset wraps around using modulo arithmetic, so any integer value is valid.
result optional
Optional output Shape instance.

Returns A new Shape with the same vertices in cyclically shifted order. The geometry is unchanged; only the starting vertex differs.

flipXstatic

static flipX(shape: Shape | ShapeLike, anchor: Point | VectorLike, result?: Shape | null): Shape

Reflects a shape across a vertical axis through the specified anchor point.

shape
The shape to reflect.
anchor
The point defining the vertical reflection axis (x = anchor.X).
result optional
Optional output Shape instance.

Returns A new Shape with every vertex mirrored horizontally around anchor.

flipYstatic

static flipY(shape: Shape | ShapeLike, anchor: Point | VectorLike, result?: Shape | null): Shape

Reflects a shape across a horizontal axis through the specified anchor point.

shape
The shape to reflect.
anchor
The point defining the horizontal reflection axis (y = anchor.Y).
result optional
Optional output Shape instance.

Returns A new Shape with every vertex mirrored vertically around anchor.

mirrorstatic

static mirror(shape: Shape | ShapeLike, p1: Point | VectorLike, p2: Point | VectorLike, result?: Shape | null): Shape

Reflects a shape across the infinite line passing through two points.

shape
The shape to reflect.
p1
The first point defining the reflection axis.
p2
The second point defining the reflection axis.
result optional
Optional output Shape instance.

Returns A new Shape with every vertex reflected across the line through p1 and p2. If p1 and p2 are identical the shape is returned unchanged.

moveBystatic

static moveBy(shape: Shape | ShapeLike, direction: Vector | VectorLike, result?: Shape | null): Shape

Translates a shape by the specified direction vector.

shape
The shape to translate.
direction
The translation offset to apply.
result optional
Optional output Shape instance.

Returns A new Shape translated by direction.

orientatestatic

static orientate(shape: Shape | ShapeLike, anchor: Point | VectorLike, sourceOrientation: Vector | VectorLike, targetOrientation: Vector | VectorLike, result?: Shape | null): Shape

Reorients a shape by rotating it from one direction to another around a specified anchor point.

shape
The shape to reorient.
anchor
The pivot point around which the rotation is applied.
sourceOrientation
The direction representing the shape's current orientation.
targetOrientation
The direction representing the desired final orientation.
result optional
Optional output Shape instance.

Returns A new Shape rotated around anchor so that sourceOrientation aligns with targetOrientation. If either direction is zero-length the shape is returned unchanged.

reversedstatic

static reversed(shape: Shape | ShapeLike, result?: Shape | null): Shape

Reverses the vertex order of a shape.

shape
The shape to reverse.
result optional
Optional output Shape instance.

Returns A new Shape whose vertices are in the opposite order to shape. For closed shapes this effectively flips the winding direction.

rotateBystatic

static rotateBy(shape: Shape | ShapeLike, anchor: Point | VectorLike, angle: Real | NumberLike, result?: Shape | null): Shape

Rotates a shape by a given angle around an anchor point.

shape
The shape to rotate.
anchor
The pivot point around which to rotate.
angle
The angle to rotate by, in radians. Positive values rotate from the positive X axis towards the positive Y axis (like Vectors.rotateBy), which is clockwise on screen.
result optional
Optional output Shape instance.

Returns A new Shape rotated by angle around anchor.

scaleBystatic

static scaleBy(shape: Shape | ShapeLike, anchor: Point | VectorLike, scaleX: Real | NumberLike, scaleY: Real | NumberLike, result?: Shape | null): Shape

Scales a shape non-uniformly around an anchor point.

shape
The shape to scale.
anchor
The fixed point around which scaling is applied.
scaleX
The scale factor along the X axis.
scaleY
The scale factor along the Y axis.
result optional
Optional output Shape instance.

Returns A new Shape scaled by (scaleX, scaleY) relative to anchor.

transformstatic

static transform(shape: Shape | ShapeLike, pin: Pin | PinLike, result?: Shape | null): Shape

Applies a similarity transform encoded in a Pin to a shape. The pin's location defines the translation and its orientation defines the combined rotation and uniform scale, where the orientation length is the scale factor and its angle is the rotation.

shape
The shape to transform.
pin
The transform to apply. pin.Location is the translation offset; pin.Orientation is the complex rotation+scale multiplier.
result optional
Optional output Shape instance.

Returns A new Shape with the similarity transform applied to every vertex.