Package jsl.modeling.elements.spatial
Class RectangularCell2D
- java.lang.Object
-
- jsl.modeling.elements.spatial.RectangularCell2D
-
public class RectangularCell2D extends java.lang.Object
Represents a basic unit of a RectangularGridSpatialModel
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addSpatialElement(SpatialElementIfc element)
Add the spatial element to the cellboolean
contains(double x, double y)
Checks if x and y are in this cellint
countModelElements(java.lang.Class targetClass)
Counts the number of ModelElements of the provided class type that are in the cell.int
countSpatialElements(java.lang.Class targetClass)
Counts the number of SpatialElements of the provided class type that are in the cell.CoordinateIfc
getCenterCoordinate()
double
getCenterX()
The x-coordinate of the center of the celldouble
getCenterY()
The y-coordinate of the center of the cellint
getColumnIndex()
<T> java.util.List<T>
getElements(java.lang.Class<T> targetClass)
Gets a list of elements of the target class that are in the celldouble
getHeight()
java.util.List<SpatialElementIfc>
getListOfSpatialElements()
This is a copy.CoordinateIfc
getLowerLeftCoordinate()
CoordinateIfc
getLowerRightCoordinate()
double
getMaxX()
The x-coordinate of the maximum x still within the celldouble
getMaxY()
The y-coordinate of the maximum y still within the celldouble
getMinX()
The x-coordinate of the minimum x still within the celldouble
getMinY()
The y-coordinate of the minimum y still within the celljava.util.List<ModelElement>
getModelElements()
Returns a list of the ModelElements attached to any spatial elements within the cell.<T> java.util.List<T>
getModelElementsOfType(java.lang.Class<T> targetClass)
Gets a list of model elements of the target class that are in the cell This uses getModelElements() as the basis for the searchvoid
getMooreNeighborhood(RectangularCell2D[][] neighborhood)
Returns an array containing the cells associated with the 1st Moore neighborhood for the cell.int
getNumSpatialElements()
RectangularGridSpatialModel2D
getParentRectangularGrid2D()
Returns the RectangularGridSpatialModel2D that contains this celljava.lang.String
getRowColName()
int
getRowIndex()
int
getRowMajorIndex()
The row major index for this cell, based on getRowMajorIndex() of RectangularGridSpatialModel2Djava.util.List<SpatialElementIfc>
getUnmodifiableSpatialElements()
Returns an unmodifiable view of the spatial elements in this cell The list is unmodifiable, i.e.CoordinateIfc
getUpperLeftCoordinate()
CoordinateIfc
getUpperRightCoordinate()
double
getWidth()
double
getX()
The x-coordinate of the upper left corner of the rectangle for the celldouble
getY()
The y-coordinate of the upper left corner of the rectangle for the cellboolean
isAvailable()
Can be used to check if the cell is available or not.protected boolean
removeSpatialElement(SpatialElementIfc element)
Removes the spatial element from the cellvoid
setAvailability(boolean flag)
Can be used to check if the cell is available or not.java.lang.String
toString()
Converts the cell to a string
-
-
-
Method Detail
-
getRowMajorIndex
public final int getRowMajorIndex()
The row major index for this cell, based on getRowMajorIndex() of RectangularGridSpatialModel2D- Returns:
- the index
-
isAvailable
public final boolean isAvailable()
Can be used to check if the cell is available or not. For example, this can be used to see if the cell is available for traversal.- Returns:
- true means available
-
setAvailability
public final void setAvailability(boolean flag)
Can be used to check if the cell is available or not. For example, this can be used to see if the cell is available for traversal.- Parameters:
flag
- true means available
-
getRowColName
public java.lang.String getRowColName()
-
getNumSpatialElements
public final int getNumSpatialElements()
- Returns:
- the number of spatial elements in the cell
-
getElements
public final <T> java.util.List<T> getElements(java.lang.Class<T> targetClass)
Gets a list of elements of the target class that are in the cell- Type Parameters:
T
- the type- Parameters:
targetClass
- the class type- Returns:
- the list
-
getModelElementsOfType
public final <T> java.util.List<T> getModelElementsOfType(java.lang.Class<T> targetClass)
Gets a list of model elements of the target class that are in the cell This uses getModelElements() as the basis for the search- Type Parameters:
T
- the type- Parameters:
targetClass
- the class type- Returns:
- the list
-
countModelElements
public final int countModelElements(java.lang.Class targetClass)
Counts the number of ModelElements of the provided class type that are in the cell. Use X.class for the search, where X is a valid class name.- Parameters:
targetClass
-- Returns:
- the count
-
countSpatialElements
public final int countSpatialElements(java.lang.Class targetClass)
Counts the number of SpatialElements of the provided class type that are in the cell. Use X.class for the search, where X is a valid class name.- Parameters:
targetClass
-- Returns:
- the count
-
getModelElements
public final java.util.List<ModelElement> getModelElements()
Returns a list of the ModelElements attached to any spatial elements within the cell.- Returns:
- a list of the ModelElements attached to any spatial elements within the cell
-
getUnmodifiableSpatialElements
public final java.util.List<SpatialElementIfc> getUnmodifiableSpatialElements()
Returns an unmodifiable view of the spatial elements in this cell The list is unmodifiable, i.e. you can't change the list, but you can still change the elements in the list. WARNING: Don't change the elements unless you really know what you are doing.- Returns:
-
getListOfSpatialElements
public final java.util.List<SpatialElementIfc> getListOfSpatialElements()
This is a copy. The underlying list of spatial elements might change- Returns:
- a copy of the current list of spatial elements
-
getMooreNeighborhood
public final void getMooreNeighborhood(RectangularCell2D[][] neighborhood)
Returns an array containing the cells associated with the 1st Moore neighborhood for the cell.- Parameters:
neighborhood
-
-
toString
public java.lang.String toString()
Converts the cell to a string- Overrides:
toString
in classjava.lang.Object
- Returns:
-
getParentRectangularGrid2D
public final RectangularGridSpatialModel2D getParentRectangularGrid2D()
Returns the RectangularGridSpatialModel2D that contains this cell- Returns:
-
getColumnIndex
public final int getColumnIndex()
- Returns:
- Returns the column index
-
getHeight
public final double getHeight()
- Returns:
- Returns the height of the cell
-
getRowIndex
public final int getRowIndex()
- Returns:
- Returns the cell's Row Index.
-
getWidth
public final double getWidth()
- Returns:
- Returns the cell's Width.
-
contains
public final boolean contains(double x, double y)
Checks if x and y are in this cell- Parameters:
x
-y
-- Returns:
-
getUpperLeftCoordinate
public final CoordinateIfc getUpperLeftCoordinate()
-
getCenterCoordinate
public final CoordinateIfc getCenterCoordinate()
-
getUpperRightCoordinate
public final CoordinateIfc getUpperRightCoordinate()
-
getLowerLeftCoordinate
public final CoordinateIfc getLowerLeftCoordinate()
-
getLowerRightCoordinate
public final CoordinateIfc getLowerRightCoordinate()
-
getX
public final double getX()
The x-coordinate of the upper left corner of the rectangle for the cell- Returns:
-
getY
public final double getY()
The y-coordinate of the upper left corner of the rectangle for the cell- Returns:
-
getCenterX
public final double getCenterX()
The x-coordinate of the center of the cell- Returns:
-
getCenterY
public final double getCenterY()
The y-coordinate of the center of the cell- Returns:
-
getMaxX
public final double getMaxX()
The x-coordinate of the maximum x still within the cell- Returns:
-
getMaxY
public final double getMaxY()
The y-coordinate of the maximum y still within the cell- Returns:
-
getMinX
public final double getMinX()
The x-coordinate of the minimum x still within the cell- Returns:
-
getMinY
public final double getMinY()
The y-coordinate of the minimum y still within the cell- Returns:
-
addSpatialElement
protected void addSpatialElement(SpatialElementIfc element)
Add the spatial element to the cell- Parameters:
element
-
-
removeSpatialElement
protected boolean removeSpatialElement(SpatialElementIfc element)
Removes the spatial element from the cell- Parameters:
element
-- Returns:
-
-