Classdesc

A polygon class. Any polygon consists of an array of vertices; polygons can be open or closed.

Requires

BezierPath

Requires

Bounds

Requires

SVGSerializabe

Requires

UID

Requires

UIDGenerator

Requires

Vertex

Requires

XYCoords

Hierarchy (view full)

Implements

Constructors

  • The constructor.

    Parameters

    • Optional vertices: Vertex[]

      An array of 2d vertices that shape the polygon.

    • Optional isOpen: boolean

      Indicates if the polygon should be rendered as an open or closed shape.

    Returns Polygon

    Name

    Polygon

Properties

className: string = "Polygon"

Required to generate proper CSS classes and other class related IDs.

isDestroyed: boolean

Member

isDestroyed

Memberof

Polygon

Instance

isOpen: boolean

Member

Memberof

Polygon

Instance

uid: string

The UID of this drawable object.

Member

Memberof

Polygon

Instance

vertices: Vertex[]

Member

Memberof

Polygon

Instance

utils: {
    area(vertices): number;
    signedArea(vertices): number;
} = ...

Type declaration

  • area:function
    • Calculate the area of the given polygon (unsigned).

      Note that this does not work for self-intersecting polygons.

      Parameters

      Returns number

      Name

      area

  • signedArea:function
    • Calulate the signed polyon area by interpreting the polygon as a matrix and calculating its determinant.

      Parameters

      Returns number

      Name

      signedArea

Methods

  • Add a vertex at a particular position of the vertices array.

    Parameters

    • vert: Vertex

      The vertex to add.

    • index: number

      The position to add the vertex at. Will be handled modulo.

    Returns void

    Method

    addVertexAt

    Instance

    Memberof

    Polygon

  • Calculate the area of the given polygon (unsigned).

    Note that this does not work for self-intersecting polygons.

    Returns number

    Method

    area

    Instance

    Memberof

    Polygon

  • Get the closest line-polygon-intersection point (closest the line point A).

    See demo 47-closest-vector-projection-on-polygon for how it works.

    Parameters

    • line: VertTuple<any>

      The line to find intersections with.

    • inVectorBoundsOnly: boolean = false

      If set to true only intersecion points on the passed vector are considered (located strictly between start and end vertex).

    Returns Vertex

    • An array of all intersections within the polygon bounds.
  • Check if the passed polygon is completly contained inside this polygon.

    This means:

    • all polygon's vertices must be inside this polygon.
    • the polygon has no edge intersections with this polygon.

    Parameters

    • polygon: Polygon

      The polygon to check if contained.

    Returns boolean

  • This function should invalidate any installed listeners and invalidate this object. After calling this function the object might not hold valid data any more and should not be used.

    Returns void

  • Construct a new polygon from this polygon with more vertices on each edge. The interpolation count determines the number of additional vertices on each edge. An interpolation count of 0 will return a polygon that equals the source polygon.

    Parameters

    • interpolationCount: number

    Returns Polygon

    A polygon with interpolationCount more vertices (as as factor).

  • Get the polygon vertex at the given position (index).

    The index may exceed the total vertex count, and will be wrapped around then (modulo).

    For k >= 0:

    • getVertexAt( vertices.length ) == getVertexAt( 0 )
    • getVertexAt( vertices.length + k ) == getVertexAt( k )
    • getVertexAt( -k ) == getVertexAt( vertices.length -k )

    Parameters

    • index: number

      The index of the desired vertex.

    Returns Vertex

    At the given index.

    Metho

    getVertexAt

    Instance

    Memberof

    Polygon

  • Get the winding order of this polgon: clockwise or counterclockwise.

    Returns boolean

    Method

    isClockwise

    Instance

    Memberof

    Polygon

  • Get all line intersections with this polygon.

    See demo 47-closest-vector-projection-on-polygon for how it works.

    Parameters

    • line: VertTuple<any>

      The line to find intersections with.

    • inVectorBoundsOnly: boolean = false

      If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).

    Returns Vertex[]

    • An array of all intersections within the polygon bounds.
  • Get the perimeter of this polygon. The perimeter is the absolute length of the outline.

    If this polygon is open then the last segment (connecting the first and the last vertex) will be skipped.

    Returns number

    Method

    perimeter

    Instance

    Memberof

    Polygon

  • Calulate the signed polyon area by interpreting the polygon as a matrix and calculating its determinant.

    Returns number

    Method

    signedArea

    Instance

    Memberof

    Polygon

  • Convert this polygon to a sequence of cubic Bézier curves.

    The first vertex in the returned array is the start point.
    The following sequence are triplets of (first-control-point, secnond-control-point, end-point):

    startPoint, controlPoint0_0, controlPoint1_1, pathPoint1, controlPoint1_0, controlPoint1_1, ..., endPoint

    Parameters

    • threshold: number

      An optional threshold (default=1.0) how strong the curve segments should over-/under-drive. Should be between 0.0 and 1.0 for best results but other values are allowed.

    Returns Vertex[]

    An array of 2d vertices that shape the cubic Bézier curve.

    Method

    toCubicBezierData

    Instance

    Memberof

    Polygon

  • Convert this polygon to a cubic bezier path instance.

    Parameters

    • threshold: number

      The threshold, usually from 0.0 to 1.0.

    Returns BezierPath

    • A bezier path instance.

    Method

    toCubicBezierPath

    Instance

    Memberof

    Polygon

  • Convert this polygon to a cubic bezier curve, represented as an SVG data string.

    Parameters

    • threshold: number

    Returns string

    The 'd' part for an SVG 'path' element.

    Method

    toCubicBezierSVGString

    Instance

    Memberof

    Polygon

  • Convert this polygon to a sequence of quadratic Bézier curves.

    The first vertex in the returned array is the start point.
    The following sequence are pairs of control-point-and-end-point:

    startPoint, controlPoint0, pathPoint1, controlPoint1, pathPoint2, controlPoint2, ..., endPoint

    Returns Vertex[]

    An array of 2d vertices that shape the quadratic Bézier curve.

    Method

    toQuadraticBezierData

    Instance

    Memberof

    Polygon

  • Convert this polygon to a quadratic bezier curve, represented as an SVG data string.

    Returns string

    The 'd' part for an SVG 'path' element.

    Method

    toQuadraticBezierSVGString

    Instance

    Memberof

    Polygon