Class GridPoint2

  • All Implemented Interfaces:
    java.io.Serializable

    public class GridPoint2
    extends java.lang.Object
    implements java.io.Serializable
    A point in a 2D grid, with integer x and y coordinates
    See Also:
    Serialized Form
    • Field Detail

      • x

        public int x
      • y

        public int y
    • Constructor Detail

      • GridPoint2

        public GridPoint2()
        Constructs a new 2D grid point.
      • GridPoint2

        public GridPoint2​(int x,
                          int y)
        Constructs a new 2D grid point.
        Parameters:
        x - X coordinate
        y - Y coordinate
      • GridPoint2

        public GridPoint2​(GridPoint2 point)
        Copy constructor
        Parameters:
        point - The 2D grid point to make a copy of.
    • Method Detail

      • set

        public GridPoint2 set​(GridPoint2 point)
        Sets the coordinates of this 2D grid point to that of another.
        Parameters:
        point - The 2D grid point to copy the coordinates of.
        Returns:
        this 2D grid point for chaining.
      • set

        public GridPoint2 set​(int x,
                              int y)
        Sets the coordinates of this 2D grid point.
        Parameters:
        x - X coordinate
        y - Y coordinate
        Returns:
        this 2D grid point for chaining.
      • dst2

        public float dst2​(GridPoint2 other)
        Parameters:
        other - The other point
        Returns:
        the squared distance between this point and the other point.
      • dst2

        public float dst2​(int x,
                          int y)
        Parameters:
        x - The x-coordinate of the other point
        y - The y-coordinate of the other point
        Returns:
        the squared distance between this point and the other point.
      • dst

        public float dst​(GridPoint2 other)
        Parameters:
        other - The other point
        Returns:
        the distance between this point and the other vector.
      • dst

        public float dst​(int x,
                         int y)
        Parameters:
        x - The x-coordinate of the other point
        y - The y-coordinate of the other point
        Returns:
        the distance between this point and the other point.
      • add

        public GridPoint2 add​(GridPoint2 other)
        Adds another 2D grid point to this point.
        Parameters:
        other - The other point
        Returns:
        this 2d grid point for chaining.
      • add

        public GridPoint2 add​(int x,
                              int y)
        Adds another 2D grid point to this point.
        Parameters:
        x - The x-coordinate of the other point
        y - The y-coordinate of the other point
        Returns:
        this 2d grid point for chaining.
      • sub

        public GridPoint2 sub​(GridPoint2 other)
        Subtracts another 2D grid point from this point.
        Parameters:
        other - The other point
        Returns:
        this 2d grid point for chaining.
      • sub

        public GridPoint2 sub​(int x,
                              int y)
        Subtracts another 2D grid point from this point.
        Parameters:
        x - The x-coordinate of the other point
        y - The y-coordinate of the other point
        Returns:
        this 2d grid point for chaining.
      • cpy

        public GridPoint2 cpy()
        Returns:
        a copy of this grid point
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object