Class WrapAroundBorders

  • All Implemented Interfaces:
    GridPointTranslator

    public class WrapAroundBorders
    extends Object
    implements GridPointTranslator
    Periodic type border implementation. Translates and transforms beyond the grid's dimensions are wrapped around the borders. Creating a 2D grid with these types of border results in a torus.
    Author:
    Jerry Vos
    • Field Detail

      • spaceWidths

        protected transient int[] spaceWidths
      • origin

        protected transient int[] origin
    • Constructor Detail

      • WrapAroundBorders

        public WrapAroundBorders()
    • Method Detail

      • init

        public void init​(GridDimensions dimensions)
        Initializes this with the given dimensions.
        Specified by:
        init in interface GridPointTranslator
        Parameters:
        dimensions - the dimensions of the space
      • translate

        public void translate​(int[] location,
                              int... displacement)
        Translates the specified location by the specified displacement according to periodic "wrapped" semantics. Locations outside the grid will be wrapped into the grid's dimensions. The results will be placed into the location array.
        Specified by:
        translate in interface GridPointTranslator
        Parameters:
        location - the current location
        displacement - the amount of displacement
      • transform

        public void transform​(int[] transformedLocation,
                              int... targetLocation)
                       throws SpatialException
        Transform the given targetLocation according to periodic "wrapped" semantics. The new transformed coordinates will be placed in the transformedLocation.
        Specified by:
        transform in interface GridPointTranslator
        Parameters:
        transformedLocation - the coordinates once they have been transformed by this GridPointTranslator
        targetLocation - the new target location whose coordinates will be transformed
        Throws:
        SpatialException - if the transform is invalid.
      • transform

        public void transform​(GridPoint transformedLocation,
                              int... targetLocation)
                       throws SpatialException
        Transform the given targetLocation according to periodic "wrapped" semantics. The new transformed coordinates will be placed in the transformedLocation.
        Specified by:
        transform in interface GridPointTranslator
        Parameters:
        transformedLocation - the coordinates once they have been transformed by this GridPointTranslator
        targetLocation - the new target location whose coordinates will be transformed
        Throws:
        SpatialException - if the transform is invalid.
      • getNewCoord

        protected int getNewCoord​(int dimension,
                                  int location)
      • 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.
        Specified by:
        isToroidal in interface GridPointTranslator
        Returns:
        true if this grid is toroidal, otherwise false.