Options
All
  • Public
  • Public/Protected
  • All
Menu
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

Implements

Index

Constructors

constructor

  • new Polygon(vertices?: Array<Vertex>, isOpen?: boolean): Polygon
  • The constructor.

    name

    Polygon

    Parameters

    • Optional vertices: Array<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

Properties

Readonly className

className: string = "Polygon"

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

isDestroyed

isDestroyed: boolean
member

isDestroyed

memberof

Polygon

instance

isOpen

isOpen: boolean
member

{boolean}

memberof

Polygon

instance

Readonly uid

uid: UID

The UID of this drawable object.

member

{UID}

memberof

Polygon

instance
readonly

vertices

vertices: Array<Vertex>
member

{Array}

memberof

Polygon

instance

Methods

addVertex

  • addVertex(vert: Vertex): void
  • Add a vertex to the end of the vertices array.

    method

    addVert

    instance
    memberof

    Polygon

    Parameters

    • vert: Vertex

      The vertex to add.

    Returns void

area

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

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

    method

    area

    instance
    memberof

    Polygon

    Returns number

clone

closestLineIntersection

  • closestLineIntersection(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Vertex | null
  • 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.

    • Default value 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 | null

    • An array of all intersections within the polygon bounds.

containsPolygon

  • containsPolygon(polygon: Polygon): boolean
  • 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

containsVert

destroy

  • destroy(): void
  • 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

getBounds

  • Get the bounding box (bounds) of this polygon.

    method

    getBounds

    instance
    memberof

    Polygon

    Returns Bounds

    The rectangular bounds of this polygon.

getEvenDistributionPolygon

  • getEvenDistributionPolygon(pointCount: number): Polygon
  • Convert this polygon into a new polygon with n evenly distributed vertices.

    Parameters

    • pointCount: number

      Must not be negative.

    Returns Polygon

getInterpolationPolygon

  • getInterpolationPolygon(interpolationCount: number): Polygon
  • 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).

getVertexAt

  • getVertexAt(index: number): Vertex
  • 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 )
    metho

    getVertexAt

    instance
    memberof

    Polygon

    Parameters

    • index: number

      The index of the desired vertex.

    Returns Vertex

    At the given index.

isClockwise

  • isClockwise(): boolean
  • Get the winding order of this polgon: clockwise or counterclockwise.

    method

    isClockwise

    instance
    memberof

    Polygon

    Returns boolean

lineIntersections

  • lineIntersections(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vertex>
  • 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.

    • Default value inVectorBoundsOnly: boolean = false

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

    Returns Array<Vertex>

    • An array of all intersections within the polygon bounds.

move

  • Move the polygon's vertices by the given amount.

    method

    move

    instance
    memberof

    Polygon

    Parameters

    Returns Polygon

    this for chaining

perimeter

  • perimeter(): number
  • 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.

    method

    perimeter

    instance
    memberof

    Polygon

    Returns number

rotate

  • Rotate the polygon around the given center.

    method

    rotate

    instance
    memberof

    Polygon

    Parameters

    • angle: number

      The rotation angle.

    • center: Vertex

      The center of rotation.

    Returns Polygon

    this, for chaining.

scale

  • Scale the polygon relative to the given center.

    method

    scale

    instance
    memberof

    Polygon

    Parameters

    • factor: number

      The scale factor.

    • center: Vertex

      The center of scaling.

    Returns Polygon

    this, for chaining.

signedArea

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

    method

    signedArea

    instance
    memberof

    Polygon

    Returns number

toCubicBezierData

  • toCubicBezierData(threshold: number | undefined): Array<Vertex>
  • 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
    method

    toCubicBezierData

    instance
    memberof

    Polygon

    Parameters

    • threshold: number | undefined

      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 Array<Vertex>

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

toCubicBezierPath

  • toCubicBezierPath(threshold: number): BezierPath
  • Convert this polygon to a cubic bezier path instance.

    method

    toCubicBezierPath

    instance
    memberof

    Polygon

    Parameters

    • threshold: number

      The threshold, usually from 0.0 to 1.0.

    Returns BezierPath

    • A bezier path instance.

toCubicBezierSVGString

  • toCubicBezierSVGString(threshold: number): string
  • Convert this polygon to a cubic bezier curve, represented as an SVG data string.

    method

    toCubicBezierSVGString

    instance
    memberof

    Polygon

    Parameters

    • threshold: number

    Returns string

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

toQuadraticBezierData

  • toQuadraticBezierData(): Array<Vertex>
  • 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
    method

    toQuadraticBezierData

    instance
    memberof

    Polygon

    Returns Array<Vertex>

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

toQuadraticBezierSVGString

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

    method

    toQuadraticBezierSVGString

    instance
    memberof

    Polygon

    Returns string

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

Object literals

Static utils

utils: object

area

  • area(vertices: Array<XYCoords>): number
  • Calculate the area of the given polygon (unsigned).

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

    name

    area

    Parameters

    Returns number

signedArea

  • signedArea(vertices: Array<XYCoords>): number
  • Calulate the signed polyon area by interpreting the polygon as a matrix and calculating its determinant.

    name

    signedArea

    Parameters

    Returns number

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Private property
  • Private method
  • Static property
  • Static method

Generated using TypeDoc