Skip to content

@technobuddha > library > Geometry > Polygon

Function: toPolygon()

Converts two Cartesian points or a Rect into a Polygon.

Call Signature

ts
function toPolygon(pointA: Cartesian, pointB: Cartesian): Polygon;

Defined in: to-polygon.ts:23

Converts two Cartesian points into a Polygon.

Construct a rectangle defined by two points as opposite corners.

Parameters

ParameterTypeDescription
pointACartesianThe first corner point of the rectangle.
pointBCartesianThe opposite corner point of the rectangle.

Returns

Polygon

A rectangle shaped Polygon.

Example

typescript
toPolygon({ x: 1, y: 2 }, { x: 4, y: 6 });
// [
//   { x: 1, y: 2 },
//   { x: 4, y: 2 },
//   { x: 4, y: 6 },
//   { x: 1, y: 6 }
// ]

Call Signature

ts
function toPolygon(rect: Rect): Polygon;

Defined in: src/to-polygon.ts:43

Convert a Rect into a Polygon.

Construct a rectangle defined by location and dimensions.

Parameters

ParameterTypeDescription
rectRectThe Rect to convert.

Returns

Polygon

A rectangle shaped Polygon.

Example

typescript
toPolygon({ x: 1, y: 2, width: 3, height: 4 });
// [
//   { x: 1, y: 2 },
//   { x: 4, y: 2 },
//   { x: 4, y: 6 },
//   { x: 1, y: 6 }
// ]