- connection-grid-core ⇐
@mitchallen/grid-core
Connection Grid Core generated by create
- connection-grid-core-factory
A factory for generating connection grid core objects
- @mitchallen/grid-core
Grid Core
connection-grid-core ⇐ @mitchallen/grid-core
Connection Grid Core generated by create
Extends: @mitchallen/grid-core
- connection-grid-core ⇐
@mitchallen/grid-core
- .isDir(dir) ⇒
boolean
- .getOppositeDir(dir) ⇒
string
- .getNeighbor(x, y, dir) ⇒
string
- .getNeighborDirs(x, y)
- .getShuffledNeighborDirs(x, y)
- .setFlag(x, y) ⇒
boolean
- .clearFlag(x, y) ⇒
boolean
- .isFlagSet(x, y) ⇒
boolean
- .markVisited(x, y) ⇒
boolean
- .clearVisited(x, y) ⇒
boolean
- .clearAllVisited()
- .visited(x, y) ⇒
boolean
- .mask(x, y) ⇒
boolean
- .clearMask(x, y) ⇒
boolean
- .clearAllMasks()
- .isMasked(x, y) ⇒
boolean
- .markRed(x, y) ⇒
boolean
- .clearRed(x, y) ⇒
boolean
- .clearAllRed()
- .isRed(x, y) ⇒
boolean
- .markGreen(x, y) ⇒
boolean
- .clearGreen(x, y) ⇒
boolean
- .clearAllGreen()
- .isGreen(x, y) ⇒
boolean
- .hasConnections(x, y) ⇒
boolean
- .open(x, y, dir)
- .close(x, y, dir)
- .connect(x, y, dir) ⇒
boolean
- .disconnect(x, y, dir) ⇒
boolean
- .connectUndirected(x, y, dir) ⇒
boolean
- .disconnectUndirected(x, y, dir) ⇒
boolean
- .connects(x, y, dir) ⇒
boolean
- .connectsAny(x, y, list) ⇒
boolean
- .getMaxDistance(x, y) ⇒
MaxDistance
- .getDistance(x, y) ⇒
MaxDistance
- .connectionCount(x, y) ⇒
number
- .isLeaf(x, y) ⇒
boolean
- .reset(x, y) ⇒
boolean
- .isDir(dir) ⇒
Returns true if string is found in DIR_MAP array.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
dir | string |
A string representing a direction |
Example (usage)
if(core.isDir("N")) ...
Returns opposite direction based on OPPOSITE array.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
dir | string |
A string representing a direction |
Example (usage)
core.getOppositeDir("N").should.eql("S");
Returns the neighbor in a particular direction for a cell at x,y. This should be overriden by derived class
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
dir | string |
A string representing a direction |
Example (usage)
var neighbor = core.getNeighbor(1,2,"N");
Returns the neighbor directions for a cell at x,y. This should be overriden by derived class. Classic square grids ignore x and y, but other derived classes, like hexagon, may not.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
var neighbors = core.getNeighborDirs(1,2);
Returns a shuffled list of neighbors for a cell at x,y. Useful for generating random mazes.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
var neighbors = core.getShuffledNeighborDirs(1,2);
Sets a flag in a cell at x,y
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.setFlag(1,2,VISITED);
Clears a flag from cell
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.clearFlag(1,2,flag);
Returns true if a cell at x,y exists and flag has been set.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
if(core.isFlagSet(x,y,VISITED)) ...
Marks a cell at x,y as visited.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.markVisited(1,2);
Clears visit flag from cell
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.clearVisited(1,2);
Clear all visited flag from grid
Kind: instance method of connection-grid-core
Example (usage)
core.clearAllVisited();
Returns true if a cell at x,y exists and it has been marked as visited.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
if(core.visited(x)) ...
Marks a cell at x,y as masked. Useful for maze generators to mark cells to skip
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.mask(1,2)
Clear the mask flag from cell at x,y. Useful for maze generators to mark and clear cells to skip
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.clearMask(1,2)
Clear all mask flags from grid
Kind: instance method of connection-grid-core
Example (usage)
core.clearAllMasks();
Returns true if a cell at x,y has been marked using mask.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
if(core.isMasked(1,2)) ...
Marks a cell at x,y as red.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.markRed(1,2)
Clear the red flag from cell at x,y.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.clearRed(1,2)
Clear all red flags from grid
Kind: instance method of connection-grid-core
Example (usage)
core.clearAllRed();
Returns true if a cell at x,y has been set red using markRed.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
if(core.isRed(1,2)) ...
Marks a cell at x,y as green.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.markGreen(1,2)
Clear the green flag from cell at x,y.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
core.clearGreen(1,2)
Clear all green flags from grid
Kind: instance method of connection-grid-core
Example (usage)
core.clearAllGreen();
Returns true if a cell at x,y has been set green using markGreen.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
if(core.isGreen(1,2)) ...
Returns true if a cell at x,y has connections.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
if(core.hasConnections(1,2)) ...
Maps a connection for a cell at x,y in a particular direction. Unlike connect a cell in the direction does not have to exist. Useful for mazes that need to open up border walls.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
dir | string |
A string representing a direction |
Example (usage)
core.open(0,0,"N");
Removes a connection for a cell at x,y in a particular direction. Unlike connect a cell in the direction does not have to exist.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
dir | string |
A string representing a direction |
Example (usage)
core.close(0,0,"N");
Maps a connection for a cell at x,y in a particular direction. Returns false if the cell in the target direction does not exist.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
dir | string |
A string representing a direction |
Example (usage)
if(core.connect(1,2,"N")) ...
Removes connection for a cell at x,y in a particular direction. Returns false if the cell in the target direction does not exist.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
dir | string |
A string representing a direction |
Example (usage)
if(core.disconnect(1,2,"N")) ...
Maps a connection for a cell at x,y in a particular direction. Also maps a connection from the target cell back to the source cell. Returns false if the cell in the target direction does not exist.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
dir | string |
A string representing a direction |
Example (usage)
if(core.connectUndirected(1,2,"N")) ...
Removes a connection for a cell at x,y in a particular direction. Also removes a connection from the target cell back from the source cell. Returns false if the cell in the target direction does not exist.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
dir | string |
A string representing a direction |
Example (usage)
if(core.disconnectUndirected(1,2,"N")) ...
Returns true if a cell connects to a neighbor cell in a particular direction. It does not matter if a the target cell exists such as when open maps a connection to a non-existant cell.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
dir | string |
A string representing a direction |
Example (usage)
if(core.connects(1,2,"N")) ...
Returns true if a cell connects to a neighbor cell in any direction in the list.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
list | array |
An array of strings that each represent a direction |
Example (usage)
if(core.connectsAny(1,2,["N","W"]) ...
Returns cell that is max distance from x,y.
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
let d = core.getMaxDistance(1,2)
console.log( "DISTANCE: " + d.x + ", " + d.y + " = " + d.distance );
Internal recursive function that update internal maxDistance
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Returns number of connections for cell
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
let count = core.connectionCount(1,2)
Returns true or false if cell is a dead end / leaf node (only one connection)
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
let flag = core.isLeaf(1,2);
Clears all connections and flags from cell
Kind: instance method of connection-grid-core
Param | Type | Description |
---|---|---|
x | number |
The x coordinate |
y | number |
The y coordinate |
Example (usage)
let isCell = core.reset(1,2);
A factory for generating connection grid core objects
connection-grid-core-factory.create(options) ⇒ connection-grid-core
Factory method that returns a connection grid core object. It takes one spec parameter that must be an object with named parameters.
Kind: static method of connection-grid-core-factory
Param | Type | Description |
---|---|---|
options | Object |
Named parameters for generating a connection grid core |
options.grid | grid |
Grid based on @mitchallen/grid-core |
options.dirMap | dirMap |
Direction map containing bit map flags for directions |
options.oppositeMap | oppositeMap |
Opposite direction map |
Example (Creating a connection-grid-core)
"use strict";
var gridFactory = require("@mitchallen/connection-grid-core"),
gridSquare = require('@mitchallen/grid-square')
var sourceGrid = gridSquare.create({ x: 5, y: 6 });
var _dirMap = {
"N": 0x010,
"S": 0x020,
"E": 0x040,
"W": 0x080 };
let _oppositeMap = { "E": "W", "W": "E", "N": "S", "S": "N" };
var cg = gridFactory.create({
grid: sourceGrid,
dirMap: _dirMap,
oppositeMap: _oppositeMap
});
Grid Core
Kind: global external
See: @mitchallen/grid-core