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

### Properties

- area
- isConvex
- isSimple
- numTriangles
- numVertices

### Methods

- addVertices
- clone
- contains
- containsPoint
- copyToVertexData
- getVertex
- get_area
- get_isConvex
- get_isSimple
- get_numTriangles
- get_numVertices
- reverse
- setVertex
- set_numVertices
- toString
- triangulate
- createCircle
- createEllipse
- createRectangle

## Constructors

### constructor

- new Polygon(vertices?: Array<any>): Polygon

- - Defined in lib/starling/geom/Polygon.d.ts:21

  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

- Defined in lib/starling/geom/Polygon.d.ts:91

Calculates the total area of the polygon.

### isConvex

isConvex: boolean

- Defined in lib/starling/geom/Polygon.d.ts:87

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

- Defined in lib/starling/geom/Polygon.d.ts:82

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

- Defined in lib/starling/geom/Polygon.d.ts:103

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

### numVertices

numVertices: number

- Defined in lib/starling/geom/Polygon.d.ts:97

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

- - Defined in lib/starling/geom/Polygon.d.ts:37

  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

- clone(): Polygon

- - Defined in lib/starling/geom/Polygon.d.ts:29

  Creates a clone of this polygon.

  #### Returns Polygon

### contains

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

- - Defined in lib/starling/geom/Polygon.d.ts:46

  Figures out if the given coordinates lie within the polygon.

  #### Parameters

  - ##### x: number

  - ##### y: number

  #### Returns boolean

### containsPoint

- containsPoint(point: Point): boolean

- - Defined in lib/starling/geom/Polygon.d.ts:49

  Figures out if the given point lies within the polygon.

  #### Parameters

  - ##### point: Point

  #### Returns boolean

### copyToVertexData

- copyToVertexData(target: VertexData, targetVertexID?: number, attrName?: string): void

- - Defined in lib/starling/geom/Polygon.d.ts:60

  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

- - Defined in lib/starling/geom/Polygon.d.ts:43

  Returns the coordinates of a certain vertex.

  #### Parameters

  - ##### index: number

  - ##### Optional out: Point

  #### Returns Point

### Protected get_area

- get_area(): number

- - Defined in lib/starling/geom/Polygon.d.ts:92

  #### Returns number

### Protected get_isConvex

- get_isConvex(): boolean

- - Defined in lib/starling/geom/Polygon.d.ts:88

  #### Returns boolean

### Protected get_isSimple

- get_isSimple(): boolean

- - Defined in lib/starling/geom/Polygon.d.ts:83

  #### Returns boolean

### Protected get_numTriangles

- get_numTriangles(): number

- - Defined in lib/starling/geom/Polygon.d.ts:104

  #### Returns number

### Protected get_numVertices

- get_numVertices(): number

- - Defined in lib/starling/geom/Polygon.d.ts:98

  #### Returns number

### reverse

- reverse(): void

- - Defined in lib/starling/geom/Polygon.d.ts:33

  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

- - Defined in lib/starling/geom/Polygon.d.ts:40

  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

- - Defined in lib/starling/geom/Polygon.d.ts:100

  #### Parameters

  - ##### value: number

  #### Returns number

### toString

- toString(): string

- - Defined in lib/starling/geom/Polygon.d.ts:64

  Creates a string that contains the values of all included points.

  #### Returns string

### triangulate

- triangulate(indexData?: IndexData, offset?: number): IndexData

- - Defined in lib/starling/geom/Polygon.d.ts:57

  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

- - Defined in lib/starling/geom/Polygon.d.ts:72

  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

- - Defined in lib/starling/geom/Polygon.d.ts:69

  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

- - Defined in lib/starling/geom/Polygon.d.ts:75

  Creates a rectangle with optimized implementations of triangulation, hitTest, etc.

  #### Parameters

  - ##### x: number

  - ##### y: number

  - ##### width: number

  - ##### height: number

  #### Returns Polygon

Generated using TypeDoc