[geos-commits] r2327 - in trunk/source: geom headers/geos/geom
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Apr 8 10:41:58 EDT 2009
Author: strk
Date: 2009-04-08 10:41:58 -0400 (Wed, 08 Apr 2009)
New Revision: 2327
Modified:
trunk/source/geom/CoordinateSequence.cpp
trunk/source/headers/geos/geom/CoordinateSequence.h
Log:
Add increasingDirection static method, from JTS's CoordinateArray (GEOS puts all of them in CoordinateSequence for historical reasons)
Modified: trunk/source/geom/CoordinateSequence.cpp
===================================================================
--- trunk/source/geom/CoordinateSequence.cpp 2009-04-08 13:16:37 UTC (rev 2326)
+++ trunk/source/geom/CoordinateSequence.cpp 2009-04-08 14:41:58 UTC (rev 2327)
@@ -141,6 +141,21 @@
cl->setPoints(v);
}
+int
+CoordinateSequence::increasingDirection(const CoordinateSequence& pts)
+{
+ size_t ptsize = pts.size();
+ for (size_t i=0, n=ptsize/2; i<n; ++i)
+ {
+ size_t j = ptsize - 1 - i;
+ // skip equal points on both ends
+ int comp = pts[i].compareTo(pts[j]);
+ if (comp != 0) return comp;
+ }
+ // array must be a palindrome - defined to be in positive direction
+ return 1;
+}
+
void
CoordinateSequence::reverse(CoordinateSequence *cl)
{
Modified: trunk/source/headers/geos/geom/CoordinateSequence.h
===================================================================
--- trunk/source/headers/geos/geom/CoordinateSequence.h 2009-04-08 13:16:37 UTC (rev 2326)
+++ trunk/source/headers/geos/geom/CoordinateSequence.h 2009-04-08 14:41:58 UTC (rev 2327)
@@ -265,6 +265,25 @@
/// Scroll given CoordinateSequence so to start with given Coordinate.
static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
+ /** \brief
+ * Determines which orientation of the {@link Coordinate} array
+ * is (overall) increasing.
+ *
+ * In other words, determines which end of the array is "smaller"
+ * (using the standard ordering on {@link Coordinate}).
+ * Returns an integer indicating the increasing direction.
+ * If the sequence is a palindrome, it is defined to be
+ * oriented in a positive direction.
+ *
+ * @param pts the array of Coordinates to test
+ * @return <code>1</code> if the array is smaller at the start
+ * or is a palindrome,
+ * <code>-1</code> if smaller at the end
+ *
+ * NOTE: this method is found in CoordinateArrays class for JTS
+ */
+ static int increasingDirection(const CoordinateSequence& pts);
+
/// Reverse Coordinate order in given CoordinateSequence
static void reverse(CoordinateSequence *cl);
More information about the geos-commits
mailing list