[geos-commits] r3234 - in trunk: include/geos/noding src/noding
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Feb 23 05:25:20 EST 2011
Author: strk
Date: 2011-02-23 02:25:20 -0800 (Wed, 23 Feb 2011)
New Revision: 3234
Added:
trunk/include/geos/noding/SegmentPointComparator.h
Modified:
trunk/include/geos/noding/Makefile.am
trunk/src/noding/SegmentNode.cpp
Log:
Take SegmentPointComparator out of implelmentation file, to allow for unit-testing.
Modified: trunk/include/geos/noding/Makefile.am
===================================================================
--- trunk/include/geos/noding/Makefile.am 2011-02-23 09:37:10 UTC (rev 3233)
+++ trunk/include/geos/noding/Makefile.am 2011-02-23 10:25:20 UTC (rev 3234)
@@ -29,6 +29,7 @@
SegmentIntersector.h \
SegmentNode.h \
SegmentNodeList.h \
+ SegmentPointComparator.h \
SegmentSetMutualIntersector.h \
SegmentString.h \
SegmentString.inl \
Added: trunk/include/geos/noding/SegmentPointComparator.h
===================================================================
--- trunk/include/geos/noding/SegmentPointComparator.h (rev 0)
+++ trunk/include/geos/noding/SegmentPointComparator.h 2011-02-23 10:25:20 UTC (rev 3234)
@@ -0,0 +1,94 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2006 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: noding/SegmentPointComparator.java r320 (JTS-1.12)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_SEGMENTPOINTCOMPARATOR_H
+#define GEOS_NODING_SEGMENTPOINTCOMPARATOR_H
+
+#include <geos/geom/Coordinate.h>
+
+namespace geos {
+namespace noding { // geos.noding
+
+/**
+ * Implements a robust method of comparing the relative position of two
+ * points along the same segment.
+ * The coordinates are assumed to lie "near" the segment.
+ * This means that this algorithm will only return correct results
+ * if the input coordinates
+ * have the same precision and correspond to rounded values
+ * of exact coordinates lying on the segment.
+ *
+ */
+class SegmentPointComparator {
+
+public:
+
+ /**
+ * Compares two Coordinates for their relative position along a
+ * segment lying in the specified Octant.
+ *
+ * @return -1 node0 occurs first
+ * @return 0 the two nodes are equal
+ * @return 1 node1 occurs first
+ */
+ static int compare(int octant, const geom::Coordinate& p0,
+ const geom::Coordinate& p1)
+ {
+ // nodes can only be equal if their coordinates are equal
+ if (p0.equals2D(p1)) return 0;
+
+ int xSign = relativeSign(p0.x, p1.x);
+ int ySign = relativeSign(p0.y, p1.y);
+
+ switch (octant) {
+ case 0: return compareValue(xSign, ySign);
+ case 1: return compareValue(ySign, xSign);
+ case 2: return compareValue(ySign, -xSign);
+ case 3: return compareValue(-xSign, ySign);
+ case 4: return compareValue(-xSign, -ySign);
+ case 5: return compareValue(-ySign, -xSign);
+ case 6: return compareValue(-ySign, xSign);
+ case 7: return compareValue(xSign, -ySign);
+ }
+ assert(0); // invalid octant value
+ return 0;
+
+ }
+
+ static int relativeSign(double x0, double x1)
+ {
+ if (x0 < x1) return -1;
+ if (x0 > x1) return 1;
+ return 0;
+ }
+
+ static int compareValue(int compareSign0, int compareSign1)
+ {
+ if (compareSign0 < 0) return -1;
+ if (compareSign0 > 0) return 1;
+ if (compareSign1 < 0) return -1;
+ if (compareSign1 > 0) return 1;
+ return 0;
+ }
+
+};
+
+} // namespace geos.noding
+} // namespace geos
+
+#endif // GEOS_NODING_SEGMENTPOINTCOMPARATOR_H
Modified: trunk/src/noding/SegmentNode.cpp
===================================================================
--- trunk/src/noding/SegmentNode.cpp 2011-02-23 09:37:10 UTC (rev 3233)
+++ trunk/src/noding/SegmentNode.cpp 2011-02-23 10:25:20 UTC (rev 3234)
@@ -27,6 +27,7 @@
#include <iomanip>
#include <geos/noding/SegmentNode.h>
+#include <geos/noding/SegmentPointComparator.h>
#include <geos/noding/NodedSegmentString.h>
#include <geos/geom/Coordinate.h>
@@ -37,71 +38,6 @@
namespace noding { // geos.noding
-/**
- * Implements a robust method of comparing the relative position of two
- * points along the same segment.
- * The coordinates are assumed to lie "near" the segment.
- * This means that this algorithm will only return correct results
- * if the input coordinates
- * have the same precision and correspond to rounded values
- * of exact coordinates lying on the segment.
- *
- * Last port: noding/SegmentPointComparator.java rev. 1.2 (JTS-1.7)
- */
-class SegmentPointComparator {
-
-public:
-
- /**
- * Compares two Coordinates for their relative position along a
- * segment lying in the specified Octant.
- *
- * @return -1 node0 occurs first
- * @return 0 the two nodes are equal
- * @return 1 node1 occurs first
- */
- static int compare(int octant, const Coordinate& p0,
- const Coordinate& p1)
- {
- // nodes can only be equal if their coordinates are equal
- if (p0.equals2D(p1)) return 0;
-
- int xSign = relativeSign(p0.x, p1.x);
- int ySign = relativeSign(p0.y, p1.y);
-
- switch (octant) {
- case 0: return compareValue(xSign, ySign);
- case 1: return compareValue(ySign, xSign);
- case 2: return compareValue(ySign, -xSign);
- case 3: return compareValue(-xSign, ySign);
- case 4: return compareValue(-xSign, -ySign);
- case 5: return compareValue(-ySign, -xSign);
- case 6: return compareValue(-ySign, xSign);
- case 7: return compareValue(xSign, -ySign);
- }
- assert(0); // invalid octant value
- return 0;
-
- }
-
- static int relativeSign(double x0, double x1)
- {
- if (x0 < x1) return -1;
- if (x0 > x1) return 1;
- return 0;
- }
-
- static int compareValue(int compareSign0, int compareSign1)
- {
- if (compareSign0 < 0) return -1;
- if (compareSign0 > 0) return 1;
- if (compareSign1 < 0) return -1;
- if (compareSign1 > 0) return 1;
- return 0;
- }
-
-};
-
/*public*/
SegmentNode::SegmentNode(const NodedSegmentString& ss, const Coordinate& nCoord,
unsigned int nSegmentIndex, int nSegmentOctant)
More information about the geos-commits
mailing list