Options
All
  • Public
  • Public/Protected
  • All
Menu
classdesc

A vertex is a pair of two numbers.

It is used to identify a 2-dimensional point on the x-y-plane.

requires

IVertexAttr

requires

SVGSerializable

requires

UID

requires

UIDGenerator

requires

VertexAttr

requires

VertexListeners

requires

XYCoords

Hierarchy

  • Vertex

Implements

Index

Constructors

constructor

  • new Vertex(x?: number | XYCoords | undefined, y?: number | undefined): Vertex
  • The constructor for the vertex class.

    name

    Vertex

    Parameters

    • Optional x: number | XYCoords | undefined

      The x-coordinate of the new vertex.

    • Optional y: number | undefined

      The y-coordinate of the new vertex.

    Returns Vertex

Properties

attr

member

{IVertexAttr}

memberof

{Vertex}

instance

Readonly className

className: string = "Vertex"

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

isDestroyed

isDestroyed: boolean
member

isDestroyed

memberof

Vertex

instance

listeners

listeners: VertexListeners
member

{VertexListeners}

memberof

{Vertex}

instance

Readonly uid

uid: UID

The UID of this drawable object.

member

{UID}

memberof

Vertex

instance
readonly

x

x: number
member

{number}

memberof

Vertex

instance

y

y: number
member

{number}

memberof

Vertex

instance

z

z: number

Static Readonly Private EPSILON

EPSILON: 0.000001 = 0.000001

An epsilon for comparison

readonly

Static Private Readonly ZERO

ZERO: Vertex = new Vertex(0, 0)

Methods

abs

  • Set both coordinates of this vertex to their absolute value (abs(x), abs(y)).

    method

    abs

    instance
    memberof

    Vertex

    Returns Vertex

    this

add

  • Add the passed amount to x- and y- component of this vertex.

    This function works with add( {number}, {number} ) and add( {Vertex} ), as well.

    method

    add

    instance
    memberof

    Vertex

    Parameters

    • x: number | XYCoords

      The amount to add to x (or a vertex itself).

    • Optional y: number

      The amount to add to y.

    Returns Vertex

    this

addX

  • addX(amountX: number): Vertex
  • Add the passed amounts to the x-component of this vertex.

    method

    addX

    instance
    memberof

    Vertex

    Parameters

    • amountX: number

    Returns Vertex

    this

addXY

  • addXY(amountX: number, amountY: number): Vertex
  • Add the passed amounts to the x- and y- components of this vertex.

    method

    addXY

    instance
    memberof

    Vertex

    Parameters

    • amountX: number
    • amountY: number

    Returns Vertex

    this

addY

  • addY(amountY: number): Vertex
  • Add the passed amounts to the y-component of this vertex.

    method

    addY

    instance
    memberof

    Vertex

    Parameters

    • amountY: number

    Returns Vertex

    this

angle

  • Get the angle of this point (relative to (0,0) or to the given other origin point).

    method

    angle

    instance
    memberof

    Vertex

    Parameters

    • Optional origin: XYCoords

      The vertex to measure the angle from.

    Returns number

clone

  • Create a copy of this vertex.

    method

    clone

    instance
    memberof

    Vertex

    Returns Vertex

    A new vertex, an exact copy of this.

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

difference

  • Get the difference to the passed point.

    The difference is (vert.x-this.x, vert.y-this.y).

    method

    difference

    instance
    memberof

    Vertex

    Parameters

    • vert: XYCoords

      The vertex to measure the x-y-difference to.

    Returns Vertex

    A new vertex.

distance

  • Get the distance to the passed point (in euclidean metric)

    method

    distance

    instance
    memberof

    Vertex

    Parameters

    • vert: XYCoords

      The vertex to measure the distance to.

    Returns number

equals

  • Check if this vertex equals the passed one.
    This function uses an internal epsilon as tolerance.

    method

    equals

    instance
    memberof

    Vertex

    Parameters

    • vertex: XYCoords

      The vertex to compare this with.

    Returns boolean

inv

  • Change this vertex (x,y) to its inverse (-x,-y).

    method

    inv

    instance
    memberof

    Vertex

    Returns Vertex

    this

invX

  • Set the x-component if this vertex to the inverse of its value.

    method

    invX

    instance
    memberof

    Vertex

    Returns Vertex

    this

invY

  • Set the y-component if this vertex to the inverse of its value.

    method

    invY

    instance
    memberof

    Vertex

    Returns Vertex

    this

lerp

  • Perform a linear interpolation towards the given target vertex. The amount value t is relative, t=0.0 means no change, t=1.0 means this point will be moved to the exact target position.

    t=0.5 will move this point to the middle of the connecting linear segment.

    Parameters

    • target: XYCoords

      The target position to lerp this vertex to.

    • t: number

      The relative amount, usually in [0..1], but other values will work, too.

    Returns Vertex

lerpAbs

  • Perform a linear interpolation towards the given target vertex (absolute variant). The amount value t is absolute, which means the lerp amount is a direct distance value. This point will have move the amount of the passed distance u.

    Parameters

    • target: XYCoords

      The target position to lerp this vertex to.

    • u: number

    Returns Vertex

multiplyScalar

  • multiplyScalar(scalar: number): this

rotate

  • This is a vector-like behavior and 'rotates' this vertex around given center.

    method

    rotate

    instance
    memberof

    Vertex

    Parameters

    • angle: number

      The angle to 'rotate' this vertex; 0.0 means no change.

    • center: XYCoords | undefined

      The center of rotation; default is (0,0).

    Returns Vertex

    this

round

  • Round the two components x and y of this vertex.

    method

    round

    instance
    memberof

    Vertex

    Returns Vertex

    this

scale

  • This is a vector-like behavior and 'scales' this vertex towards/from a given center by one uniform scale factor.

    method

    scale

    instance
    memberof

    Vertex

    Parameters

    • factor: number

      The factor to 'scale' this vertex; 1.0 means no change.

    • Optional center: XYCoords

      The origin of scaling; default is (0,0).

    Returns Vertex

    this

scaleXY

  • This is a vector-like behavior and 'scales' this vertex towards/from a given center by two independent x- and y- scale factors.

    method

    scale

    instance
    memberof

    Vertex

    Parameters

    • factors: XYCoords
    • Optional center: XYCoords

      The origin of scaling; default is (0,0).

    Returns Vertex

    this

set

  • Set the x- and y- component of this vertex.

    method

    set

    instance
    memberof

    Vertex

    Parameters

    • x: number | XYCoords

      The new x-component.

    • Optional y: number | undefined

      The new y-component.

    Returns Vertex

    this

setX

  • Set the x-component of this vertex.

    method

    setX

    instance
    memberof

    Vertex

    Parameters

    • x: number

      The new x-component.

    Returns Vertex

    this

setY

  • Set the y-component of this vertex.

    method

    setY

    instance
    memberof

    Vertex

    Parameters

    • y: number

      The new y-component.

    Returns Vertex

    this

sub

  • Substract the passed amount from x- and y- component of this vertex.

    This function works with sub( {number}, {number} ) and sub( {Vertex} ), as well.

    method

    sub

    instance
    memberof

    Vertex

    Parameters

    • x: number | XYCoords

      The amount to substract from x (or a vertex itself).

    • Optional y: number

      The amount to substract from y.

    Returns Vertex

    this

subX

  • subX(amountX: number): Vertex
  • Substract the passed amounts from the x-component of this vertex.

    method

    addX

    instance
    memberof

    Vertex

    Parameters

    • amountX: number

    Returns Vertex

    this

subXY

  • subXY(amountX: number, amountY: number): Vertex
  • Substract the passed amounts from the x- and y- components of this vertex.

    method

    subXY

    instance
    memberof

    Vertex

    Parameters

    • amountX: number
    • amountY: number

    Returns Vertex

    this

subY

  • subY(amountY: number): Vertex
  • Substract the passed amounts from the y-component of this vertex.

    method

    subY

    instance
    memberof

    Vertex

    Parameters

    • amountY: number

    Returns Vertex

    this

toString

  • toString(): string
  • Get a string representation of this vertex.

    method

    toString

    instance
    memberof

    Vertex

    Returns string

    The string representation of this vertex.

Static randomVertex

Object literals

Static utils

utils: object

arrayToJSON

  • arrayToJSON(vertices: Array<XYCoords>, precision?: number): string
  • Convert the given vertices (array) to a JSON string.

    Parameters

    • vertices: Array<XYCoords>
    • Optional precision: number

      (optional) The numeric precision to be used (number of precision digits).

    Returns string

buildArrowHead

  • Generate a four-point arrow head, starting at the vector end minus the arrow head length.

    The first vertex in the returned array is guaranteed to be the located at the vector line end minus the arrow head length.

    Due to performance all params are required.

    The params scaleX and scaleY are required for the case that the scaling is not uniform (x and y scaling different). Arrow heads should not look distored on non-uniform scaling.

    If unsure use 1.0 for scaleX and scaleY (=no distortion). For headlen use 8, it's a good arrow head size.

    Example: buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )

    Parameters

    • zA: XYCoords

      The start vertex of the vector to calculate the arrow head for.

    • zB: XYCoords

      The end vertex of the vector.

    • headlen: number

      The length of the arrow head (along the vector direction. A good value is 12).

    • scaleX: number

      The horizontal scaling during draw.

    • scaleY: number

      the vertical scaling during draw.

    Returns Array<Vertex>

Legend

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

Generated using TypeDoc