compareTo method

int compareTo(
  1. Coordinate other
)
override

Compares this {@link Coordinate} with the specified {@link Coordinate} for order. This method ignores the z value when making the comparison. Returns:

  • -1 : this.x < other.x || ((this.x == other.x) && (this.y < other.y))
  • 0 : this.x == other.x && this.y = other.y
  • 1 : this.x > other.x || ((this.x == other.x) && (this.y > other.y))
Note: This method assumes that ordinate values are valid numbers. NaN values are not handled correctly.

@param o the Coordinate with which this Coordinate is being compared @return -1, zero, or 1 as this Coordinate is less than, equal to, or greater than the specified Coordinate

Implementation

int compareTo(Coordinate other) {
  if (x < other.x) return -1;
  if (x > other.x) return 1;
  if (y < other.y) return -1;
  if (y > other.y) return 1;
  return 0;
}