Class representing a polygon.
Polygon is a multipolygon comprised from a set of [faces]Face.
Face, in turn, is a closed loop of [edges]Edge, where edge may be segment or circular arc

Hierarchy (view full)

Constructors

  • Constructor creates new instance of polygon. With no arguments new polygon is empty.
    Constructor accepts as argument array that define loop of shapes or array of arrays in case of multi polygon
    Loop may be defined in different ways:

    • array of shapes of type Segment or Arc
    • array of points (Point)
    • array of numeric pairs which represent points
    • box or circle object
      Alternatively, it is possible to use polygon.addFace method

    Parameters

    • Rest...args:
          | []
          | [Point[]]
          | [[number, number][]]
          | [(Segment | Arc)[]]
          | [Box | Circle]
          | [(Segment | Arc)[][]]
          | [Point[][]]

      array of shapes or array of arrays

    Returns Polygon

Properties

edges: PlanarSet = ...

Container of edges

faces: PlanarSet = ...

Container of faces (closed loops), may be empty

Accessors

  • get box(): Box
  • (Getter) Returns bounding box of the polygon

    Returns Box

  • get name(): string
  • Shape name

    Returns string

    name of the shape

  • get vertices(): Point[]
  • (Getter) Returns array of vertices

    Returns Point[]

Methods

  • Add new face to polygon. Returns added face

    Parameters

    • Rest...args:
          | [Point[]]
          | [[number, number][]]
          | [(Segment | Arc)[]]
          | [Box | Circle]
          | [Edge, Edge]

      new face may be create with one of the following ways:

      1. array of points that describe closed path (edges are segments)
      2. array of shapes (segments and arcs) which describe closed path
      3. circle - will be added as counterclockwise arc
      4. box - will be added as counterclockwise rectangle
        You can chain method face.reverse() is you need to change direction of the creates face

    Returns Face

  • Returns area of the polygon. Area of an island will be added, area of a hole will be subtracted

    Returns number

  • Create new cloned instance of the polygon

    Returns Polygon

  • Returns true if polygon contains shape: no point of shape lay outside of the polygon, false otherwise

    Parameters

    • shape: Shape<any>

      test shape

    Returns boolean

  • Delete existing face from polygon

    Parameters

    • face: Face

      Face to be deleted

    Returns boolean

  • Return distance and shortest segment between polygon and other shape as array [distance, shortestSegment]

    Parameters

    • shape: Shape<any>

      Shape of one of the types Point, Circle, Line, Segment, Arc or Polygon

    Returns [number, Segment]

  • Returns the first found edge of polygon that contains given point If point is a vertex, return the edge where the point is an end vertex, not a start one

    Parameters

    Returns undefined | Edge

  • Return array of intersection points between polygon and other shape

    Parameters

    • shape: Shape<any>

      Shape of the one of supported types

    Returns Point[]

  • Return true is polygon has no edges

    Returns boolean

  • Clear all faces and create new faces from edges

    Returns void

  • Reverse orientation of all faces to opposite

    Returns Polygon

  • Return new polygon rotated by given angle around given point If point omitted, rotate around origin (0,0) Positive value of angle defines rotation counterclockwise, negative - clockwise

    Parameters

    • angle: number = 0

      rotation angle in radians

    • center: Point = ...

      rotation center, default is (0,0)

    Returns Polygon

    new rotated polygon

  • Return new polygon with coordinates multiplied by scaling factor

    Parameters

    • sx: number

      x-axis scaling factor

    • sy: number

      y-axis scaling factor

    Returns Polygon

  • Return new polygon transformed using affine transformation matrix

    Parameters

    • matrix: Matrix = ...

      affine transformation matrix

    Returns Polygon

    • new polygon
  • Returns new polygon translated by given vector

    Parameters

    • Rest...args: [number, number] | [Vector]

      Translation vector or translation by x and y

    Returns Polygon