Class: Point

Point

Represents a 2d point.
Can be created in serveral ways:

new Point(x, y) [source]

var point = new Point(1000, 1000);
var point = new Point([1000,1000]);
var point = new Point({x:1000, y:1000});
Parameter Type Description
x Number x value
y Number y value

Members

  • x

  • Properties:
    Name Type Description
    x Number x value
    Source:

  • y

  • Properties:
    Name Type Description
    y Number y value
    Source:

    Methods

  • abs() [source]

  • Return abs value of the point
    Returns:
    Point: abs point
  • copy() [source]

  • Returns a copy of the point
    Returns:
    Point: copy
  • round() [source]

  • Like math.round, rounding the point's xy.
    Returns:
    Point: rounded point
  • equals(c2) [source]

  • Compare with another point to see whether they are equal.
    Parameter Type Description
    c2 Point point to compare
    Returns:
    Boolean:
  • distanceTo(point) [source]

  • Returns the distance between the current and the given point.
    Parameter Type Description
    point Point another point
    Returns:
    Number: distance
  • add(point) [source]

  • Returns the result of addition of another point.
    Parameter Type Description
    point Point point to add
    Returns:
    Point: result
  • substract(point) [source]

  • Returns the result of subtraction of another point.
    Parameter Type Description
    point Point point to substract
    Returns:
    Point: result
  • multi(n) [source]

  • Returns the result of multiplication of the current point by the given number.
    Parameter Type Description
    n Number number to multi
    Returns:
    Point: result
  • div(n) [source]

  • Returns the result of division of the current point by the given number.
    Parameter Type Description
    n Number number to div
    Returns:
    Point: result
  • _isNaN() [source]

  • Whether the point is NaN
    Returns:
    Boolean:
  • toArray() [source]

  • Convert the point to a number array [x, y]
    Returns:
    Array.<Number>: number array
  • toJSON() [source]

  • Convert the point to a json object {x : .., y : ..}
    Returns:
    Object: json
  • mag() [source]

  • Return the magitude of this point: this is the Euclidean distance from the 0, 0 coordinate to this point's x and y coordinates.
    Returns:
    Number: magnitude
  • unit() [source]

  • Calculate this point but as a unit vector from 0, 0, meaning that the distance from the resulting point to the 0, 0 coordinate will be equal to 1 and the angle from the resulting point to the 0, 0 coordinate will be the same as before.
    Returns:
    Point: unit vector point
  • perp() [source]

  • Compute a perpendicular point, where the new y coordinate is the old x coordinate and the new x coordinate is the old y coordinate multiplied by -1
    Returns:
    Point: perpendicular point