GEOS
3.3.8
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.refractions.net 00005 * 00006 * Copyright (C) 2006 Refractions Research Inc. 00007 * 00008 * This is free software; you can redistribute and/or modify it under 00009 * the terms of the GNU Lesser General Public Licence as published 00010 * by the Free Software Foundation. 00011 * See the COPYING file for more information. 00012 * 00013 ********************************************************************** 00014 * 00015 * Last port: noding/SegmentPointComparator.java r320 (JTS-1.12) 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 { // geos.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 // nodes can only be equal if their coordinates are equal 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); // invalid octant value 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 } // namespace geos.noding 00094 } // namespace geos 00095 00096 #endif // GEOS_NODING_SEGMENTPOINTCOMPARATOR_H