[geos-commits] r4049 - in trunk: . capi tests/unit/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Apr 10 00:37:17 PDT 2015
Author: strk
Date: 2015-04-10 00:37:17 -0700 (Fri, 10 Apr 2015)
New Revision: 4049
Added:
trunk/tests/unit/capi/GEOSisClosedTest.cpp
Modified:
trunk/NEWS
trunk/capi/geos_ts_c.cpp
Log:
Support for MultiLineString->isClosed() in C API
Includes tests for GEOSisClosed() in C API
Patch by Benjamin Morel <benjamin.morel at gmail.com>
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2015-03-02 11:22:29 UTC (rev 4048)
+++ trunk/NEWS 2015-04-10 07:37:17 UTC (rev 4049)
@@ -11,6 +11,7 @@
- Improvements:
- Speed-up intersection and difference between geometries
with small bounding box overlap.
+ - CAPI: add MULTILINESTRING support for GEOSisClosed (Benjamin Morel)
Changes in 3.4.2
2013-08-25
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2015-03-02 11:22:29 UTC (rev 4048)
+++ trunk/capi/geos_ts_c.cpp 2015-04-10 07:37:17 UTC (rev 4049)
@@ -2574,7 +2574,7 @@
}
/*
- * Call only on LINESTRING
+ * Call only on LINESTRING or MULTILINESTRING
* return 2 on exception, 1 on true, 0 on false
*/
char
@@ -2595,13 +2595,20 @@
try
{
using geos::geom::LineString;
+ using geos::geom::MultiLineString;
+
const LineString *ls = dynamic_cast<const LineString *>(g1);
- if ( ! ls )
- {
- handle->ERROR_MESSAGE("Argument is not a LineString");
- return 2;
+ if ( ls ) {
+ return ls->isClosed();
}
- return ls->isClosed();
+
+ const MultiLineString *mls = dynamic_cast<const MultiLineString *>(g1);
+ if ( mls ) {
+ return mls->isClosed();
+ }
+
+ handle->ERROR_MESSAGE("Argument is not a LineString or MultiLineString");
+ return 2;
}
catch (const std::exception &e)
{
Added: trunk/tests/unit/capi/GEOSisClosedTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSisClosedTest.cpp (rev 0)
+++ trunk/tests/unit/capi/GEOSisClosedTest.cpp 2015-04-10 07:37:17 UTC (rev 4049)
@@ -0,0 +1,95 @@
+//
+// Test Suite for C-API GEOSisClosed
+
+#include <tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <cctype>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used in test cases.
+ struct test_capiisclosed_data
+ {
+ GEOSGeometry* geom_;
+
+ 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_capiisclosed_data() : geom_(0)
+ {
+ initGEOS(notice, notice);
+ }
+
+ ~test_capiisclosed_data()
+ {
+ GEOSGeom_destroy(geom_);
+ finishGEOS();
+ }
+
+ };
+
+ typedef test_group<test_capiisclosed_data> group;
+ typedef group::object object;
+
+ group test_capiisclosed_group("capi::GEOSisClosed");
+
+ //
+ // Test Cases
+ //
+
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ geom_ = GEOSGeomFromWKT("LINESTRING(0 0, 1 0, 1 1)");
+ int r = GEOSisClosed(geom_);
+ ensure_equals(r, 0);
+ }
+
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ geom_ = GEOSGeomFromWKT("LINESTRING(0 0, 0 1, 1 1, 0 0)");
+ int r = GEOSisClosed(geom_);
+ ensure_equals(r, 1);
+ }
+
+ template<>
+ template<>
+ void object::test<3>()
+ {
+ geom_ = GEOSGeomFromWKT("MULTILINESTRING ((1 1, 1 2, 2 2, 1 1), (0 0, 0 1, 1 1))");
+ int r = GEOSisClosed(geom_);
+ ensure_equals(r, 0);
+ }
+
+ template<>
+ template<>
+ void object::test<4>()
+ {
+ geom_ = GEOSGeomFromWKT("MULTILINESTRING ((1 1, 1 2, 2 2, 1 1), (0 0, 0 1, 1 1, 0 0))");
+ int r = GEOSisClosed(geom_);
+ ensure_equals(r, 1);
+ }
+
+} // namespace tut
More information about the geos-commits
mailing list