[geos-commits] r3305 - in trunk: capi tests/unit/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Apr 27 09:38:53 EDT 2011
Author: strk
Date: 2011-04-27 06:38:53 -0700 (Wed, 27 Apr 2011)
New Revision: 3305
Modified:
trunk/capi/geos_c.cpp
trunk/capi/geos_c.h.in
trunk/capi/geos_ts_c.cpp
trunk/tests/unit/capi/GEOSOffsetCurveTest.cpp
Log:
Drop one argument from GEOSOffsetCurve. Tell right/left from width/distance sign (<0 for right side)
Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp 2011-04-27 13:06:31 UTC (rev 3304)
+++ trunk/capi/geos_c.cpp 2011-04-27 13:38:53 UTC (rev 3305)
@@ -395,10 +395,10 @@
Geometry *
GEOSOffsetCurve(const Geometry *g1, double width, int quadsegs,
- int joinStyle, double mitreLimit, int leftSide)
+ int joinStyle, double mitreLimit)
{
return GEOSOffsetCurve_r( handle, g1, width, quadsegs,
- joinStyle, mitreLimit, leftSide );
+ joinStyle, mitreLimit );
}
Geometry *
Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in 2011-04-27 13:06:31 UTC (rev 3304)
+++ trunk/capi/geos_c.h.in 2011-04-27 13:38:53 UTC (rev 3305)
@@ -466,7 +466,7 @@
int joinStyle, double mitreLimit);
/* These functions return NULL on exception. Only LINESTRINGs are accepted. */
-/* @deprecated: use GEOSOffsetCurve instead */
+/* @deprecated in 3.3.0: use GEOSOffsetCurve instead */
extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer(const GEOSGeometry* g1,
double width, int quadsegs, int joinStyle, double mitreLimit,
int leftSide);
@@ -475,14 +475,18 @@
const GEOSGeometry* g1, double width, int quadsegs,
int joinStyle, double mitreLimit, int leftSide);
-/* These functions return NULL on exception. Only LINESTRINGs are accepted. */
+/*
+ * Only LINESTRINGs are accepted.
+ * @param width : offset distance.
+ * negative for right side offset.
+ * positive for left side offset.
+ * @return NULL on exception
+ */
extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve(const GEOSGeometry* g1,
- double width, int quadsegs, int joinStyle, double mitreLimit,
- int leftSide);
-extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve_r(
- GEOSContextHandle_t handle,
+ double width, int quadsegs, int joinStyle, double mitreLimit);
+extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve_r(GEOSContextHandle_t handle,
const GEOSGeometry* g1, double width, int quadsegs,
- int joinStyle, double mitreLimit, int leftSide);
+ int joinStyle, double mitreLimit);
/************************************************************************
@@ -570,8 +574,10 @@
extern GEOSGeometry GEOS_DLL *GEOSBoundary(const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2);
extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion(const GEOSGeometry* g1);
-/* @deprecated: use GEOSUnaryUnion instead */
+
+/* @deprecated in 3.3.0: use GEOSUnaryUnion instead */
extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded(const GEOSGeometry* g1);
+extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded_r(GEOSContextHandle_t handle, const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface(const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSGetCentroid(const GEOSGeometry* g);
@@ -596,7 +602,6 @@
const GEOSGeometry* g2);
extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion_r(GEOSContextHandle_t handle,
const GEOSGeometry* g);
-extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded_r(GEOSContextHandle_t handle, const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface_r(GEOSContextHandle_t handle,
const GEOSGeometry* g1);
extern GEOSGeometry GEOS_DLL *GEOSGetCentroid_r(GEOSContextHandle_t handle,
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2011-04-27 13:06:31 UTC (rev 3304)
+++ trunk/capi/geos_ts_c.cpp 2011-04-27 13:38:53 UTC (rev 3305)
@@ -122,6 +122,7 @@
using geos::operation::overlay::overlayOp;
using geos::operation::geounion::CascadedPolygonUnion;
using geos::operation::buffer::BufferParameters;
+using geos::operation::buffer::BufferBuilder;
using geos::util::IllegalArgumentException;
using geos::algorithm::distance::DiscreteHausdorffDistance;
@@ -1712,24 +1713,13 @@
}
Geometry *
-GEOSOffsetCurve_r(GEOSContextHandle_t extHandle, const Geometry *g1, double width, int quadsegs, int joinStyle, double mitreLimit, int leftSide)
+GEOSOffsetCurve_r(GEOSContextHandle_t extHandle, const Geometry *g1, double width, int quadsegs, int joinStyle, double mitreLimit)
{
- using geos::operation::buffer::BufferParameters;
- using geos::operation::buffer::BufferBuilder;
- using geos::operation::buffer::BufferOp;
- using geos::util::IllegalArgumentException;
+ if ( 0 == extHandle ) return NULL;
- if ( 0 == extHandle )
- {
- return NULL;
- }
-
GEOSContextHandleInternal_t *handle = 0;
handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
- if ( 0 == handle->initialized )
- {
- return NULL;
- }
+ if ( 0 == handle->initialized ) return NULL;
try
{
@@ -1746,7 +1736,11 @@
);
bp.setMitreLimit(mitreLimit);
- bool isLeftSide = leftSide == 0 ? false : true;
+ bool isLeftSide = true;
+ if ( width < 0 ) {
+ isLeftSide = false;
+ width = -width;
+ }
BufferBuilder bufBuilder (bp);
Geometry *g3 = bufBuilder.bufferLineSingleSided(g1, width, isLeftSide);
@@ -1764,11 +1758,47 @@
return NULL;
}
+/* @deprecated in 3.3.0 */
Geometry *
GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle, const Geometry *g1, double width, int quadsegs, int joinStyle, double mitreLimit, int leftSide)
{
- return GEOSOffsetCurve_r(extHandle, g1, width, quadsegs,
- joinStyle, mitreLimit, leftSide);
+ if ( 0 == extHandle ) return NULL;
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized ) return NULL;
+
+ try
+ {
+ BufferParameters bp;
+ bp.setEndCapStyle( BufferParameters::CAP_FLAT );
+ bp.setQuadrantSegments(quadsegs);
+
+ if ( joinStyle > BufferParameters::JOIN_BEVEL )
+ {
+ throw IllegalArgumentException("Invalid buffer join style");
+ }
+ bp.setJoinStyle(
+ static_cast<BufferParameters::JoinStyle>(joinStyle)
+ );
+ bp.setMitreLimit(mitreLimit);
+
+ bool isLeftSide = leftSide == 0 ? false : true;
+ BufferBuilder bufBuilder (bp);
+ Geometry *g3 = bufBuilder.bufferLineSingleSided(g1, width, isLeftSide);
+
+ return g3;
+ }
+ catch (const std::exception &e)
+ {
+ handle->ERROR_MESSAGE("%s", e.what());
+ }
+ catch (...)
+ {
+ handle->ERROR_MESSAGE("Unknown exception thrown");
+ }
+
+ return NULL;
}
Geometry *
Modified: trunk/tests/unit/capi/GEOSOffsetCurveTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSOffsetCurveTest.cpp 2011-04-27 13:06:31 UTC (rev 3304)
+++ trunk/tests/unit/capi/GEOSOffsetCurveTest.cpp 2011-04-27 13:38:53 UTC (rev 3305)
@@ -78,7 +78,7 @@
ensure( 0 != geom1_ );
- geom2_ = GEOSOffsetCurve(geom1_, 2, 2, GEOSBUF_JOIN_ROUND, 2, 1);
+ geom2_ = GEOSOffsetCurve(geom1_, 2, 0, GEOSBUF_JOIN_ROUND, 2);
ensure( 0 != geom2_ );
@@ -97,7 +97,7 @@
ensure( 0 != geom1_ );
- geom2_ = GEOSOffsetCurve(geom1_, 2, 2, GEOSBUF_JOIN_ROUND, 2, 0);
+ geom2_ = GEOSOffsetCurve(geom1_, -2, 0, GEOSBUF_JOIN_ROUND, 2);
ensure( 0 != geom2_ );
@@ -117,7 +117,7 @@
ensure( 0 != geom1_ );
- geom2_ = GEOSOffsetCurve(geom1_, 2, 1, GEOSBUF_JOIN_ROUND, 2, 0);
+ geom2_ = GEOSOffsetCurve(geom1_, -2, 1, GEOSBUF_JOIN_ROUND, 2);
ensure( 0 != geom2_ );
@@ -137,7 +137,7 @@
ensure( 0 != geom1_ );
- geom2_ = GEOSOffsetCurve(geom1_, 2, 1, GEOSBUF_JOIN_ROUND, 2, 1);
+ geom2_ = GEOSOffsetCurve(geom1_, 2, 1, GEOSBUF_JOIN_ROUND, 2);
ensure( 0 != geom2_ );
More information about the geos-commits
mailing list