class Geometry · Shapes

Cast

Gives a shape a more specific shape type, so that the computations for that type accept it.

as… checks the number of points and returns null if it doesn't fit (asPolyline and asPolygon don't check); to… doesn't check.

Static methods

asArcstatic

static asArc(shape: Shape): Arc | null

Casts a generic shape to an arc defined by three points.

Use it to pass a circle to an Arcs function on purpose: the three points of the circle are then read as an arc (from the first through the second to the third point), not as the full circle.

shape
The shape object to cast.

Returns The shape cast as an arc, or null if the shape does not have exactly 3 points.

asBoxstatic

static asBox(shape: Shape): Box | null

Casts a generic shape to a box (rectangle) type.

Validates that the shape contains exactly 2 control points before casting. A box is defined by two control points representing its bounding corners.

shape
The shape object to cast.

Returns The shape cast as a box, or null if the shape does not have exactly 2 points.

asCirclestatic

static asCircle(shape: Shape): Circle | null

Casts a generic shape to a circle defined by three points.

Validates that the shape contains exactly 3 control points before casting. A circle defined by three points requires exactly three control points to be valid.

shape
The shape object to cast.

Returns The shape cast as a circle, or null if the shape does not have exactly 3 points.

asPolygonstatic

static asPolygon(shape: Shape): Polygon

Casts a generic shape to a polygon type.

Performs a direct type assertion without validation.

shape
The shape object to cast.

Returns The shape cast as a polygon.

asPolylinestatic

static asPolyline(shape: Shape): Polyline

Casts a generic shape to a polyline type.

Performs a direct type assertion without validation.

shape
The shape object to cast.

Returns The shape cast as a polyline.

asRectanglestatic

static asRectangle(shape: Shape): Rectangle | null

Casts a generic shape to a rectangle type.

Validates that the shape contains exactly 4 control points before casting. A rectangle is defined by four control points representing its corners.

shape
The shape object to cast.

Returns The shape cast as a rectangle, or null if the shape does not have exactly 4 points.

asSegmentstatic

static asSegment(shape: Shape): Segment | null

Casts a generic shape to a line segment type.

Validates that the shape contains exactly 2 control points before casting. A line segment is defined by two control points representing its endpoints.

shape
The shape object to cast.

Returns The shape cast as a line segment, or null if the shape does not have exactly 2 points.

toArcstatic

static toArc(shape: Shape): Arc

Casts a generic shape to an arc defined by three points.

Performs a direct type assertion without validation. See asArc.

shape
The shape object to cast.

Returns The shape cast as an arc.

toBoxstatic

static toBox(shape: Shape): Box

Casts a generic shape to a box (rectangle) type.

Performs a direct type assertion without validation.

shape
The shape object to cast.

Returns The shape cast as a box.

toCirclestatic

static toCircle(shape: Shape): Circle

Casts a generic shape to a circle defined by three points.

Performs a direct type assertion without validation.

shape
The shape object to cast.

Returns The shape cast as a circle.

toRectanglestatic

static toRectangle(shape: Shape): Rectangle

Casts a generic shape to a rectangle type.

Performs a direct type assertion without validation.

shape
The shape object to cast.

Returns The shape cast as a rectangle.

toSegmentstatic

static toSegment(shape: Shape): Segment

Casts a generic shape to a line segment type.

Performs a direct type assertion without validation.

shape
The shape object to cast.

Returns The shape cast as a line segment.