[geos-commits] r2328 - in trunk/source: headers/geos/noding noding
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Apr 8 10:54:59 EDT 2009
Author: strk
Date: 2009-04-08 10:54:59 -0400 (Wed, 08 Apr 2009)
New Revision: 2328
Added:
trunk/source/headers/geos/noding/OrientedCoordinateArray.h
trunk/source/noding/OrientedCoordinateArray.cpp
Modified:
trunk/source/headers/geos/noding/Makefile.am
trunk/source/noding/Makefile.am
Log:
OrientedCoordinateArray ported from JTS
Modified: trunk/source/headers/geos/noding/Makefile.am
===================================================================
--- trunk/source/headers/geos/noding/Makefile.am 2009-04-08 14:41:58 UTC (rev 2327)
+++ trunk/source/headers/geos/noding/Makefile.am 2009-04-08 14:54:59 UTC (rev 2328)
@@ -19,6 +19,7 @@
Noder.h \
NodingValidator.h \
Octant.h \
+ OrientedCoordinateArray.h \
ScaledNoder.h \
SegmentIntersectionDetector.h \
SegmentIntersector.h \
Added: trunk/source/headers/geos/noding/OrientedCoordinateArray.h
===================================================================
--- trunk/source/headers/geos/noding/OrientedCoordinateArray.h (rev 0)
+++ trunk/source/headers/geos/noding/OrientedCoordinateArray.h 2009-04-08 14:54:59 UTC (rev 2328)
@@ -0,0 +1,105 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ *
+ * 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/OrientedCoordinateArray.java rev. 1.1 (JTS-1.9)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_ORIENTEDCOORDINATEARRAY_H
+#define GEOS_NODING_ORIENTEDCOORDINATEARRAY_H
+
+//#include <vector>
+//#include <iostream>
+
+//#include <geos/inline.h>
+
+// Forward declarations
+namespace geos {
+ namespace geom {
+ class CoordinateSequence;
+ }
+ namespace noding {
+ //class SegmentString;
+ }
+}
+
+namespace geos {
+namespace noding { // geos.noding
+
+/** \brief
+ * Allows comparing {@link geom::CoordinateSequence}s
+ * in an orientation-independent way.
+ */
+class OrientedCoordinateArray
+{
+public:
+
+ /**
+ * Creates a new {@link OrientedCoordinateArray}
+ * for the given {@link geom::CoordinateSequence}.
+ *
+ * @param pts the coordinates to orient
+ */
+ OrientedCoordinateArray(const geom::CoordinateSequence& pts)
+ :
+ pts(pts),
+ orientationVar(orientation(pts))
+ {
+ }
+
+ /** \brief
+ * Compares two {@link OrientedCoordinateArray}s for their
+ * relative order
+ *
+ * @return -1 this one is smaller
+ * @return 0 the two objects are equal
+ * @return 1 this one is greater
+ *
+ * In JTS, this is used automatically by ordered lists.
+ * In C++, operator< would be used instead....
+ */
+ int compareTo(const OrientedCoordinateArray& o1);
+
+
+private:
+
+ static int compareOriented(const geom::CoordinateSequence& pts1,
+ bool orientation1,
+ const geom::CoordinateSequence& pts2,
+ bool orientation2);
+
+
+ /**
+ * Computes the canonical orientation for a coordinate array.
+ *
+ * @param pts the array to test
+ * @return <code>true</code> if the points are oriented forwards
+ * @return <code>false</code if the points are oriented in reverse
+ */
+ static bool orientation(const geom::CoordinateSequence& pts);
+
+ /// Externally owned
+ const geom::CoordinateSequence& pts;
+
+ bool orientationVar;
+};
+
+
+} // namespace geos.noding
+} // namespace geos
+
+
+#endif // GEOS_NODING_ORIENTEDCOORDINATEARRAY_H
+
Modified: trunk/source/noding/Makefile.am
===================================================================
--- trunk/source/noding/Makefile.am 2009-04-08 14:41:58 UTC (rev 2327)
+++ trunk/source/noding/Makefile.am 2009-04-08 14:54:59 UTC (rev 2328)
@@ -16,6 +16,7 @@
NodedSegmentString.cpp \
NodingValidator.cpp \
Octant.cpp \
+ OrientedCoordinateArray.cpp \
ScaledNoder.cpp \
SegmentIntersectionDetector.cpp \
SegmentNode.cpp \
Added: trunk/source/noding/OrientedCoordinateArray.cpp
===================================================================
--- trunk/source/noding/OrientedCoordinateArray.cpp (rev 0)
+++ trunk/source/noding/OrientedCoordinateArray.cpp 2009-04-08 14:54:59 UTC (rev 2328)
@@ -0,0 +1,93 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ *
+ * 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/OrientedCoordinateArray.java rev. 1.1 (JTS-1.9)
+ *
+ **********************************************************************/
+
+//#include <cmath>
+//#include <sstream>
+
+#include <geos/noding/OrientedCoordinateArray.h>
+
+//#include <geos/util/IllegalArgumentException.h>
+//#include <geos/noding/Octant.h>
+//#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+
+//using namespace std;
+using namespace geos::geom;
+
+namespace geos {
+namespace noding { // geos.noding
+
+bool
+OrientedCoordinateArray::orientation(const CoordinateSequence& pts)
+{
+ return CoordinateSequence::increasingDirection(pts) == 1;
+}
+
+int
+OrientedCoordinateArray::compareTo(const OrientedCoordinateArray& oca)
+{
+ int comp = compareOriented(pts, orientationVar,
+ oca.pts, oca.orientationVar);
+#if 0 // MD - testing only
+ int oldComp = SegmentStringDissolver.ptsComp.compare(pts, oca.pts);
+ if ((oldComp == 0 || comp == 0) && oldComp != comp) {
+ System.out.println("bidir mismatch");
+
+ boolean orient1 = orientation(pts);
+ boolean orient2 = orientation(oca.pts);
+ int comp2 = compareOriented(pts, orientation,
+ oca.pts, oca.orientation);
+ int oldComp2 = SegmentStringDissolver.ptsComp.compare(pts, oca.pts);
+ }
+#endif
+
+ return comp;
+}
+
+int
+OrientedCoordinateArray::compareOriented(const geom::CoordinateSequence& pts1,
+ bool orientation1,
+ const geom::CoordinateSequence& pts2,
+ bool orientation2)
+{
+ int dir1 = orientation1 ? 1 : -1;
+ int dir2 = orientation2 ? 1 : -1;
+ int limit1 = orientation1 ? pts1.size() : -1;
+ int limit2 = orientation2 ? pts2.size() : -1;
+
+ int i1 = orientation1 ? 0 : pts1.size() - 1;
+ int i2 = orientation2 ? 0 : pts2.size() - 1;
+ //int comp = 0; // unused, but is in JTS ...
+ while (true) {
+ int compPt = pts1[i1].compareTo(pts2[i2]);
+ if (compPt != 0)
+ return compPt;
+ i1 += dir1;
+ i2 += dir2;
+ bool done1 = i1 == limit1;
+ bool done2 = i2 == limit2;
+ if (done1 && ! done2) return -1;
+ if (! done1 && done2) return 1;
+ if (done1 && done2) return 0;
+ }
+}
+
+} // namespace geos.noding
+} // namespace geos
+
More information about the geos-commits
mailing list