polygon2.rectangle

An axis-aligned rectangle, counter-clockwise from its lower-left corner.

GeometricSince 0.4.0

Usage

TypeScript
Polygon2.rectangle(width: number, height: number, center?: Point2): Result<Polygon2>

Parameters

  • widthnumber

    Extent along x; must be positive. Required. In model.

  • heightnumber

    Extent along y; must be positive. Required. In model.

  • centerPoint2

    The rectangle’s centre. Default Point2.origin. In model.

Returns

Ok with a four-corner counter-clockwise polygon.

Errors

Guarantees

  • area() equals width · height
  • isCounterClockwise() is true
  • its bounding box is centred on center
  • The same result on every machine.

Example

TypeScript
Polygon2.rectangle(4, 2).value.signedArea() // → 8

See also