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 | nullCasts 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 | nullCasts 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 | nullCasts 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
asPolylinestatic
asRectanglestatic
static asRectangle(shape: Shape): Rectangle | nullCasts 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 | nullCasts 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.
