AbstractGrid

Kind of class:class
Inherits from:none
Implements:
Known subclasses:
Version:1.0
Author:Francis Bourre
Classpath:com.bourre.structures.AbstractGrid
File last modified:Wednesday, 31 October 2007, 07:35:30
AbstractGrid represents base class for all grid operations

AbstractGrid is an abstract class and can be directly use.

Concrete implementations are :

Instance properties

getVal

getVal:Function
(read,write)
Virtual method for retreiving cell value.

Must be implements in subclass

setVal

setVal:Function
(read,write)
Virtual method for setting cell value.

Must be implements in subclass

Instance methods

checkGridCoords

function checkGridCoords (
) : Void
Indicates if passed-in coordinates can be inside
current grid.

Nothing is returned, result is send to logging API if
passed-in coordinates are not available for current grid.

Example

var g : BGrid = new BGrid(10,10);

//log message "**Error** invalid grid coordinates....
g.checkGridCoords( new Point(20,20) );
Parameters:
v:
a {link Point} instance defining grid access point.

getArea

function getArea (
) : Number
Returns grid area.
Returns:
Number area value

getArrayRange

function getArrayRange (
from:Point, to:Point) : Array

getCloneRange

function getCloneRange (

getColumn

function getColumn (
n:Number, startIndex:Number, endIndex:Number) : Array
Returns all elements contained in a specific grid's column.

Example

var g : BGrid = new BGrid(10,10);
var aColumn : Array = g.getColumn(0);
Parameters:
n :
row index in grid.
startIndex:
optional parameter.
endIndex :
optional parameter.
Returns:
a Array instance with all column's elements (if any) from start index (optional) to end index (optional).

getCoordinates

function getCoordinates (
n:Number) : Point
TODO getCoordinates documentation

getIntFromVector

function getIntFromVector (
v:Point) : Number
TODO getIntFromVector documentation

getIterator

function getIterator (
Returns an com.bourre.data.Iterator instance to iterates
over grid elements.

Use GridIterator class for concrete implementation.

Returns:
an Iterator instance

getRandomCoords

function getRandomCoords (
) : Point
Returns a random grid cell.

Example

var g : BGrid = new BGrid(10,10);
var p : Point = g.getRandomCoords();
Returns:
Point instance with random cell coordinates

getRow

function getRow (
n:Number, startIndex:Number, endIndex:Number) : Array
Returns all elements contained in a specific grid's row.

Example

var g : BGrid = new BGrid(10,10);
var aRow : Array = g.getRow(2);
Parameters:
n :
row index in grid.
startIndex:
optional parameter.
endIndex :
optional parameter.
Returns:
a Array instance with all row's elements (if any) from start index (optional) to end index (optional).

getSize

function getSize (
) : Point
Returns grid dimension.
Returns:
a Point instance

initContent

function initContent (
) : Void
Builds (or resets) an empty 2D Array structure.

Automatically call by Constructor

isGridCoords

function isGridCoords (
v:Point) : Boolean
Checks if passed-in coordinates can be inside
current grid.

Example

var g : BGrid = new BGrid(10,10);
var b : Boolean = g.isGridCoords( new Point(20,20) ); //return false
Parameters:
v:
a {link Point} instance defining grid access point.
Returns:
true is passed-in coordinates are valid for
current grid, either false

searchForAll

function searchForAll (
) : Array
Returns all positions of passed-in Object in grid.
Parameters:
v:
Element to search
Returns:
Array structure representing all element's positions
in grid.

searchForOne

function searchForOne (
) : Point
Returns passed-in Object position in grid.
Parameters:
v:
Element to search
Returns:
Point instance representing element's position
in grid.

toString

function toString (
) : String
Returns the string representation of this instance.
Returns:
the string representation of this instance