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

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.

isOpen

isOpen: boolean
member

{boolean}

memberof

Polygon

instance

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

containsVert

  • containsVert(vert: Vertex): boolean

getBounds

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

    method

    getBounds

    instance
    memberof

    Polygon

    Returns Bounds

    The rectangular bounds of this polygon.

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.

move

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

    method

    move

    instance
    memberof

    Polygon

    Parameters

    Returns Polygon

    this for chaining

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.

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.

toSVGString

  • toSVGString(options: { className?: string } | undefined): string
  • Create an SVG representation of this polygon.

    method

    toSVGString

    instance
    memberof

    Polygon

    Parameters

    • options: { className?: string } | undefined

      An optional set of options, like 'className'.

    Returns string

    The SVG string.

Legend

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

Generated using TypeDoc