Class ConvexHull.RadialComparator

  • All Implemented Interfaces:
    java.util.Comparator
    Enclosing class:
    ConvexHull

    private static class ConvexHull.RadialComparator
    extends java.lang.Object
    implements java.util.Comparator
    Compares Coordinates for their angle and distance relative to an origin.
    Version:
    1.7
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Coordinate origin  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.Object o1, java.lang.Object o2)  
      private static int polarCompare​(Coordinate o, Coordinate p, Coordinate q)
      Given two points p and q compare them with respect to their radial ordering about point o.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • RadialComparator

        public RadialComparator​(Coordinate origin)
    • Method Detail

      • compare

        public int compare​(java.lang.Object o1,
                           java.lang.Object o2)
        Specified by:
        compare in interface java.util.Comparator
      • polarCompare

        private static int polarCompare​(Coordinate o,
                                        Coordinate p,
                                        Coordinate q)
        Given two points p and q compare them with respect to their radial ordering about point o. First checks radial ordering. If points are collinear, the comparison is based on their distance to the origin.

        p < q iff

        • ang(o-p) < ang(o-q) (e.g. o-p-q is CCW)
        • or ang(o-p) == ang(o-q) && dist(o,p) < dist(o,q)
        Parameters:
        o - the origin
        p - a point
        q - another point
        Returns:
        -1, 0 or 1 depending on whether p is less than, equal to or greater than q