Package repast.simphony.space.grid
Class BouncyBorders
- java.lang.Object
-
- repast.simphony.space.grid.AbstractGridPointTranslator
-
- repast.simphony.space.grid.BouncyBorders
-
- All Implemented Interfaces:
GridPointTranslator
public class BouncyBorders extends AbstractGridPointTranslator
Calculates a new location by translating a current one. If the new location is outside some specified bounds then, the new location will be calculated by "bouncing" off the boundaries. This assumes that any boundaries are either horizontal or vertical such that the "bounce" only involves a simple sign change of the direction vector.- Author:
- Nick Collier
-
-
Field Summary
-
Fields inherited from class repast.simphony.space.grid.AbstractGridPointTranslator
dimensions
-
-
Constructor Summary
Constructors Constructor Description BouncyBorders()
Creates a new BouncyBorders.BouncyBorders(int... dimensions)
Creates a BounceTranslator whose boundaries are the specified dimensions.BouncyBorders(int[] dimensions, int[] origin)
Creates a BounceTranslator whose boundaries are the specified dimensions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
init(GridDimensions dimensions)
Initializes this with the given dimensions.boolean
isToroidal()
True if this grid is toroidal (in the sense that moving off one border makes you appear on the other one), otherwise false.void
translate(int[] location, int... displacement)
Translate the specified location by the specified displacement.-
Methods inherited from class repast.simphony.space.grid.AbstractGridPointTranslator
boundsCheck, transform, transform
-
-
-
-
Constructor Detail
-
BouncyBorders
public BouncyBorders()
Creates a new BouncyBorders.
-
BouncyBorders
public BouncyBorders(int... dimensions)
Creates a BounceTranslator whose boundaries are the specified dimensions. A boundary is created from each dimension having a min of 0 and a max of dimension - 1.- Parameters:
dimensions
-
-
BouncyBorders
public BouncyBorders(int[] dimensions, int[] origin)
Creates a BounceTranslator whose boundaries are the specified dimensions. A boundary is created from each dimension having a min of 0 and a max of dimension - 1.- Parameters:
dimensions
-
-
-
Method Detail
-
translate
public void translate(int[] location, int... displacement)
Translate the specified location by the specified displacement. The new location will stored in the location array. For example, if the location is (3, 4) and the displacement is (1, -2), the new location will be (4, 2). This will bounce off of any boundaries if necessary.- Parameters:
location
- the current locationdisplacement
- the amount to translate
-
init
public void init(GridDimensions dimensions)
Description copied from class:AbstractGridPointTranslator
Initializes this with the given dimensions.- Specified by:
init
in interfaceGridPointTranslator
- Overrides:
init
in classAbstractGridPointTranslator
- Parameters:
dimensions
- the dimensions of the space
-
isToroidal
public boolean isToroidal()
Description copied from interface:GridPointTranslator
True if this grid is toroidal (in the sense that moving off one border makes you appear on the other one), otherwise false.- Returns:
- true if this grid is toroidal, otherwise false.
-
-