00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GEOS_NODING_SEGMENTPOINTCOMPARATOR_H
00020 #define GEOS_NODING_SEGMENTPOINTCOMPARATOR_H
00021
00022 #include <geos/export.h>
00023 #include <geos/geom/Coordinate.h>
00024 #include <cassert>
00025
00026 namespace geos {
00027 namespace noding {
00028
00039 class GEOS_DLL SegmentPointComparator {
00040
00041 public:
00042
00051 static int compare(int octant, const geom::Coordinate& p0,
00052 const geom::Coordinate& p1)
00053 {
00054
00055 if (p0.equals2D(p1)) return 0;
00056
00057 int xSign = relativeSign(p0.x, p1.x);
00058 int ySign = relativeSign(p0.y, p1.y);
00059
00060 switch (octant) {
00061 case 0: return compareValue(xSign, ySign);
00062 case 1: return compareValue(ySign, xSign);
00063 case 2: return compareValue(ySign, -xSign);
00064 case 3: return compareValue(-xSign, ySign);
00065 case 4: return compareValue(-xSign, -ySign);
00066 case 5: return compareValue(-ySign, -xSign);
00067 case 6: return compareValue(-ySign, xSign);
00068 case 7: return compareValue(xSign, -ySign);
00069 }
00070 assert(0);
00071 return 0;
00072
00073 }
00074
00075 static int relativeSign(double x0, double x1)
00076 {
00077 if (x0 < x1) return -1;
00078 if (x0 > x1) return 1;
00079 return 0;
00080 }
00081
00082 static int compareValue(int compareSign0, int compareSign1)
00083 {
00084 if (compareSign0 < 0) return -1;
00085 if (compareSign0 > 0) return 1;
00086 if (compareSign1 < 0) return -1;
00087 if (compareSign1 > 0) return 1;
00088 return 0;
00089 }
00090
00091 };
00092
00093 }
00094 }
00095
00096 #endif // GEOS_NODING_SEGMENTPOINTCOMPARATOR_H