Class: Coordinate

Coordinate(x, y)

Class representing a single 2D point (x and y).

Constructor

new Coordinate(x, y)

Generate a coordninate from x and y numbers.

Parameters:
Name Type Description
x number
y number
Properties:
Name Type Description
x number
y number
Source:

Methods

add(other) → {Coordinate}

Add other coordinate (x and y) to this coordinate.

Parameters:
Name Type Description
other Coordinate

the coordinate to add

Source:
Returns:

this coordinate

Type
Coordinate
Example
const a = new Coordinate(2,2);
const b = new Coordinate(1,1);
a.add(b);	// a += b
// a is now (3,3)

clone() → {Coordinate}

Creates a new instance with the same coordinates.

Source:
Returns:

a new instance of this coordinate

Type
Coordinate

equals(other) → {boolean}

Compares the position of this to an given coordinate.

Parameters:
Name Type Description
other Coordinate

the coordinate to compare against

Source:
Returns:
  • true if coordinates have the same position
Type
boolean

getDistance(other) → {number}

Calculates the distance of two points.

Parameters:
Name Type Description
other Coordinate

the other coordinate

Source:
Returns:

the distance

Type
number

mirrorX() → {Coordinate}

Mirrors the coordinate on the x axis (inverts y).

Source:
Returns:

this

Type
Coordinate

mirrorY() → {Coordinate}

Mirrors the coordinate on the y axis (inverts x).

Source:
Returns:

this

Type
Coordinate

orthogonalProjection(lineStart, lineEnd) → {Coordinate}

Projects a point perpendicular on a line.

Parameters:
Name Type Description
lineStart Coordinate

first coord of the line

lineEnd Coordinate

second coord of the line

Source:
Returns:

the Coordinate on the line (new instance)

Type
Coordinate

rotate(angle, centerCoordopt) → {Coordinate}

Rotate the Coordinate around centerCoord. The rotation is counter clockwise, like the default mathematical rotation.

Parameters:
Name Type Attributes Description
angle number

rotation angle in degrees

centerCoord Coordinate <optional>

center of rotation

Source:
Returns:

this

Type
Coordinate

scale(scaleXopt, scaleYopt) → {Coordinate}

Scale the coordinate with one or two factors.

Parameters:
Name Type Attributes Default Description
scaleX number <optional>
1

factor for the x coordinate

scaleY number | true <optional>
1

factor for the y coordinate or true to use scaleX

Source:
Returns:

this

Type
Coordinate

serializeName() → {String}

Serializes the coordinate for TikZ.

Source:
Returns:

the serialized coordinate

Type
String
Example
new Coordinate(1, 2).serializeName();
// returns (1, 2)

subtract(other) → {Coordinate}

Subtract other coordinate (x and y) from this coordinate.

Parameters:
Name Type Description
other Coordinate

the coordinate to subtract

Source:
Returns:

this

Type
Coordinate
Example
const a = new Coordinate(2,2);
const b = new Coordinate(1,1);
a.subtract(b);	// a -= b
// a is now (1,1)

sum(…others) → {Coordinate}

Calculates the sum of this and other given coordinates. This coordinate will not be altered, instead a new coordinate will bw returned.

Parameters:
Name Type Attributes Description
others Coordinate <repeatable>

other coordinates to sum up

Source:
Returns:

the new Coordinate (sum)

Type
Coordinate

toString() → {String}

Alias for serializeName().

Source:
See:
  • serializeName for details
Returns:

the serialized coordinate

Type
String