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
boundingBoxOfShapesstatic
static boundingBoxOfShapes(shapes: Iterable<Shape>, result?: Box | null): BoxComputes the axis-aligned bounding box that contains all shapes in the collection.
shapes- The shapes to enclose.
resultoptional- Optional output
Boxinstance.
Returns The smallest axis-aligned box that fully contains every shape in shapes.
centroidstatic
static centroid(shape: Shape | ShapeLike, result?: Point | null): PointComputes the centroid (arithmetic mean position) of all vertices in the shape.
shape- The shape whose centroid to compute.
resultoptional- Optional output
Pointinstance.
Returns The centroid of shape, or the origin if the shape has no vertices.
copystatic
cycleBystatic
static cycleBy(shape: Shape | ShapeLike, offset: number, result?: Shape | null): ShapeCyclically 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
offsetbecomes the first vertex (index 0), i.e. a positive value moves every vertexoffsetpositions towards the start. A negative value shifts in the opposite direction. The offset wraps around using modulo arithmetic, so any integer value is valid. resultoptional- Optional output
Shapeinstance.
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): ShapeReflects 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).
resultoptional- Optional output
Shapeinstance.
Returns A new Shape with every vertex mirrored horizontally around anchor.
flipYstatic
static flipY(shape: Shape | ShapeLike, anchor: Point | VectorLike, result?: Shape | null): ShapeReflects 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).
resultoptional- Optional output
Shapeinstance.
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): ShapeReflects 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.
resultoptional- Optional output
Shapeinstance.
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): ShapeTranslates a shape by the specified direction vector.
shape- The shape to translate.
direction- The translation offset to apply.
resultoptional- Optional output
Shapeinstance.
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): ShapeReorients 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.
resultoptional- Optional output
Shapeinstance.
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): ShapeReverses the vertex order of a shape.
shape- The shape to reverse.
resultoptional- Optional output
Shapeinstance.
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): ShapeRotates 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. resultoptional- Optional output
Shapeinstance.
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): ShapeScales 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.
resultoptional- Optional output
Shapeinstance.
Returns A new Shape scaled by (scaleX, scaleY) relative to anchor.
transformstatic
static transform(shape: Shape | ShapeLike, pin: Pin | PinLike, result?: Shape | null): ShapeApplies 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.Locationis the translation offset;pin.Orientationis the complex rotation+scale multiplier. resultoptional- Optional output
Shapeinstance.
Returns A new Shape with the similarity transform applied to every vertex.
