wang-tiles - v2.1.2
    Preparing search index...

    Class CoordMap<D, V>

    An abstraction on Map which provides helper functions and serialization for coordinate based storage and lookup.

    Type Parameters

    • D extends number[]
    • V = unknown

    Implements

    • Map<D, V>
    Index
    • Type Parameters

      • D extends number[]
      • V = unknown

      Returns CoordMap<D, V>

    "[toStringTag]": string = ...
    coords: Map<string, V> = ...
    • Delete the element at the coordinate.

      Parameters

      • coordinates: D

        The coordinates to delete from the space.

      Returns boolean

      true if an element in the Map existed and has been removed, or false if the element does not exist.

    • Executes a provided function once per each key/value pair in the CoordMap, in insertion order.

      Parameters

      • callbackfn: (value: V, key: D, map: Map<D, V>) => void

        The function to call over each element.

      • OptionalthisArg: unknown

        the element representing this

      Returns void

    • Determine if coordinates are set with a value.

      Parameters

      • coordinates: D

        The coordinates to check.

      Returns boolean

      boolean indicating whether an element with the specified key exists or not.

    • Get the value at the provided point in space.

      Parameters

      • coordinates: D

        The coordinates to retrieve from the space.

      Returns V | undefined

      the value stored at the point.

    • Get the value at the provided offset.

      Parameters

      • dimensions: number

        The number of dimensions

      • dimension: number

        The dimension to get the offset

      • offset: -1 | 1

        The amount of offset

      Returns V | undefined

      the value stored at the offset

    • Set the value at the provided point in space.

      Parameters

      • coordinates: D

        The coordinates to set a value.

      • value: V

        The value to set.

      Returns this

      this CoordMap instance.

    • Fill the CoordinateMap with a predefined value. Always square.

      Parameters

      • generator: (coord: D) => V

        Function returning a value to fill.

      • start: D

        the minimum size of the area to fill.

      • end: D

        the maximum size of the area to fill.

      Returns this

      this CoordMap instance.

    • Convert coordinate map to a simple object for storage and testing.

      Returns Record<string, V>

      An object representing all coordinates in the map. Keys are comma delineated coordinates.

    • Take an array of numbers representing coordinates and convert them into a coordinate key.

      Parameters

      • coordinates: D

        the coordinates to convert.

      Returns string

      A string storing the coordinates of the provided array.

      // returns "1,-2,3"
      this.encodeCoordinate([1, -2, 3]);
    • Take a stored coordinate key and convert them back into numbers.

      Parameters

      • key: string

        Joined and stringified coordinates.

      Returns D

      An array of numbers representing the coordinates.

      // returns [1, -2, 3]
      this.decodeCoordinate("1,-2,3");
    • Recursively fill the coordinates with the

      Parameters

      • generator: (coord: D) => V

        Function returning a value to fill.

      • start: D

        the minimum size of the area to fill.

      • end: D

        the maximum size of the area to fill.

      • state: number[] = []

        the current coordinate state.

      Returns void