@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
| Parameter | Type | Description |
|---|---|---|
pointA | Cartesian | The first corner point of the rectangle. |
pointB | Cartesian | The opposite corner point of the rectangle. |
Returns
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
| Parameter | Type | Description |
|---|---|---|
rect | Rect | The Rect to convert. |
Returns
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 }
// ]