/// <summary> /// Comparator used for ordering point first by ascending X, then by ascending Y. /// </summary> /// <param name="other">The <see cref="Point"/> to compare.</param> /// <returns> /// 0 if the points are spatially equal or both empty; 1 if <paramref name="other"/> is empty or /// if this point has a greater <see cref="X"/> value or equal X values and a greater <see cref="Y"/> value; /// -1 if this point is empty or if <paramref name="other"/> has a greater <see cref="X"/> value or equal X values /// and a greater <see cref="Y"/> value. /// </returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="other"/> is null.</exception> public virtual Int32 CompareTo(Point other) { if (other == null) { throw new ArgumentNullException("other"); } if (Equals(other)) // This handles the case where both are empty. { return(0); } else if (IsEmpty) { return(-1); } else if (other.IsEmpty) { return(1); } else if (Tolerance.Less(X, other.X) || Tolerance.Equal(X, other.X) && Tolerance.Less(Y, other.Y)) { return(-1); } else if (Tolerance.Greater(X, other.X) || Tolerance.Equal(X, other.X) && Tolerance.Greater(Y, other.Y)) { return(1); } throw new InvalidOperationException("Points cannot be compared."); }