Class CoordPair


  • public final class CoordPair
    extends java.lang.Object
    A class to describe a coordinate (in Euclidean space). It consists of a pair of (x, y) values.

    Instances of this class are immutable. All change operations return a new instance of this CoordPair class.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static CoordPair ZERO_ZERO
      The CoordPair corresponding to the (0, 0) origin.
    • Constructor Summary

      Constructors 
      Constructor Description
      CoordPair()
      Instantiates a CoordPair with the coordinate (0, 0).
      CoordPair​(CoordPair source)
      Deprecated.
      CoordPair is immutable, so there is no need to copy an instance.
      CoordPair​(UnitSpan x, UnitSpan y)
      Instantiates a CoordPair from the given UnitSpan(s).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CoordPair add​(CoordPair add)
      Returns a CoordPair representing the addition of this object and the given CoordPair.
      boolean equals​(java.lang.Object object)
      Determines if this object is equal to the given Object.
      CoordPair grid​(CoordPair grid)
      Returns a CoordPair representing this CoordPair snaped to the nearest grid coordinates of the given CoordPair.
      boolean gt​(CoordPair compare)
      Determines if this object is greater than the given CoordPair.
      int hashCode()  
      boolean lt​(CoordPair compare)
      Determines if this object is less than the given CoordPair.
      boolean notEquals​(java.lang.Object compare)
      Determines if this object is not equal to the given Object.
      CoordPair rotatePoint​(CoordPair oRPoint, Angle oAngle)
      Returns a CoordPair representing the rotation of this object through the given Angle and about the given CoordPair.
      CoordPair round​(CoordPair round)
      Returns a CoordPair representing the rounding of this object's coordinates to the given CoordPair.
      CoordPair scale​(double dXScale, double dYScale)
      Returns a CoordPair representing the scaling of this object to the given scaling factors.
      CoordPair subtract​(CoordPair subtract)
      Returns a CoordPair representing the subtraction of this object and the given CoordPair.
      UnitSpan x()
      Gets this object's x coordinate.
      UnitSpan y()
      Gets this object's y coordinate.
      static CoordPair zeroZero()
      The zero (0, 0) coordinate.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ZERO_ZERO

        public static final CoordPair ZERO_ZERO
        The CoordPair corresponding to the (0, 0) origin.
    • Constructor Detail

      • CoordPair

        public CoordPair()
        Instantiates a CoordPair with the coordinate (0, 0).
        See Also:
        zeroZero()
      • CoordPair

        public CoordPair​(CoordPair source)
        Deprecated.
        CoordPair is immutable, so there is no need to copy an instance.
        Instantiates a CoordPair from the given CoordPair.
        Parameters:
        source - the CoordPair to copy to this object.
      • CoordPair

        public CoordPair​(UnitSpan x,
                         UnitSpan y)
        Instantiates a CoordPair from the given UnitSpan(s).
        Parameters:
        x - the x coordinate.
        y - the y coordinate.
    • Method Detail

      • grid

        public CoordPair grid​(CoordPair grid)
        Returns a CoordPair representing this CoordPair snaped to the nearest grid coordinates of the given CoordPair.
        Parameters:
        grid - the grid coordinate
        Returns:
        a coordinate aligned to the grid.
        See Also:
        UnitSpan.grid(UnitSpan)
      • round

        public CoordPair round​(CoordPair round)
        Returns a CoordPair representing the rounding of this object's coordinates to the given CoordPair.
        Parameters:
        round - the rounding coordinate.
        Returns:
        a coordinate of the rounding.
        See Also:
        UnitSpan.round(UnitSpan)
      • x

        public UnitSpan x()
        Gets this object's x coordinate.
        Returns:
        the x coordinate.
      • y

        public UnitSpan y()
        Gets this object's y coordinate.
        Returns:
        the y coordinate.
      • rotatePoint

        public CoordPair rotatePoint​(CoordPair oRPoint,
                                     Angle oAngle)
        Returns a CoordPair representing the rotation of this object through the given Angle and about the given CoordPair.
        Parameters:
        oRPoint - the point of rotation.
        oAngle - the angle of rotation.
        Returns:
        a coordinate of the rotation.
      • equals

        public boolean equals​(java.lang.Object object)
        Determines if this object is equal to the given Object. Comparisons with instances of non-CoordPair objects are never equal. When comparing instances of CoordPair objects, the object's UnitSpan coordinates are each compared for equality.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - the Object to compare.
        Returns:
        true if equal, false otherwise.
        See Also:
        UnitSpan.equals(Object)
      • hashCode

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

        public boolean notEquals​(java.lang.Object compare)
        Determines if this object is not equal to the given Object. Comparisons with instances of non-CoordPair objects are always not equal. When comparing instances of CoordPair objects, the object's UnitSpan coordinates are each compared for inequality.
        Parameters:
        compare - the Object to compare.
        Returns:
        true if not equal, false othewise.
        See Also:
        equals(Object)
      • add

        public CoordPair add​(CoordPair add)
        Returns a CoordPair representing the addition of this object and the given CoordPair.
        Parameters:
        add - the CoordPair to add.
        Returns:
        a coordinate of the addition.
      • subtract

        public CoordPair subtract​(CoordPair subtract)
        Returns a CoordPair representing the subtraction of this object and the given CoordPair.
        Parameters:
        subtract - the CoordPair to subtract.
        Returns:
        a coordinate of the subtraction.
      • scale

        public CoordPair scale​(double dXScale,
                               double dYScale)
        Returns a CoordPair representing the scaling of this object to the given scaling factors.
        Parameters:
        dXScale - the X coordinate scaling factor.
        dYScale - the Y coordinate scaling factor.
        Returns:
        a coordinate of the scaling.
      • gt

        public boolean gt​(CoordPair compare)
        Determines if this object is greater than the given CoordPair. Coordinate comparisons rules are as follows: order by the y coordnate first, and if equal, then by the x coordinate.
        Parameters:
        compare - the CoordPair to compare.
        Returns:
        true if greater than, false otherwise.
      • lt

        public boolean lt​(CoordPair compare)
        Determines if this object is less than the given CoordPair. Coordinate comparisons rules as as follows: order by the y coordnate first, and if equal, then by the x coordinate.
        Parameters:
        compare - the CoordPair to compare.
        Returns:
        true if greater than, false otherwise.
      • zeroZero

        public static CoordPair zeroZero()
        The zero (0, 0) coordinate.
        Returns:
        the coordinate equal to (0, 0).