Class GridCoordinates2D

  • All Implemented Interfaces:
    Serializable, Cloneable, GridCoordinates, Cloneable

    public class GridCoordinates2D
    extends Point
    implements GridCoordinates
    Holds the set of two-dimensional grid coordinates that specifies the location of the grid point within the grid. This class extends Point for interoperability with Java2D.
    Since:
    2.5
    Author:
    Martin Desruisseaux
    See Also:
    GeneralGridCoordinates, Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class Point2D

        Point2D.Double, Point2D.Float
    • Field Summary

      • Fields inherited from class Point

        x, y
    • Constructor Summary

      Constructors 
      Constructor Description
      GridCoordinates2D()
      Creates an initially empty grid coordinates.
      GridCoordinates2D​(int x, int y)
      Creates a grid coordinates initialized to the specified values.
      GridCoordinates2D​(Point coordinates)
      Creates a grid coordinates initialized to the specified point.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      GridCoordinates2D clone()
      Returns a clone of this coordinates.
      int getCoordinateValue​(int dimension)
      Returns the coordinate value at the specified dimension.
      int[] getCoordinateValues()
      Returns one integer value for each dimension of the grid.
      int getDimension()
      Returns the number of dimensions, which is always 2.
      void setCoordinateValue​(int dimension, int value)
      Sets the coordinate value at the specified dimension.
      String toString()
      Returns a string representation of this grid coordinates.
      • Methods inherited from class Point

        equals, getLocation, getX, getY, move, setLocation, setLocation, setLocation, translate
      • Methods inherited from class Point2D

        distance, distance, distance, distanceSq, distanceSq, distanceSq, hashCode, setLocation
      • Methods inherited from class Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • GridCoordinates2D

        public GridCoordinates2D()
        Creates an initially empty grid coordinates.
      • GridCoordinates2D

        public GridCoordinates2D​(int x,
                                 int y)
        Creates a grid coordinates initialized to the specified values.
        Parameters:
        x - The x coordinate value.
        y - The y coordinate value.
      • GridCoordinates2D

        public GridCoordinates2D​(Point coordinates)
        Creates a grid coordinates initialized to the specified point.
        Parameters:
        coordinates - The coordinate values to copy.
    • Method Detail

      • getDimension

        public final int getDimension()
        Returns the number of dimensions, which is always 2.
        Specified by:
        getDimension in interface GridCoordinates
        Returns:
        The number of dimensions.
      • getCoordinateValues

        public int[] getCoordinateValues()
        Returns one integer value for each dimension of the grid. This method returns (x,y) in an array of length 2.
        Specified by:
        getCoordinateValues in interface GridCoordinates
        Returns:
        A copy of the coordinates. Changes in the returned array will not be reflected back in this GridCoordinates object.
      • getCoordinateValue

        public int getCoordinateValue​(int dimension)
                               throws IndexOutOfBoundsException
        Returns the coordinate value at the specified dimension. This method is equivalent to getCoordinateValues()[i]. It is provided for efficienty.
        Specified by:
        getCoordinateValue in interface GridCoordinates
        Parameters:
        dimension - The dimension from 0 inclusive to getDimension() exclusive.
        Returns:
        The value at the requested dimension.
        Throws:
        IndexOutOfBoundsException - if the specified dimension is out of bounds.
      • setCoordinateValue

        public void setCoordinateValue​(int dimension,
                                       int value)
                                throws IndexOutOfBoundsException,
                                       UnsupportedOperationException
        Sets the coordinate value at the specified dimension.
        Specified by:
        setCoordinateValue in interface GridCoordinates
        Parameters:
        dimension - The index of the value to set.
        value - The new value.
        Throws:
        IndexOutOfBoundsException - if the specified dimension is out of bounds.
        UnsupportedOperationException - if this grid coordinates is not modifiable.
      • toString

        public String toString()
        Returns a string representation of this grid coordinates.
        Overrides:
        toString in class Point
      • clone

        public GridCoordinates2D clone()
        Returns a clone of this coordinates.
        Specified by:
        clone in interface Cloneable
        Overrides:
        clone in class Point2D
        Returns:
        A clone of this coordinates.
        See Also:
        Object.clone()