Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Polygon

A polygon describes a closed two-dimensional shape bounded by a number of straight line segments.

The vertices of a polygon form a closed path (i.e. the last vertex will be connected to the first). It is recommended to provide the vertices in clockwise order. Self-intersecting paths are not supported and will give wrong results on triangulation, area calculation, etc.

Hierarchy

  • Polygon

Index

Constructors

constructor

  • new Polygon(vertices?: Array<any>): Polygon
  • Creates a Polygon with the given coordinates.

    Parameters

    • Optional vertices: Array<any>

      an array that contains either 'Point' instances or alternating 'x' and 'y' coordinates.

    Returns Polygon

Properties

area

area: number

Calculates the total area of the polygon.

isConvex

isConvex: boolean

Indicates if the polygon is convex. In a convex polygon, the vector between any two points inside the polygon lies inside it, as well.

isSimple

isSimple: boolean

Indicates if the polygon's line segments are not self-intersecting. Beware: this is a brute-force implementation with O(n^2).

numTriangles

numTriangles: number

Returns the number of triangles that will be required when triangulating the polygon.

numVertices

numVertices: number

Returns the total number of vertices spawning up the polygon. Assigning a value that's smaller than the current number of vertices will crop the path; a bigger value will fill up the path with zeros.

Methods

addVertices

  • addVertices(args: Array<any>): void
  • Adds vertices to the polygon. Pass either a list of 'Point' instances or alternating 'x' and 'y' coordinates.

    Parameters

    • args: Array<any>

    Returns void

clone

contains

  • contains(x: number, y: number): boolean

containsPoint

  • containsPoint(point: Point): boolean

copyToVertexData

  • copyToVertexData(target: VertexData, targetVertexID?: number, attrName?: string): void
  • Copies all vertices to a 'VertexData' instance, beginning at a certain target index.

    Parameters

    • target: VertexData
    • Optional targetVertexID: number
    • Optional attrName: string

    Returns void

getVertex

  • getVertex(index: number, out?: Point): Point

Protected get_area

  • get_area(): number

Protected get_isConvex

  • get_isConvex(): boolean

Protected get_isSimple

  • get_isSimple(): boolean

Protected get_numTriangles

  • get_numTriangles(): number

Protected get_numVertices

  • get_numVertices(): number

reverse

  • reverse(): void
  • Reverses the order of the vertices. Note that some methods of the Polygon class require the vertices in clockwise order.

    Returns void

setVertex

  • setVertex(index: number, x: number, y: number): void
  • Moves a given vertex to a certain position or adds a new vertex at the end.

    Parameters

    • index: number
    • x: number
    • y: number

    Returns void

Protected set_numVertices

  • set_numVertices(value: number): number

toString

  • toString(): string

triangulate

  • Calculates a possible representation of the polygon via triangles. The resulting IndexData instance will reference the polygon vertices as they are saved in this Polygon instance, optionally incremented by the given offset.

    If you pass an indexData object, the new indices will be appended to it. Otherwise, a new instance will be created.

    Parameters

    • Optional indexData: IndexData
    • Optional offset: number

    Returns IndexData

Static createCircle

  • createCircle(x: number, y: number, radius: number, numSides?: number): Polygon
  • Creates a circle with optimized implementations of triangulation, hitTest, etc.

    Parameters

    • x: number
    • y: number
    • radius: number
    • Optional numSides: number

    Returns Polygon

Static createEllipse

  • createEllipse(x: number, y: number, radiusX: number, radiusY: number, numSides?: number): Polygon
  • Creates an ellipse with optimized implementations of triangulation, hitTest, etc.

    Parameters

    • x: number
    • y: number
    • radiusX: number
    • radiusY: number
    • Optional numSides: number

    Returns Polygon

Static createRectangle

  • createRectangle(x: number, y: number, width: number, height: number): Polygon
  • Creates a rectangle with optimized implementations of triangulation, hitTest, etc.

    Parameters

    • x: number
    • y: number
    • width: number
    • height: number

    Returns Polygon

Generated using TypeDoc