Package jsl.modeling.elements.spatial
Class RectangularGridSpatialModel2D
- java.lang.Object
-
- jsl.modeling.elements.spatial.SpatialModel
-
- jsl.modeling.elements.spatial.RectangularGridSpatialModel2D
-
- All Implemented Interfaces:
ObservableIfc
,GetNameIfc
,IdentityIfc
public class RectangularGridSpatialModel2D extends SpatialModel
-
-
Field Summary
Fields Modifier and Type Field Description static int
CELL_CHANGED
An "enum" to indicate that a element has been added when notifying observers-
Fields inherited from class jsl.modeling.elements.spatial.SpatialModel
ADDED_ELEMENT, myDefaultPositionPrecision, myElements, REMOVED_ELEMENT, UPDATED_POSITION
-
-
Constructor Summary
Constructors Constructor Description RectangularGridSpatialModel2D()
Creates a grid in the 2D plane.RectangularGridSpatialModel2D(double x, double y, double width, double height, int numRows, int numCols)
Creates a grid in the 2D plane.RectangularGridSpatialModel2D(double width, double height, int numRows, int numCols)
Creates a grid in the 2D plane.RectangularGridSpatialModel2D(java.lang.String name)
Creates a grid in the 2D plane.RectangularGridSpatialModel2D(java.lang.String name, double x, double y, double width, double height, int numRows, int numCols)
Creates a grid in the 2D plane.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addSpatialElement(SpatialElement element)
Adds the supplied element to the spatial modelboolean
comparePositions(CoordinateIfc coordinate1, CoordinateIfc coordinate2)
Only checks 1st and 2nd coordinates, because of 2D gridboolean
contains(double x, double y)
Checks if the x and y values are in the griddouble
distance(CoordinateIfc fromCoordinate, CoordinateIfc toCoordinate)
Computes the distance between the two supplied coordinatesstatic java.util.List<RectangularCell2D>
findCellsWithMaximumElements(java.util.List<RectangularCell2D> cells)
Across all the cells, which cells have the maximum number of elements in cellsstatic java.util.List<RectangularCell2D>
findCellsWithMinimumElements(java.util.List<RectangularCell2D> cells)
Across all the cells, which cells have the minimum number of elements in cellsstatic RectangularCell2D
findCellWithMinimumElements(java.util.List<RectangularCell2D> cells)
Finds the cell that has the least number of spatial elementsRectangularCell2D
findCellWithMinimumElementsInNeighborhood(double x, double y)
Finds the cell that has the least number of spatial elements.RectangularCell2D
findCellWithMinimumElementsInNeighborhood(double x, double y, boolean includeCore)
Finds the cell that has the least number of spatial elementsRectangularCell2D
findCellWithMinimumElementsInNeighborhood(CoordinateIfc coordinate)
Finds the cell that has the least number of spatial elements.RectangularCell2D
findCellWithMinimumElementsInNeighborhood(CoordinateIfc coordinate, boolean includeCore)
Finds the cell that has the least number of spatial elementsRectangularCell2D
findCellWithMinimumElementsInNeighborhood(RectangularCell2D coreCell)
Finds the cell that has the least number of spatial elements.RectangularCell2D
findCellWithMinimumElementsInNeighborhood(RectangularCell2D coreCell, boolean includeCore)
Finds the cell that has the least number of spatial elementsstatic int
findMaximumNumberOfElements(java.util.List<RectangularCell2D> cells)
Across all the cells, what is the maximum number of elements in cellsstatic int
findMinimumNumberOfElements(java.util.List<RectangularCell2D> cells)
Across all the cells, what is the minimum number of elements in cellsRectangularCell2D
getCell(double x, double y)
The cell that contains this x,y coordinate or null if no cellRectangularCell2D
getCell(int row, int col)
The cell at this row, colRectangularCell2D
getCell(CoordinateIfc coordinate)
Returns the cell that the coordinate is in or nullRectangularCell2D
getCell(SpatialElement element)
Returns the cell that the element is in or nulldouble
getCellHeight()
java.util.Iterator<RectangularCell2D>
getCellIterator()
An iterator to the cells in the grid.java.util.List<RectangularCell2D>
getCellsAsList()
double
getCellWidth()
CoordinateIfc
getCoordinate(double x1, double x2, double x3)
Creates a valid coordinate for this spatial model This method should check whether the coordinate can be represented spatially within this spatial model.CoordinateIfc
getDefaultCoordinate()
Returns a default set of coordinates to be used to initialize the location of spatial elements if necessary.double
getHeight()
RectangularCell2D[][]
getMooreNeighborhood(double x, double y)
Returns an array containing the 1st Moore neighborhood for the cell that contains x and y in the gridRectangularCell2D[][]
getMooreNeighborhood(int row, int col)
Returns an array containing the 1st Moore neighborhood for the cell at row, col in the gridvoid
getMooreNeighborhood(int row, int col, RectangularCell2D[][] neighborhood)
Fills the supplied array with the 1st order Moore neighborhood for the given cell at row, col of the gridRectangularCell2D[][]
getMooreNeighborhood(CoordinateIfc coordinate)
Returns an array containing the 1st Moore neighborhood for the cell that contains x and y in the gridRectangularCell2D[][]
getMooreNeighborhood(RectangularCell2D coreCell)
Returns an array containing the 1st Moore neighborhood for the cell in the gridvoid
getMooreNeighborhood(RectangularCell2D coreCell, RectangularCell2D[][] neighborhood)
Fills the supplied array with the 1st order Moore neighborhood for the given core cell.RectangularCell2D[][]
getMooreNeighborhood(SpatialElementIfc element)
Returns an array containing the 1st Moore neighborhood for the cell that contains x and y in the gridjava.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(double x, double y)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid.java.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(double x, double y, boolean includeCore)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the gridjava.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(int row, int col)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid.java.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(int row, int col, boolean includeCore)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the gridjava.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(CoordinateIfc coordinate)
Returns an list containing the 1st Moore neighborhood for the cell that contains x and y in the grid of the coordinate.java.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(CoordinateIfc coordinate, boolean includeCore)
Returns an list containing the 1st Moore neighborhood for the cell that contains x and y in the grid of the coordinatejava.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(RectangularCell2D coreCell)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid.java.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(RectangularCell2D[][] neighborhood, boolean includeCore)
Copies the non-null cells in the neighborhood into a Listjava.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(RectangularCell2D coreCell, boolean includeCore)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the gridjava.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(SpatialElementIfc element)
Returns an list containing the 1st Moore neighborhood for the cell that contains x and y in the grid of the coordinate.java.util.List<RectangularCell2D>
getMooreNeighborhoodAsList(SpatialElementIfc element, boolean includeCore)
Returns an list containing the 1st Moore neighborhood for the cell that contains x and y in the grid of the coordinateint
getNumColumns()
static NumElementsComparator
getNumElementsComparator()
A comparator based on the number of elements in the cellint
getNumRows()
int
getNumSpatialElementInCell(double x, double y)
Returns the number of spatial elements in the cell that the element is inint
getNumSpatialElementInCell(CoordinateIfc coordinate)
Returns the number of spatial elements in the cell that the element is inint
getNumSpatialElementInCell(SpatialElement element)
Returns the number of spatial elements in the cell that the element is inint
getRowMajorIndex(int row, int col)
The row major index is row(number of columns) + col + 1 Labeling starts at 1 and goes by row (across columns).java.awt.Shape
getShape()
Returns the AWT shape representationjava.util.List<SpatialElementIfc>
getSpatialElementsInCell(double x, double y)
Gets a list of spatial elements that are in the cell with the supplied elementjava.util.List<SpatialElementIfc>
getSpatialElementsInCell(CoordinateIfc coordinate)
Gets a list of spatial elements that are in the cell with the supplied elementjava.util.List<SpatialElementIfc>
getSpatialElementsInCell(SpatialElement element)
Gets a list of spatial elements that are in the cell with the supplied elementdouble
getWidth()
boolean
isValid(CoordinateIfc coordinate)
This only checks whether 1st and 2nd (x,y) coordinates are valid, since this is only rectangular 2D grid.protected boolean
removeSpatialElement(SpatialElement element)
Removes the spatial element from the spatial modelprotected void
setGrid(double startX, double startY, int numRows, int numCols)
Sets up the rectangular grid into points, lines, and rectangle Dividing the grid into the appropriate number of rows and columns.protected void
setHeight(double height)
protected void
setWidth(double width)
static java.util.List<RectangularCell2D>
sortCellsByNumElements(java.util.List<RectangularCell2D> cells)
Returns an array of the cells sorted from smallest to largest based on the number of spacial elements in the cellsjava.lang.String
toString()
protected void
updatePosition()
When the spatial element's position is changed then this method is called to ensure that the spatial model properly tracks the elements position-
Methods inherited from class jsl.modeling.elements.spatial.SpatialModel
addObserver, checkForSpatialElementRemoved, checkSpatialElementAdded, checkSpatialElementPositionChanged, comparePositions, contains, contains, countObservers, deleteObserver, deleteObservers, distance, getCoordinate, getDefaultPositionPrecision, getId, getModel, getName, getObserverState, getUpdatingSpatialElement, isValid, notifyObservers, removeSpatialElement, setDefaultPositionPrecision, setModel, setName, setObserverState, setUpdatingElement, updatePosition_
-
-
-
-
Constructor Detail
-
RectangularGridSpatialModel2D
public RectangularGridSpatialModel2D()
Creates a grid in the 2D plane. The grid is based on the standard user coordinate system, with (x,y) = (0,0) being the upper left most corner point, with the x-axis going from left to right and the y-axis going from the top down Default values name = use default assigned name x = 0.0 The x coordinate of the upper left most corner point y = 0.0 The y coordinate of the upper left most corner point width = Double.MAX_VALUE The width (along the x-axis) of the grid height = Double.MAX_VALUE The height (along the y-axis) of the grid numRows = 1 The number of rows in the grid (0-based) numCols = 1 The number of columns in the grid (0-based)
-
RectangularGridSpatialModel2D
public RectangularGridSpatialModel2D(java.lang.String name)
Creates a grid in the 2D plane. The grid is based on the standard user coordinate system, with (x,y) = (0,0) being the upper left most corner point, with the x-axis going from left to right and the y-axis going from the top down Default values x = 0.0 The x coordinate of the upper left most corner point y = 0.0 The y coordinate of the upper left most corner point width = Double.MAX_VALUE The width (along the x-axis) of the grid height = Double.MAX_VALUE The height (along the y-axis) of the grid numRows = 1 The number of rows in the grid (0-based) numCols = 1 The number of columns in the grid (0-based)- Parameters:
name
- The name of the spatial model
-
RectangularGridSpatialModel2D
public RectangularGridSpatialModel2D(double width, double height, int numRows, int numCols)
Creates a grid in the 2D plane. The grid is based on the standard user coordinate system, with (x,y) = (0,0) being the upper left most corner point, with the x-axis going from left to right and the y-axis going from the top down Default values name = use default assigned name x = 0.0 The x coordinate of the upper left most corner point y = 0.0 The y coordinate of the upper left most corner point- Parameters:
width
- The width (along the x-axis) of the gridheight
- The height (along the y-axis) of the gridnumRows
- The number of rows in the grid (0-based)numCols
- The number of columns in the grid (0-based)
-
RectangularGridSpatialModel2D
public RectangularGridSpatialModel2D(double x, double y, double width, double height, int numRows, int numCols)
Creates a grid in the 2D plane. The grid is based on the standard user coordinate system, with (x,y) = (0,0) being the upper left most corner point, with the x-axis going from left to right and the y-axis going from the top down- Parameters:
x
- The x coordinate of the upper left most corner pointy
- The y coordinate of the upper left most corner pointwidth
- The width (along the x-axis) of the gridheight
- The height (along the y-axis) of the gridnumRows
- The number of rows in the grid (0-based)numCols
- The number of columns in the grid (0-based)
-
RectangularGridSpatialModel2D
public RectangularGridSpatialModel2D(java.lang.String name, double x, double y, double width, double height, int numRows, int numCols)
Creates a grid in the 2D plane. The grid is based on the standard user coordinate system, with (x,y) = (0,0) being the upper left most corner point, with the x-axis going from left to right and the y-axis going from the top down- Parameters:
name
- The name of the spatial modelx
- The x coordinate of the upper left most corner pointy
- The y coordinate of the upper left most corner pointwidth
- The width (along the x-axis) of the gridheight
- The height (along the y-axis) of the gridnumRows
- The number of rows in the grid (0-based)numCols
- The number of columns in the grid (0-based)
-
-
Method Detail
-
contains
public final boolean contains(double x, double y)
Checks if the x and y values are in the grid- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- true if in the grid
-
getShape
public final java.awt.Shape getShape()
Returns the AWT shape representation- Returns:
-
getCellWidth
public final double getCellWidth()
- Returns:
- Returns the cell width.
-
getCellHeight
public final double getCellHeight()
- Returns:
- Returns the cell height.
-
getNumColumns
public final int getNumColumns()
- Returns:
- Returns the number of columns.
-
getNumRows
public final int getNumRows()
- Returns:
- Returns the number of rows
-
getHeight
public final double getHeight()
- Returns:
- Returns the height.
-
getWidth
public final double getWidth()
- Returns:
- Returns the width.
-
getCell
public final RectangularCell2D getCell(SpatialElement element)
Returns the cell that the element is in or null- Parameters:
element
- the element- Returns:
- the cell or null
-
getNumSpatialElementInCell
public final int getNumSpatialElementInCell(SpatialElement element)
Returns the number of spatial elements in the cell that the element is in- Parameters:
element
- the element to check- Returns:
- zero if element is not in cell or the number
-
getNumSpatialElementInCell
public final int getNumSpatialElementInCell(CoordinateIfc coordinate)
Returns the number of spatial elements in the cell that the element is in- Parameters:
coordinate
- the coordinate to check- Returns:
- zero if element is not in cell or the number
-
getNumSpatialElementInCell
public final int getNumSpatialElementInCell(double x, double y)
Returns the number of spatial elements in the cell that the element is in- Parameters:
x
- the x coordinatey
- the y coordinate- Returns:
- zero if element is not in cell or the number
-
getSpatialElementsInCell
public final java.util.List<SpatialElementIfc> getSpatialElementsInCell(SpatialElement element)
Gets a list of spatial elements that are in the cell with the supplied element- Parameters:
element
- the element- Returns:
- the list
-
getSpatialElementsInCell
public final java.util.List<SpatialElementIfc> getSpatialElementsInCell(CoordinateIfc coordinate)
Gets a list of spatial elements that are in the cell with the supplied element- Parameters:
coordinate
- the coordinate- Returns:
- the list
-
getSpatialElementsInCell
public final java.util.List<SpatialElementIfc> getSpatialElementsInCell(double x, double y)
Gets a list of spatial elements that are in the cell with the supplied element- Parameters:
x
- the x coordinatey
- the y coordinate- Returns:
- the list
-
getCell
public final RectangularCell2D getCell(CoordinateIfc coordinate)
Returns the cell that the coordinate is in or null- Parameters:
coordinate
-- Returns:
- the cell or null
-
getCell
public final RectangularCell2D getCell(double x, double y)
The cell that contains this x,y coordinate or null if no cell- Parameters:
x
- the x coordinatey
- the y coordinate- Returns:
- the cell or null
-
getCell
public final RectangularCell2D getCell(int row, int col)
The cell at this row, col- Parameters:
row
- the rowcol
- the column- Returns:
- the cell or null
-
getRowMajorIndex
public final int getRowMajorIndex(int row, int col)
The row major index is row(number of columns) + col + 1 Labeling starts at 1 and goes by row (across columns). For example for a 3 by 3 grid[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
- Parameters:
row
- the rowcol
- the column- Returns:
- the row major index of the cell
-
getCellIterator
public final java.util.Iterator<RectangularCell2D> getCellIterator()
An iterator to the cells in the grid. The cells are accesses by rows (row, col): (0,0), then (0,1), etc 0th row first,- Returns:
- an iterator over the cells in the grid
-
getCellsAsList
public final java.util.List<RectangularCell2D> getCellsAsList()
- Returns:
- an unmodifiable list of the cells
-
findCellWithMinimumElements
public static final RectangularCell2D findCellWithMinimumElements(java.util.List<RectangularCell2D> cells)
Finds the cell that has the least number of spatial elements- Parameters:
cells
- the cells to search- Returns:
- the minimum cell or null
-
findMinimumNumberOfElements
public static final int findMinimumNumberOfElements(java.util.List<RectangularCell2D> cells)
Across all the cells, what is the minimum number of elements in cells- Parameters:
cells
- cells to search- Returns:
- the minimum
-
findMaximumNumberOfElements
public static final int findMaximumNumberOfElements(java.util.List<RectangularCell2D> cells)
Across all the cells, what is the maximum number of elements in cells- Parameters:
cells
- cells to search- Returns:
- the maximum
-
findCellsWithMinimumElements
public static final java.util.List<RectangularCell2D> findCellsWithMinimumElements(java.util.List<RectangularCell2D> cells)
Across all the cells, which cells have the minimum number of elements in cells- Parameters:
cells
- the cells to search- Returns:
- a list of cells that have the minimum number of elements
-
findCellsWithMaximumElements
public static final java.util.List<RectangularCell2D> findCellsWithMaximumElements(java.util.List<RectangularCell2D> cells)
Across all the cells, which cells have the maximum number of elements in cells- Parameters:
cells
- the cells to search- Returns:
- a list of cells that have the maximum number of elements
-
getNumElementsComparator
public static NumElementsComparator getNumElementsComparator()
A comparator based on the number of elements in the cell- Returns:
- A comparator based on the number of elements in the cell
-
sortCellsByNumElements
public static final java.util.List<RectangularCell2D> sortCellsByNumElements(java.util.List<RectangularCell2D> cells)
Returns an array of the cells sorted from smallest to largest based on the number of spacial elements in the cells- Parameters:
cells
- the cells to sort- Returns:
- a new list of the sorted cells
-
findCellWithMinimumElementsInNeighborhood
public final RectangularCell2D findCellWithMinimumElementsInNeighborhood(RectangularCell2D coreCell, boolean includeCore)
Finds the cell that has the least number of spatial elements- Parameters:
coreCell
- the core cellincludeCore
- true includes the core in the list, false does not- Returns:
- the minimum cell or null
-
findCellWithMinimumElementsInNeighborhood
public final RectangularCell2D findCellWithMinimumElementsInNeighborhood(RectangularCell2D coreCell)
Finds the cell that has the least number of spatial elements. The core cell is not included in the list- Parameters:
coreCell
- the core cell- Returns:
- the minimum cell or null
-
findCellWithMinimumElementsInNeighborhood
public final RectangularCell2D findCellWithMinimumElementsInNeighborhood(CoordinateIfc coordinate, boolean includeCore)
Finds the cell that has the least number of spatial elements- Parameters:
coordinate
- the coordinate in a cellincludeCore
- true includes the core in the list, false does not- Returns:
- the minimum cell or null
-
findCellWithMinimumElementsInNeighborhood
public final RectangularCell2D findCellWithMinimumElementsInNeighborhood(CoordinateIfc coordinate)
Finds the cell that has the least number of spatial elements. The core cell is not include in the search- Parameters:
coordinate
- the coordinate in a cell- Returns:
- the minimum cell or null
-
findCellWithMinimumElementsInNeighborhood
public final RectangularCell2D findCellWithMinimumElementsInNeighborhood(double x, double y, boolean includeCore)
Finds the cell that has the least number of spatial elements- Parameters:
x
- the x-coordinatey
- the y-coordinateincludeCore
- true includes the core in the list, false does not- Returns:
- the minimum cell or null
-
findCellWithMinimumElementsInNeighborhood
public final RectangularCell2D findCellWithMinimumElementsInNeighborhood(double x, double y)
Finds the cell that has the least number of spatial elements. The core cell is not included in the search- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- the minimum cell or null
-
getMooreNeighborhood
public final RectangularCell2D[][] getMooreNeighborhood(RectangularCell2D coreCell)
Returns an array containing the 1st Moore neighborhood for the cell in the grid- Parameters:
coreCell
- the core cell in the neighborhood- Returns:
- the neighborhood array
-
getMooreNeighborhood
public final RectangularCell2D[][] getMooreNeighborhood(CoordinateIfc coordinate)
Returns an array containing the 1st Moore neighborhood for the cell that contains x and y in the grid- Parameters:
coordinate
- the coordinate- Returns:
- the neighborhood array
-
getMooreNeighborhood
public final RectangularCell2D[][] getMooreNeighborhood(SpatialElementIfc element)
Returns an array containing the 1st Moore neighborhood for the cell that contains x and y in the grid- Parameters:
element
- the element- Returns:
- the neighborhood array
-
getMooreNeighborhood
public final RectangularCell2D[][] getMooreNeighborhood(double x, double y)
Returns an array containing the 1st Moore neighborhood for the cell that contains x and y in the grid- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- the neighborhood array
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(CoordinateIfc coordinate, boolean includeCore)
Returns an list containing the 1st Moore neighborhood for the cell that contains x and y in the grid of the coordinate- Parameters:
coordinate
- the coordinateincludeCore
- true includes the core in the list, false does not- Returns:
- the neighborhood array
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(CoordinateIfc coordinate)
Returns an list containing the 1st Moore neighborhood for the cell that contains x and y in the grid of the coordinate. The core cell is not included in the list- Parameters:
coordinate
- the coordinate- Returns:
- the neighborhood array
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(SpatialElementIfc element, boolean includeCore)
Returns an list containing the 1st Moore neighborhood for the cell that contains x and y in the grid of the coordinate- Parameters:
element
- the elementincludeCore
- true includes the core in the list, false does not- Returns:
- the neighborhood array
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(SpatialElementIfc element)
Returns an list containing the 1st Moore neighborhood for the cell that contains x and y in the grid of the coordinate. The core cell is not included in the list- Parameters:
element
- the element- Returns:
- the neighborhood array
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(double x, double y, boolean includeCore)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid- Parameters:
x
- the x-coordinatey
- the y-coordinateincludeCore
- true includes the core in the list, false does not- Returns:
- the list
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(double x, double y)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid. The core cell is not included in the list.- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- the list
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(RectangularCell2D coreCell, boolean includeCore)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid- Parameters:
coreCell
- the core cellincludeCore
- true includes the core in the list, false does not- Returns:
- the list
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(RectangularCell2D coreCell)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid. The core cell is not included in the list- Parameters:
coreCell
- the core cell- Returns:
- the list
-
getMooreNeighborhood
public final RectangularCell2D[][] getMooreNeighborhood(int row, int col)
Returns an array containing the 1st Moore neighborhood for the cell at row, col in the grid- Parameters:
row
- the rowcol
- the column- Returns:
- the filled array
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(int row, int col, boolean includeCore)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid- Parameters:
row
- the rowcol
- the columnincludeCore
- true includes the core in the list, false does not- Returns:
- the list
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(int row, int col)
Returns a list containing the 1st Moore neighborhood for the cell at row, col in the grid. The core cell is not included in the list.- Parameters:
row
- the rowcol
- the column- Returns:
- the list
-
getMooreNeighborhood
public final void getMooreNeighborhood(int row, int col, RectangularCell2D[][] neighborhood)
Fills the supplied array with the 1st order Moore neighborhood for the given cell at row, col of the grid- Parameters:
row
- the rowcol
- the columnneighborhood
- the array to fill
-
getMooreNeighborhoodAsList
public final java.util.List<RectangularCell2D> getMooreNeighborhoodAsList(RectangularCell2D[][] neighborhood, boolean includeCore)
Copies the non-null cells in the neighborhood into a List- Parameters:
neighborhood
- the neighborhood to translateincludeCore
- true includes the core in the list, false does not- Returns:
- the list of cells in the neighborhood
-
getDefaultCoordinate
public CoordinateIfc getDefaultCoordinate()
Returns a default set of coordinates to be used to initialize the location of spatial elements if necessary.- Specified by:
getDefaultCoordinate
in classSpatialModel
- Returns:
-
getCoordinate
public CoordinateIfc getCoordinate(double x1, double x2, double x3)
Description copied from class:SpatialModel
Creates a valid coordinate for this spatial model This method should check whether the coordinate can be represented spatially within this spatial model. If not, an IllegalArgumentException should be thrown- Specified by:
getCoordinate
in classSpatialModel
- Returns:
-
isValid
public boolean isValid(CoordinateIfc coordinate)
This only checks whether 1st and 2nd (x,y) coordinates are valid, since this is only rectangular 2D grid. The coordinate is valid if it is within the boundary defined by the rectangle for the grid- Specified by:
isValid
in classSpatialModel
- Returns:
-
distance
public double distance(CoordinateIfc fromCoordinate, CoordinateIfc toCoordinate)
Description copied from class:SpatialModel
Computes the distance between the two supplied coordinates- Specified by:
distance
in classSpatialModel
- Returns:
-
comparePositions
public boolean comparePositions(CoordinateIfc coordinate1, CoordinateIfc coordinate2)
Only checks 1st and 2nd coordinates, because of 2D grid- Specified by:
comparePositions
in classSpatialModel
- Returns:
-
getMooreNeighborhood
public final void getMooreNeighborhood(RectangularCell2D coreCell, RectangularCell2D[][] neighborhood)
Fills the supplied array with the 1st order Moore neighborhood for the given core cell. set the top row of the neighborhood neighborhood[0][0] = getCell(i-1, j-1) neighborhood[0][1] = getCell(i-1, j) neighborhood[0][2] = getCell(i-1, j+1) set the middle row of the neighborhood neighborhood[1][0] = getCell(i, j-1) neighborhood[1][1] = getCell(i, j) neighborhood[1][2] = getCell(i, j+1) set the bottom row of the neighborhood neighborhood[2][0] = getCell(i+1,j-1) neighborhood[2][1] = getCell(i+1, j) neighborhood[2][2] = getCell(i+1, j+1)- Parameters:
coreCell
-neighborhood
-
-
addSpatialElement
protected void addSpatialElement(SpatialElement element)
Description copied from class:SpatialModel
Adds the supplied element to the spatial model- Overrides:
addSpatialElement
in classSpatialModel
-
removeSpatialElement
protected boolean removeSpatialElement(SpatialElement element)
Removes the spatial element from the spatial model- Parameters:
element
-- Returns:
-
updatePosition
protected final void updatePosition()
When the spatial element's position is changed then this method is called to ensure that the spatial model properly tracks the elements position- Overrides:
updatePosition
in classSpatialModel
-
setHeight
protected final void setHeight(double height)
- Parameters:
height
- The height to set.
-
setWidth
protected final void setWidth(double width)
- Parameters:
width
- The width to set.
-
setGrid
protected final void setGrid(double startX, double startY, int numRows, int numCols)
Sets up the rectangular grid into points, lines, and rectangle Dividing the grid into the appropriate number of rows and columns.- Parameters:
startX
-startY
-numRows
-numCols
-
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-