Class 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
  • Constructor Details

    • 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 Details

    • 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 location
      displacement - 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 interface GridPointTranslator
      Overrides:
      init in class AbstractGridPointTranslator
      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.