API Docs for: v0.1.0
Show:

Polygon Class

Defined in: src\geom\Polygon.js:5

A convex clockwise Polygon.

Constructor

Polygon

(
  • x
  • y
  • points
  • scale
)

Parameters:

  • x Number

    The X origin of the polygon, all X coords for all points are relative to this

  • y Number

    The Y origin of the polygon, all Y coords for all points are relative to this

  • points Array | Array

    This can be an array of Vectors that form the polygon, a flat array of numbers that will be interpreted as [x,y, x,y, ...]

  • scale Number

    The scale of the polygon

Methods

clone

() Polygon

Creates a clone of this polygon

Returns:

Polygon:

a copy of the polygon

contains

(
  • x
  • y
)
Boolean

Checks if the x, and y coords passed to this function are contained within this polygon

Parameters:

  • x Number

    The X coord of the point to test

  • y Number

    The Y coord of the point to test

Returns:

Boolean:

if the x/y coords are within this polygon

copy

(
  • polygon
)
Polygon chainable

Copies the values from another polygon to this one

Parameters:

  • polygon Polygon

    The polygon to copy vlaues from

Returns:

Polygon:

Returns itself.

equals

(
  • polygon
)
Boolean

Checks if this polygon's values are equal to anothers

Parameters:

  • polygon Polygon

    The polygon to check against

Returns:

Boolean:

True if they are equal

recalc

() Polygon chainable

Recalculates the scaled points, edges, and normals of this polygon based on the relative points

Returns:

Polygon:

Returns itself.

Properties

_points

Array private

The unscaled points of the polygon, the X & Y values here should be relative to the origin X & Y.

Default: []

edges

Array

These vectors are calculated by this.recalc() and represent the edges of the polygon defined by it's points.

Default: []

normals

Array

These vectors are calculated by this.recalc() and represent the normals of the polygon edges defined by it's points.

Default: []

points

Array

The points of the polygon, the X & Y values here should be relative to the origin X & Y values.

Default: []

position

Vector

The origin point of the polygon, all points are relative to this

scale

Vector

The scale of the polygon

Default: new Vector(1, 1)

x

Number

The origin X coord of the polygon

Default: 0

x

Number

The origin Y coord of the polygon

Default: 0