[geos-commits] r2937 - in trunk: . capi tests/unit tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Mar 12 02:54:47 EST 2010


Author: strk
Date: 2010-03-12 02:54:45 -0500 (Fri, 12 Mar 2010)
New Revision: 2937

Added:
   trunk/tests/unit/capi/GEOSOrientationIndex.cpp
Modified:
   trunk/NEWS
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
   trunk/tests/unit/Makefile.am
Log:
Expose GEOSOrientationIndex to C-API


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2010-03-10 09:34:02 UTC (rev 2936)
+++ trunk/NEWS	2010-03-12 07:54:45 UTC (rev 2937)
@@ -9,6 +9,7 @@
   - CAPI: GEOSGetGeometryN support for single geometries
   - CAPI: GEOSPolygonize_full to return all informations computed by
           the polygonizer
+  - CAPI: GEOSOrientationIndex
 - C++ API changes:
   - Polygonizer::getCutEdges returns by const ref
   - Polygonizer::getDangles returns by const ref

Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2010-03-10 09:34:02 UTC (rev 2936)
+++ trunk/capi/geos_c.cpp	2010-03-12 07:54:45 UTC (rev 2937)
@@ -967,4 +967,11 @@
     return GEOSGeom_createEmptyPolygon_r(handle);
 }
 
+int
+GEOSOrientationIndex(double Ax, double Ay, double Bx, double By,
+	double Px, double Py)
+{
+    return GEOSOrientationIndex_r(handle, Ax, Ay, Bx, By, Px, Py);
+}
+
 } /* extern "C" */

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-03-10 09:34:02 UTC (rev 2936)
+++ trunk/capi/geos_c.h.in	2010-03-12 07:54:45 UTC (rev 2937)
@@ -909,7 +909,26 @@
                                    const GEOSGeometry *g2,
                                    double densifyFrac, double *dist);
 
+/************************************************************************
+ *
+ * Algorithms
+ *
+ ***********************************************************************/
 
+/* Walking from A to B:
+ *  return -1 if reaching P takes a counter-clockwise (left) turn
+ *  return  1 if reaching P takes a clockwise (right) turn
+ *  return  0 if P is collinear with A-B
+ *
+ * On exceptions, return 2.
+ *
+ */
+extern int GEOSOrientationIndex(double Ax, double Ay, double Bx, double By,
+	double Px, double Py);
+extern int GEOSOrientationIndex_r(GEOSContextHandle_t handle,
+	double Ax, double Ay, double Bx, double By, double Px, double Py);
+
+
 /************************************************************************
  *
  * Reader and Writer APIs

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-03-10 09:34:02 UTC (rev 2936)
+++ trunk/capi/geos_ts_c.cpp	2010-03-12 07:54:45 UTC (rev 2937)
@@ -32,6 +32,7 @@
 #include <geos/geom/PrecisionModel.h> 
 #include <geos/geom/GeometryFactory.h> 
 #include <geos/geom/CoordinateSequenceFactory.h> 
+#include <geos/geom/Coordinate.h> 
 #include <geos/geom/IntersectionMatrix.h> 
 #include <geos/geom/Envelope.h> 
 #include <geos/index/strtree/STRtree.h> 
@@ -41,6 +42,7 @@
 #include <geos/io/WKTWriter.h>
 #include <geos/io/WKBWriter.h>
 #include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
+#include <geos/algorithm/CGAlgorithms.h>
 #include <geos/simplify/DouglasPeuckerSimplifier.h>
 #include <geos/simplify/TopologyPreservingSimplifier.h>
 #include <geos/operation/valid/IsValidOp.h>
@@ -4809,6 +4811,37 @@
     }
 }
 
+int GEOSOrientationIndex_r(GEOSContextHandle_t /*handle*/,
+	double Ax, double Ay, double Bx, double By, double Px, double Py)
+{
+    using geos::geom::Coordinate;
+    using geos::algorithm::CGAlgorithms;
 
+    if ( 0 == extHandle )
+    {
+        return 2;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return 2;
+    }
+
+    try
+    {
+        Coordinate A(Ax, Ay);
+        Coordinate B(Bx, By);
+        Coordinate P(Px, Py);
+        return CGAlgorithms::orientationIndex(A, B, P);
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+        return 2;
+    }
+}
+
+
 } /* extern "C" */
 

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2010-03-10 09:34:02 UTC (rev 2936)
+++ trunk/tests/unit/Makefile.am	2010-03-12 07:54:45 UTC (rev 2937)
@@ -93,7 +93,8 @@
 	capi/GEOSPolygonizer_getCutEdgesTest.cpp \
 	capi/GEOSBufferTest.cpp \
 	capi/GEOSGeom_create.cpp \
-	capi/GEOSGeom_extractUniquePointsTest.cpp
+	capi/GEOSGeom_extractUniquePointsTest.cpp \
+	capi/GEOSOrientationIndex.cpp
 
 noinst_HEADERS = \
 	utility.h

Added: trunk/tests/unit/capi/GEOSOrientationIndex.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSOrientationIndex.cpp	                        (rev 0)
+++ trunk/tests/unit/capi/GEOSOrientationIndex.cpp	2010-03-12 07:54:45 UTC (rev 2937)
@@ -0,0 +1,162 @@
+// $Id$
+// 
+// Test Suite for C-API GEOSOrientationIndex*
+
+#include <tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <string>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <memory>
+
+namespace tut
+{
+    //
+    // Test Group
+    //
+
+    // Common data used in test cases.
+    struct test_capigeosorientationindex_data
+    {
+	GEOSContextHandle_t handle_;
+
+        static void notice(const char *fmt, ...)
+        {
+            std::fprintf( stdout, "NOTICE: ");
+
+            va_list ap;
+            va_start(ap, fmt);
+            std::vfprintf(stdout, fmt, ap);
+            va_end(ap);
+        
+            std::fprintf(stdout, "\n");
+        }
+
+        test_capigeosorientationindex_data()
+            : handle_(initGEOS_r(notice, notice))
+        {
+        }       
+
+        ~test_capigeosorientationindex_data()
+        {
+            finishGEOS_r(handle_);
+        }
+
+    };
+
+    typedef test_group<test_capigeosorientationindex_data> group;
+    typedef group::object object;
+
+    group test_capigeosorientationindex_group("capi::GEOSOrientationIndex");
+
+    //
+    // Test Cases
+    //
+
+    // Interior, collinear
+    template<>
+    template<>
+    void object::test<1>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 0, 5, 0);
+	ensure_equals(ret, 0);
+    }
+
+    // Boundary (last point), collinear
+    template<>
+    template<>
+    void object::test<2>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 0, 10, 0);
+	ensure_equals(ret, 0);
+    }
+
+    // Boundary (first point), collinear
+    template<>
+    template<>
+    void object::test<3>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 0, 0, 0);
+	ensure_equals(ret, 0);
+    }
+
+    // Exterior, before first point, collinear
+    template<>
+    template<>
+    void object::test<4>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 0, -5, 0);
+	ensure_equals(ret, 0);
+    }
+
+    // Exterior, after last point, collinear
+    template<>
+    template<>
+    void object::test<5>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 0, 20, 0);
+	ensure_equals(ret, 0);
+    }
+
+    // Exterior, in bounding box, turn left
+    template<>
+    template<>
+    void object::test<6>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 10, 5, 6);
+	ensure_equals(ret, 1);
+    }
+
+    // Exterior, outside bounding box, turn left
+    template<>
+    template<>
+    void object::test<7>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 10, 5, 20);
+	ensure_equals(ret, 1);
+    }
+
+    // Exterior, in bounding box, turn right
+    template<>
+    template<>
+    void object::test<8>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 10, 5, 3);
+	ensure_equals(ret, -1);
+    }
+
+    // Exterior, outside bounding box, turn left
+    template<>
+    template<>
+    void object::test<9>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 10, 5, -2);
+	ensure_equals(ret, -1);
+    }
+
+    // Exterior, outside bounding box, very close to collinear, turn left
+    template<>
+    template<>
+    void object::test<10>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 10, 1000000, 1000001);
+	ensure_equals(ret, 1);
+    }
+
+    // Exterior, outside bounding box, very close to collinear, turn right
+    template<>
+    template<>
+    void object::test<11>()
+    {
+	int ret = GEOSOrientationIndex(0, 0, 10, 10, 1000000,  999999);
+	ensure_equals(ret, -1);
+    }
+
+
+
+
+} // namespace tut
+



More information about the geos-commits mailing list