# HexagonalGrid

## HexagonalGrid

Construct a hexagonal grid

## Constructor

Source:

### Members

#### (static) flatHexPoints :Array

Source:

A matrix of x and y offsets which is multiplied by the width/height vector to get flat-top polygon coordinates

#### (static) pointyHexPoints :Array

Source:

A matrix of x and y offsets which is multiplied by the width/height vector to get pointy-top polygon coordinates

Source:
Overrides:

Grid Unit Height

#### highlight :Object

Source:
Overrides:

Highlight active grid spaces

• Object

Source:
Overrides:

Grid Unit Width

### Methods

Source:

#### getCenter(x, y) → {Array.<number>}

Source:
Overrides:

Given a pair of coordinates (x, y), return the center of the grid square which contains that point

##### Parameters:
Name Type Description
`x` number

The x-coordinate

`y` number

The y-coordinate

##### Returns:

An array [cx, cy] of the central point of the grid space which contains (x, y)

Type
Array.<number>

#### getFlatHexPolygon(x, y, w, h) → {Array}

Source:

Get the points which form a flat-topped hex polygon starting at {x,y} with width and height of {w,h}

##### Parameters:
Name Type Description
`x` number

The top-left x-coordinate for the hexagon frame

`y` number

The top-left y-coordinate for the hexagon frame

`w` number

The hexagon width

`h` number

The hexagon height

Type
Array

#### getGridPositionFromPixels(x, y) → {Array.<number>}

Source:
Overrides:

Given a pair of pixel coordinates, return the grid position as an Array. Always round down to the nearest grid position so the pixels are within the grid space (from top-left).

##### Parameters:
Name Type Description
`x` number

The x-coordinate pixel position

`y` number

The y-coordinate pixel position

##### Returns:

An array representing the position in grid units

Type
Array.<number>

#### getNeighbors(row, col) → {Array}

Source:
Overrides:

Get the grid row and column positions which are neighbors of a certain position

##### Parameters:
Name Type Description
`row` Number

The grid row coordinate against which to test for neighbors

`col` Number

The grid column coordinate against which to test for neighbors

##### Returns:

An array of grid positions which are neighbors of the row and column

Type
Array

#### getPixelsFromGridPosition(x, y) → {Array.<number>}

Source:
Overrides:

Given a pair of grid coordinates, return the pixel position as an Array. Always round up to a whole pixel so the pixel is within the grid space (from top-left).

##### Parameters:
Name Type Description
`x` number

The x-coordinate grid position

`y` number

The y-coordinate grid position

##### Returns:

An array representing the position in pixels

Type
Array.<number>

#### getPointyHexPolygon(x, y, w, h) → {Array}

Source:

Get the points which form a pointy-topped hex polygon starting at {x,y} with width and height of {w,h}

##### Parameters:
Name Type Description
`x` number

The top-left x-coordinate for the hexagon frame

`y` number

The top-left y-coordinate for the hexagon frame

`w` number

The hexagon width

`h` number

The hexagon height

Type
Array

#### getSnappedPosition(x, y, interval) → {Object}

Source:
Overrides:

Given a pair of coordinates (x1,y1), return the grid coordinates (x2,y2) which represent the snapped position Under a "gridless" system, every pixel position is a valid snapping position

##### Parameters:
Name Type Default Description
`x` Number

The exact target location x

`y` Number

The exact target location y

`interval` Number `1`

An interval of grid spaces at which to snap, default is 1

##### Returns:

An object containing the coordinates of the snapped location

Type
Object

#### getTopLeft() → {Array}

Source:
Overrides:

Given a pair of coordinates (x, y) - return the top-left of the grid square which contains that point

##### Returns:

An Array [x, y] of the top-left coordinate of the square which contains (x, y)

Type
Array

#### highlightGridPosition(layer, x, y, color, border, alpha)

Source:
Overrides:

Highlight a grid position for a certain coordinates

##### Parameters:
Name Type Description
`layer` GridHighlight

The highlight layer to use

`x` Number

The x-coordinate of the highlighted position

`y` Number

The y-coordinate of the highlighted position

`color` Number

The hex fill color of the highlight

`border` Number

The hex border color of the highlight

`alpha` Number

The opacity of the highlight

#### measureDistances(segments, options) → {Array.<number>}

Source:
Overrides:

Measure the distance traversed over an array of measured segments

##### Parameters:
Name Type Description
`segments` Array.<object>

An Array of measured movement segments

`options` Options

Additional options which modify the measurement

##### Returns:

An Array of distance measurements for each segment

Type
Array.<number>

#### shiftPosition(x, y, dx, dy)

Source:
Overrides:

Shift a pixel position [x,y] by some number of grid units dx and dy

##### Parameters:
Name Type Description
`x` Number

The starting x-coordinate in pixels

`y` Number

The starting y-coordinate in pixels

`dx` Number

The number of grid positions to shift horizontally

`dy` Number

The number of grid positions to shift vertically