Description

Position class

Implements

IPosition

Example

const pos = new Position(1, 1);

Hierarchy

Implements

Constructors

Properties

x: number

Description

X position

y: number

Description

Y position

Methods

  • Returns [Position, Position, Position, Position, Position, Position, Position, Position]

    List of positions

    Description

    Get 8 positions (top, right, bottom, left, upper left, upper right, lower right, lower left)

    Example

    const pos = new Position(1, 1);
    const [topPos, rightPos, bottomPos, leftPos, upperLeftPos, upperRightPos, lowerRightPos, lowerLeftPos] = pos.allNears();
    console.log(topPos); // { x: 1, y: 0 }
    console.log(rightPos); // { x: 2, y: 1 }
    console.log(bottomPos); // { x: 1, y: 2 }
    console.log(leftPos); // { x: 0, y: 1 }
    console.log(upperLeftPos); // { x: 0, y: 0 }
    console.log(upperRightPos); // { x: 2, y: 0 }
    console.log(lowerRightPos); // { x: 2, y: 2 }
    console.log(lowerLeftPos); // { x: 0, y: 2 }
  • Parameters

    • pos: Position

      Position to calculate distance

    • formular: "mahata" | "euclid" = 'mahata'

      Formular to calculate distance (mahata, euclid)

    Returns number

    Distance between two positions

    Description

    Get distance between two positions

    Example

    const pos1 = new Position(1, 1);
    const pos2 = new Position(1, 2);
    const distance = pos1.distance(pos2);
    console.log(distance); // | 1 - 1 | + | 2 - 1 | = 1

    Example

    const pos1 = new Position(1, 1);
    const pos2 = new Position(1, 2);
    const distance = pos1.distance(pos2, 'euclid');
    console.log(distance); // sqrt((1 - 1) ^ 2 + (2 - 1) ^ 2) = 1
  • Parameters

    • pos: Position

      Position to calculate distance

    Returns number

    Distance between two positions

    Description

    Get Euclidean distance between two positions

  • Parameters

    Returns boolean

    Whether the position is equal

    Description

    Check if the position is equal

    Example

    const pos1 = new Position(1, 1);
    const pos2 = new Position(1, 1);
    const isEqual = pos1.equals(pos2)
    console.log(isEqual) // true
  • Parameters

    Returns boolean

    Whether the position is near

    Description

    Check if the position is near

    Example

    const pos1 = new Position(1, 1);
    const pos2 = new Position(1, 2);
    const isNear = pos1.isNear(pos2)
    console.log(isNear) // true

    Example

    const pos1 = new Position(1, 1);
    const pos2 = new Position(1, 3);
    const isNear = pos1.isNear(pos2)
    console.log(isNear) // false
  • Parameters

    • width: number

      The width of the map

    • height: number

      The height of the map

    Returns boolean

    Whether the position is valid

    Description

    Check if the position is valid

    Example

    const pos = new Position(1, 1);
    const isValid = pos.isValid(10, 10);
    console.log(isValid); // true

    Example

    const pos = new Position(-1, 1);
    const isValid = pos.isValid(10, 10);
    console.log(isValid); // false
  • Parameters

    • pos: Position

      Position to calculate distance

    Returns number

    Manhattan distance between two positions

    Description

    Get Manhattan distance between two positions

Generated using TypeDoc