BaseGrid

BaseGrid

The base grid class. This double-dips to implement the "gridless" option

Constructor

new BaseGrid()

Source:

Members

h

Source:

Grid Unit Height

highlight :Object

Source:

Highlight active grid spaces

Type:
  • Object

w

Source:

Grid Unit Width

Methods

getCenter() → {Array}

Source:

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

Returns:

An Array [x, y] of the central point of the square which contains (x, y)

Type
Array

getGridPositionFromPixels(x, y) → {Object}

Source:

Given a pair of pixel coordinates, return the grid position as an Array

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
Object

getNeighbors(row, col) → {Array}

Source:

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) → {Object}

Source:

Given a pair of grid coordiantes, return the pixel position as an Array

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
Object

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

Source:

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:

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()

Source:

Highlight a grid position for a certain coordinates No highlighting behavior is supported for Gridless types

measureDistance(p0, p1, gridSpaces) → {number}

Source:

Measure the distance between two pixel coordinates

Parameters:
Name Type Description
p0 Object

The origin coordinate {x, y}

p1 Object

The destination coordinate {x, y}

gridSpaces boolean

Enforce grid distance (if true) vs. direct point-to-point (if false)

Returns:

The distance between p1 and p0

Type
number

shiftPosition(x, y, dx, dy)

Source:

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