The hexagonal grid class.

Hierarchy (view full)

Constructors

Properties

columns: boolean

Is this grid column-based (flat-topped) or row-based (pointy-topped)?

even: boolean

Is this grid even or odd?

size: number

The size of a grid space in pixels.

sizeX: number

The width of a grid space in pixels.

sizeY: number

The height of a grid space in pixels.

distance: number

The distance of a grid space in units.

units: string

The distance units used in this grid.

style: string

The style of the grid.

thickness: number

The thickness of the grid.

color: Color

The color of the grid.

alpha: number

The opacity of the grid.

#TEMP_POINT: Point = ...

Used by HexagonalGrid#snapToCenter.

#TEMP_GRID: HexagonalGrid = ...

Used by HexagonalGrid#snapToCenter. Always an odd grid!

Accessors

  • get isGridless(): boolean
  • Is this a gridless grid?

    Returns boolean

  • get isSquare(): boolean
  • Is this a square grid?

    Returns boolean

  • get isHexagonal(): boolean
  • Is this a hexagonal grid?

    Returns boolean

Methods

  • Returns the offset of the grid space corresponding to the given coordinates.

    Parameters

    • coords: any

      The coordinates

    Returns GridOffset

    The offset

  • Parameters

    • __namedParameters: {
          x: any;
          y: any;
          width: any;
          height: any;
      }
      • x: any
      • y: any
      • width: any
      • height: any

    Returns any[]

  • Parameters

    • coords1: any
    • coords2: any

    Returns boolean

  • Parameters

    • coords: any
    • direction: any

    Returns GridOffset

  • Parameters

    • point: any
    • direction: any

    Returns Point

  • Returns the cube coordinates of the grid space corresponding to the given coordinates.

    Parameters

    • coords: any

      The coordinates

    Returns HexagonalGridCube

    The cube coordinates

  • Returns the cube coordinates of grid spaces adjacent to the one corresponding to the given coordinates.

    Parameters

    • coords: any

      The coordinates

    Returns HexagonalGridCube[]

    The adjacent cube coordinates

  • Returns the cube coordinates of the grid space corresponding to the given coordinates shifted by one grid space in the given direction.

    Parameters

    Returns HexagonalGridCube

    The cube coordinates

  • Returns the top-left point of the grid space corresponding to the given coordinates. If given a point, the top-left point of the grid space that contains it is returned.

    Parameters

    • coords: any

      The coordinates

    Returns Point

    The top-left point

  • Returns the center point of the grid space corresponding to the given coordinates. If given a point, the center point of the grid space that contains it is returned.

    Parameters

    • coords: any

      The coordinates

    Returns Point

    The center point

  • Returns {
        x: number;
        y: number;
    }[]

  • Parameters

    • coords: any

    Returns {
        x: number;
        y: number;
    }[]

  • Parameters

    • point: any
    • __namedParameters: {
          mode: any;
          resolution: number;
      }
      • mode: any
      • resolution: number

    Returns any

  • Calculate the total size of the canvas with padding applied, as well as the top-left coordinates of the inner rectangle that houses the scene.

    Parameters

    • sceneWidth: any

      The width of the scene.

    • sceneHeight: any

      The height of the scene.

    • padding: any

      The percentage of padding.

    Returns {
        width: any;
        height: any;
        x: number;
        y: number;
        rows: number;
        columns: number;
    }

    • width: any
    • height: any
    • x: number
    • y: number
    • rows: number
    • columns: number

    Abstract

  • Parameters

    • waypoints: any
    • __namedParameters: {
          cost: any;
      }
      • cost: any
    • result: any

    Returns void

  • Parameters

    • point: any
    • direction: any
    • distance: any

    Returns {
        x: any;
        y: any;
    }

    • x: any
    • y: any
  • Parameters

    • __namedParameters: {
          x: any;
          y: any;
      }
      • x: any
      • y: any
    • radius: any

    Returns {
        x: any;
        y: any;
    }[]

  • Measure a shortest, direct path through the given waypoints.

    Parameters

    • waypoints: any[]

      The waypoints the path must pass through

    • Optional options: {
          cost: GridMeasurePathCostFunction;
      } = {}

      Additional measurement options

      • cost: GridMeasurePathCostFunction

        The function that returns the cost for a given move between grid spaces (default is the distance travelled along the direct path)

    Returns GridMeasurePathResult

    The measurements a shortest, direct path through the given waypoints.

  • Get the cone polygon given the radius in grid units and the angle in degrees for this grid. The points of the polygon are returned ordered in positive orientation. In gridless grids an approximation of the true cone with a deviation of less than 0.25 pixels is returned.

    Parameters

    • origin: Point

      The origin point of the cone.

    • radius: number

      The radius in grid units.

    • direction: number

      The direction in degrees.

    • angle: number

      The angle in degrees.

    Returns Point[]

    The points of the cone polygon.

  • Snap the point to the nearest center of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    • Optional dx: number = 0

      The x-translation of the grid

    • Optional dy: number = 0

      The y-translation of the grid

    • Optional columns: boolean = ...

      Flat-top instead of pointy-top?

    • Optional even: boolean = ...

      Start at a full grid space?

    • Optional size: number = ...

      The size of a grid space

    Returns Point

    The snapped point

  • Snap the point to the nearest vertex of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    • Optional dx: number

      The x-offset of the grid

    • Optional dy: number

      The y-offset of the grid

    Returns Point

    The snapped point

  • Snap the point to the nearest vertex or center of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest edge of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest edge or center of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest edge or vertex of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest edge, vertex, center of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest corner of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest top/bottom-left/right vertex of a hexagon.

    Parameters

    • point: Point

      The point

    • other: boolean

      Bottom-right instead of top-left vertex?

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest top/bottom-left/right vertex or center of a hexagon.

    Parameters

    • point: Point

      The point

    • other: boolean

      Bottom-right instead of top-left vertex?

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest top/bottom-left/right corner of a hexagon.

    Parameters

    • point: Point

      The point

    • other: boolean

      Bottom-right instead of top-left corner?

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest grid intersection of the rectanglar grid.

    Parameters

    • point: Point

      The point

    • other: boolean

      Align rectangles with top-left vertices instead of top-left corners?

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest top/bottom side of the bounds of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Snap the point to the nearest left/right side of the bounds of a hexagon.

    Parameters

    • point: Point

      The point

    • resolution: number

      The grid resolution

    Returns Point

    The snapped point

  • Calculate the cost of the direct path segment.

    Parameters

    • from: HexagonalGridCube

      The coordinates the segment starts from

    • to: HexagonalGridCube

      The coordinates the segment goes to

    • cost: GridMeasurePathCostFunction

      The cost function

    Returns number

    The cost of the path segment

  • Internal

    Calculate the total size of the canvas with padding applied, as well as the top-left coordinates of the inner rectangle that houses the scene. (Legacy)

    Parameters

    • columns: number

      Column or row orientation?

    • legacySize: number

      The legacy size of the grid.

    • sceneWidth: number

      The width of the scene.

    • sceneHeight: number

      The height of the scene.

    • padding: number

      The percentage of padding.

    Returns {
        width: number;
        height: number;
        x: number;
        y: number;
        rows: number;
        columns: number;
    }

    • width: number
    • height: number
    • x: number
    • y: number
    • rows: number
    • columns: number