Skip to content

Latest commit

 

History

History
715 lines (555 loc) · 24.8 KB

DOC-API.md

File metadata and controls

715 lines (555 loc) · 24.8 KB

Modules

connection-grid-core@mitchallen/grid-core

Connection Grid Core generated by create

connection-grid-core-factory

A factory for generating connection grid core objects

External

@mitchallen/grid-core

Grid Core

connection-grid-core ⇐ @mitchallen/grid-core

Connection Grid Core generated by create

Extends: @mitchallen/grid-core

connection-grid-core.isDir(dir) ⇒ boolean

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")) ...

connection-grid-core.getOppositeDir(dir) ⇒ string

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");

connection-grid-core.getNeighbor(x, y, dir) ⇒ string

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");

connection-grid-core.getNeighborDirs(x, y)

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

connection-grid-core.getShuffledNeighborDirs(x, y)

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

connection-grid-core.setFlag(x, y) ⇒ boolean

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

connection-grid-core.clearFlag(x, y) ⇒ boolean

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

connection-grid-core.isFlagSet(x, y) ⇒ boolean

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

connection-grid-core.markVisited(x, y) ⇒ boolean

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

connection-grid-core.clearVisited(x, y) ⇒ boolean

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

connection-grid-core.clearAllVisited()

Clear all visited flag from grid

Kind: instance method of connection-grid-core
Example (usage)

core.clearAllVisited();

connection-grid-core.visited(x, y) ⇒ boolean

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

connection-grid-core.mask(x, y) ⇒ boolean

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)

connection-grid-core.clearMask(x, y) ⇒ boolean

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)

connection-grid-core.clearAllMasks()

Clear all mask flags from grid

Kind: instance method of connection-grid-core
Example (usage)

core.clearAllMasks();

connection-grid-core.isMasked(x, y) ⇒ boolean

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

connection-grid-core.markRed(x, y) ⇒ boolean

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)

connection-grid-core.clearRed(x, y) ⇒ boolean

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)

connection-grid-core.clearAllRed()

Clear all red flags from grid

Kind: instance method of connection-grid-core
Example (usage)

core.clearAllRed();

connection-grid-core.isRed(x, y) ⇒ boolean

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

connection-grid-core.markGreen(x, y) ⇒ boolean

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)

connection-grid-core.clearGreen(x, y) ⇒ boolean

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)

connection-grid-core.clearAllGreen()

Clear all green flags from grid

Kind: instance method of connection-grid-core
Example (usage)

core.clearAllGreen();

connection-grid-core.isGreen(x, y) ⇒ boolean

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

connection-grid-core.hasConnections(x, y) ⇒ boolean

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

connection-grid-core.open(x, y, dir)

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");

connection-grid-core.close(x, y, dir)

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");

connection-grid-core.connect(x, y, dir) ⇒ boolean

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")) ...

connection-grid-core.disconnect(x, y, dir) ⇒ boolean

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")) ...

connection-grid-core.connectUndirected(x, y, dir) ⇒ boolean

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")) ...

connection-grid-core.disconnectUndirected(x, y, dir) ⇒ boolean

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")) ...

connection-grid-core.connects(x, y, dir) ⇒ boolean

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")) ...

connection-grid-core.connectsAny(x, y, list) ⇒ boolean

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"]) ...

connection-grid-core.getMaxDistance(x, y) ⇒ MaxDistance

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

connection-grid-core.getDistance(x, y) ⇒ MaxDistance

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

connection-grid-core.connectionCount(x, y) ⇒ number

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)

connection-grid-core.isLeaf(x, y) ⇒ boolean

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

connection-grid-core.reset(x, y) ⇒ boolean

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

connection-grid-core-factory

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 
});

@mitchallen/grid-core

Grid Core

Kind: global external
See: @mitchallen/grid-core