Class Projected3DGrid<T>

java.lang.Object
repast.simphony.space.projection.DefaultProjection<T>
repast.simphony.visualization.editor.space.Projected3DGrid<T>
All Implemented Interfaces:
Grid<T>, Projection<T>, ProjectionListener

public class Projected3DGrid<T> extends DefaultProjection<T> implements Grid<T>, ProjectionListener
A grid that reprojects a 3D grid into a 2D grid. This is intended to be used with editing code in visualization and such will not work correctly if used as a regular projection.
Author:
Nick Collier
  • Constructor Details

    • Projected3DGrid

      public Projected3DGrid(Grid<T> grid, int dimIndex1, int dimIndex2)
  • Method Details

    • getConstantIndex

      public int getConstantIndex()
      Gets the index of the constant dimension.
      Returns:
      the index of the constant dimension.
    • getIndex1

      public int getIndex1()
    • getIndex2

      public int getIndex2()
    • getDimensions

      public GridDimensions getDimensions()
      Gets the dimensions of the space.
      Specified by:
      getDimensions in interface Grid<T>
      Returns:
      the dimensions of the space.
    • setAdder

      public void setAdder(GridAdder<T> gridAdder)
      Sets the adder used by this space to add new objects. Unsupported operation.
      Specified by:
      setAdder in interface Grid<T>
      Parameters:
      gridAdder - the adder
    • getCellAccessor

      public CellAccessor getCellAccessor()
      Gets the cell accessor used to control access to individual grid cells.
      Specified by:
      getCellAccessor in interface Grid<T>
      Returns:
      the cell accessor used to control access to individual grid cells.
    • getAdder

      public GridAdder<T> getAdder()
      Gets the adder used by this space to add new objects.
      Specified by:
      getAdder in interface Grid<T>
      Returns:
      the adder used by this space to add new objects.
    • moveTo

      public boolean moveTo(T object, int... newLocation)
      Moves the specified object from its current location to the new location. The object must previously have been introduced into the space. Objects are introduced into the space by adding them to the context of which this space is a projection.
      Specified by:
      moveTo in interface Grid<T>
      Parameters:
      object -
      newLocation -
      Returns:
      true if the move was successful, otherwise false.
      Throws:
      SpatialException - if the object is not already in the space, if the number of dimensions in the location does not agree with the number in the space, or if the object is moved outside the grid dimensions.
    • getLocation

      public GridPoint getLocation(Object obj)
      Gets the location of the specified object.
      Specified by:
      getLocation in interface Grid<T>
      Parameters:
      obj -
      Returns:
      the location of the specified object or null if the object is not in the space.
    • size

      public int size()
      Gets the number of objects currently in the space. This does NOT include any objects that may have been added, but have NOT been moved to a space location.
      Specified by:
      size in interface Grid<T>
      Returns:
      the number of objects currently in the space. This does NOT include any objects that may have been added, but have NOT been moved to a space location.
    • getGridPointTranslator

      public GridPointTranslator getGridPointTranslator()
      Retrieves the rule being used for controlling what happens at or beyond the borders of the space. Unsupported operation.
      Specified by:
      getGridPointTranslator in interface Grid<T>
      Returns:
      the rule for handling out of bounds coordinates
    • setGridPointTranslator

      public void setGridPointTranslator(GridPointTranslator rule)
      Sets the rule to use for controlling what happens at or beyond the borders of the space. Unsupported operation. Unsupported operation.
      Specified by:
      setGridPointTranslator in interface Grid<T>
      Parameters:
      rule - the rule for handling out of bounds coordinates
    • getObjects

      public Iterable<T> getObjects()
      Gets all the object currently in the space. This does NOT include any objects that may have been added, but have NOT been moved to a space location.
      Specified by:
      getObjects in interface Grid<T>
      Returns:
      an iteratable over all the object currently in the space. This does NOT include any objects that may have been added, but have NOT been moved to a space location.
    • getObjectAt

      public T getObjectAt(int... location)
      Gets the object at the specified location.
      Specified by:
      getObjectAt in interface Grid<T>
      Parameters:
      location -
      Returns:
      the object at the specified location.
    • getObjectsAt

      public Iterable<T> getObjectsAt(int... location)
      Gets all the objects at the specified location. For a multi occupancy space this will be all the objects at that location. For a single occupancy space this will be the single object at that location.
      Specified by:
      getObjectsAt in interface Grid<T>
      Parameters:
      location -
      Returns:
      the object at the specified location.
    • getRandomObjectAt

      public T getRandomObjectAt(int... location)
      Gets a random object from among those at the specified location. If this is a single occupancy space this will return the single object at that location, if any. Unsupported operation.
      Specified by:
      getRandomObjectAt in interface Grid<T>
      Parameters:
      location -
      Returns:
      the object at the specified location.
    • moveByDisplacement

      public GridPoint moveByDisplacement(T object, int... displacement)
      Moves the specified object from its current location by the specified amount. For example moveByDisplacement(object, 3, -2, 1) will move the object by 3 along the x-axis, -2 along the y and 1 along the z. The displacement argument can be less than the number of dimensions in the space in which case the remaining argument will be set to 0. For example, moveByDisplacement(object, 3) will move the object 3 along the x-axis and 0 along the y and z axes, assuming a 3D grid.

      Unsupported operation.

      Specified by:
      moveByDisplacement in interface Grid<T>
      Parameters:
      object - the object to move
      displacement - the amount to move the object
      Returns:
      the new location if the move was successful, otherwise null
      Throws:
      SpatialException - if the object is not already in the space or if the number of dimensions in the displacement greater than the number of grid dimensions.
    • moveByVector

      public GridPoint moveByVector(T object, double distance, double... anglesInRadians)
      Moves the specifed object the specified distance from its current position along the specified angle. For example, moveByVector(object, 1, Direction.NORTH) will move the object 1 unit "north" up the y-axis, assuming a 2D grid. Similarly, grid.moveByVector(object, 2, 0, Math.toRadians(90), 0) will rotate 90 degrees around the y-axis, thus moving the object 2 units along the z-axis.

      Note that the radians / degrees are incremented in a anti-clockwise fashion, such that 0 degrees is "east", 90 degrees is "north", 180 is "west" and 270 is "south."

      Unsupported operation.

      Specified by:
      moveByVector in interface Grid<T>
      Parameters:
      object - the object to move
      distance - the distance to move
      anglesInRadians - the angle to move along in radians. Note that Math.toRadians(degrees) is useful here
      Returns:
      the new location or null if the move is not successful
      Throws:
      SpatialException - if the object is not already in the space or if the number of angles is greater than the number of dimensions
      See Also:
    • isPeriodic

      public boolean isPeriodic()
      True if this grid is peridoic (in the sense that moving off one border makes you appear on the other one), otherwise false. A 2D periodic grid is a torus. This is defined by the grid's border behavior which is determined by its GridPointTranslator.
      Specified by:
      isPeriodic in interface Grid<T>
      Returns:
      always false
    • destroy

      public void destroy()
      Destroys this Projected3DGrid by doing any necessary clean up.
    • projectionEventOccurred

      public void projectionEventOccurred(ProjectionEvent evt)
      Invoked when a projection event occurs. This forwards on projection events fired by the 3D grid to any listeners of this grid.
      Specified by:
      projectionEventOccurred in interface ProjectionListener<T>
      Parameters:
      evt - the object describing the event
    • getDistance

      public double getDistance(GridPoint point1, GridPoint point2)
      Gets the the euclidian distance between the GridPoints point1 and point2. If the points do not have the same dimension then this returns Double.NaN
      Specified by:
      getDistance in interface Grid<T>
      Parameters:
      point1 - the first point
      point2 - the second point
      Returns:
      the euclidian distance between the GridPoints point1 and point2. If the points do not have the same dimension then this returns Double.NaN
    • getDistanceSq

      public double getDistanceSq(GridPoint point1, GridPoint point2)
      Gets the square of the euclidian distance between the GridPoints point1 and point2. If the points do not have the same dimension then this returns Double.NaN
      Specified by:
      getDistanceSq in interface Grid<T>
      Parameters:
      point1 - the first point
      point2 - the second point
      Returns:
      the square of the euclidian distance between the GridPoints point1 and point2. If the points do not have the same dimension then this returns Double.NaN