Class: Position

Position

Abstract parent class for Point and Coordinate

(abstract) new Position() [source]


Members

  • x

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

  • y

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

  • z

  • Properties:
    Name Type Description
    z Number z value, it's a pure property and doesn't take part in caculation for now.
    Source:

    Methods

  • set() [source]

  • Set point or coordinate's x, y value
    Returns:
    Coordinate|Point: this
  • abs() [source]

  • Return abs value of the point
    Returns:
    Coordinate|Point: abs point
  • round() [source]

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

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

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

  • Returns a copy of the coordinate
    Returns:
    Coordinate|Point: copy
  • add(x, yopt) [source]

  • Returns the result of addition of another coordinate.
    Parameter Type Description
    x Coordinate | Point | Array | Number coordinate to add
    y opt Number optional, coordinate to add
    Returns:
    Coordinate|Point: result
  • sub(x, yopt) [source]

  • Returns the result of subtraction of another coordinate.
    Parameter Type Description
    x Coordinate | Point | Array | Number coordinate to add
    y opt Number optional, coordinate to add
    Returns:
    Coordinate|Point: result
  • substract(x, yopt) [source]

  • Alias for sub
    Parameter Type Description
    x Coordinate | Point | Array | Number coordinate to add
    y opt Number optional, coordinate to add
    Returns:
    Coordinate|Point: result
  • multi(ratio) [source]

  • Returns the result of multiplication of the current coordinate by the given number.
    Parameter Type Description
    ratio Number ratio to multi
    Returns:
    Coordinate|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:
    Coordinate|Point: result
  • equals(c) [source]

  • Compare with another coordinate to see whether they are equal.
    Parameter Type Description
    c Coordinate | Point coordinate to compare
    Returns:
    Boolean:
  • isZero() [source]

  • Whether the coordinate/point is zero

  • toArray() [source]

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

  • Formats coordinate number using fixed-point notation.
    Parameter Type Description
    n Number The number of digits to appear after the decimal point
    Returns:
    Coordinate: fixed coordinate
  • toJSON() [source]

  • Convert to a json object {x : .., y : ..}
    Returns:
    Object: json