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

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.

listeners

listeners: VertexListeners
member

{VertexListeners}

memberof

{Vertex}

instance

x

x: number
member

{number}

memberof

Vertex

instance

y

y: number
member

{number}

memberof

Vertex

instance

Static Readonly Private EPSILON

EPSILON: 0.000001 = 0.000001

An epsilon for comparison

Static Private Readonly ZERO

ZERO: Vertex = new Vertex(0,0)

Methods

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

clone

  • Create a copy of this vertex.

    method

    clone

    instance
    memberof

    Vertex

    Returns Vertex

    A new vertex, an exact copy of this.

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

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: Vertex | 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.

    method

    scale

    instance
    memberof

    Vertex

    Parameters

    • factor: number

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

    • center: Vertex

      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

toSVGString

  • toSVGString(options: { className?: string }): string
  • Convert this vertex to SVG code.

    method

    toSVGString

    instance
    memberof

    Vertex

    Parameters

    • options: { className?: string }

      An optional set of options, like 'className'.

      • Optional className?: string

    Returns string

    A string representing the SVG code for this vertex.

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

buildArrowHead

  • buildArrowHead(zA: Vertex, zB: Vertex, headlen: number, scaleX: number, scaleY: number): Array<Vertex>
  • 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: Vertex

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

    • zB: Vertex

      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