[geos-commits] r2341 - in trunk/source: headers/geos/operation/buffer operation/buffer

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Apr 9 07:45:57 EDT 2009


Author: strk
Date: 2009-04-09 07:45:57 -0400 (Thu, 09 Apr 2009)
New Revision: 2341

Modified:
   trunk/source/headers/geos/operation/buffer/BufferBuilder.h
   trunk/source/headers/geos/operation/buffer/BufferOp.h
   trunk/source/headers/geos/operation/buffer/OffsetCurveBuilder.h
   trunk/source/operation/buffer/BufferBuilder.cpp
   trunk/source/operation/buffer/BufferOp.cpp
   trunk/source/operation/buffer/OffsetCurveBuilder.cpp
Log:
Sync BufferBuilder and BufferOp classes to JTS-1.9. Adapt OffsetCurveBuilder to use of BufferParameter (needs more work for JTS-sync).


Modified: trunk/source/headers/geos/operation/buffer/BufferBuilder.h
===================================================================
--- trunk/source/headers/geos/operation/buffer/BufferBuilder.h	2009-04-09 10:21:50 UTC (rev 2340)
+++ trunk/source/headers/geos/operation/buffer/BufferBuilder.h	2009-04-09 11:45:57 UTC (rev 2341)
@@ -11,6 +11,10 @@
  * by the Free Software Foundation. 
  * See the COPYING file for more information.
  *
+ **********************************************************************
+ *
+ * Last port: operation/buffer/BufferBuilder.java rev. 1.30 (JTS-1.9)
+ *
  **********************************************************************/
 
 #ifndef GEOS_OP_BUFFER_BUFFERBUILDER_H
@@ -84,10 +88,8 @@
 	 */
 	static int depthDelta(geomgraph::Label *label);
 
-	int quadrantSegments;
+	const BufferParameters& bufParams; 
 
-	int endCapStyle;
-
 	const geom::PrecisionModel* workingPrecisionModel;
 
 	algorithm::LineIntersector* li;
@@ -115,7 +117,7 @@
 	 * The function takes responsability of releasing the Edge parameter
 	 * memory when appropriate.
 	 */
-	void insertEdge(geomgraph::Edge *e);
+	void insertUniqueEdge(geomgraph::Edge *e);
 
 	void createSubgraphs(geomgraph::PlanarGraph *graph,
 			std::vector<BufferSubgraph*>& list);
@@ -156,11 +158,16 @@
 public:
 	/**
 	 * Creates a new BufferBuilder
+	 *
+	 * @param nBufParams buffer parameters, this object will
+	 *                   keep a reference to the passed parameters
+	 *                   so caller must make sure the object is
+	 *                   kept alive for the whole lifetime of
+	 *                   the buffer builder.
 	 */
-	BufferBuilder()
+	BufferBuilder(const BufferParameters& nBufParams)
 		:
-		quadrantSegments(OffsetCurveBuilder::DEFAULT_QUADRANT_SEGMENTS),
-		endCapStyle(BufferOp::CAP_ROUND),
+		bufParams(nBufParams),
 		workingPrecisionModel(NULL),
 		li(NULL),
 		intersectionAdder(NULL),
@@ -171,17 +178,7 @@
 
 	~BufferBuilder();
 
-	/**
-	 * Sets the number of segments used to approximate a angle fillet
-	 *
-	 * @param quadrantSegments the number of segments in a fillet for
-	 *  a quadrant
-	 */
-	void setQuadrantSegments(int nQuadrantSegments) {
-		quadrantSegments=nQuadrantSegments;
-	} 
 
-
 	/**
 	 * Sets the precision model to use during the curve computation
 	 * and noding,
@@ -205,10 +202,6 @@
 	 */
 	void setNoder(noding::Noder* newNoder) { workingNoder = newNoder; }
 
-	void setEndCapStyle(int nEndCapStyle) {
-		endCapStyle=nEndCapStyle;
-	}
-
 	geom::Geometry* buffer(const geom::Geometry *g, double distance);
 		// throw (GEOSException);
 

Modified: trunk/source/headers/geos/operation/buffer/BufferOp.h
===================================================================
--- trunk/source/headers/geos/operation/buffer/BufferOp.h	2009-04-09 10:21:50 UTC (rev 2340)
+++ trunk/source/headers/geos/operation/buffer/BufferOp.h	2009-04-09 11:45:57 UTC (rev 2341)
@@ -4,19 +4,26 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
  *
- * Copyright (C) 2006 Refractions Research Inc.
+ * Copyright (C) 2009  Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2005-2007 Refractions Research Inc.
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
  *
  * 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: operation/buffer/BufferOp.java rev. 1.43 (JTS-1.9)
+ *
  **********************************************************************/
 
 #ifndef GEOS_OP_BUFFER_BUFFEROP_H
 #define GEOS_OP_BUFFER_BUFFEROP_H
 
-#include <geos/operation/buffer/OffsetCurveBuilder.h> // for enum values 
+//#include <geos/operation/buffer/OffsetCurveBuilder.h> // for enum values 
+#include <geos/operation/buffer/BufferParameters.h> // for enum values 
 #include <geos/util/TopologyException.h> // for composition
 
 // Forward declarations
@@ -60,8 +67,6 @@
  * - CAP_SQUARE - end caps are squared off at the buffer distance
  *   beyond the line ends
  * 
- * Last port: operation/buffer/BufferOp.java rev. 1.31 (JTS-1.7)
- *
  */
 class BufferOp {
 
@@ -101,10 +106,10 @@
 
 	double distance;
 
-	int quadrantSegments;
+	//int quadrantSegments;
+	//int endCapStyle;
+	BufferParameters bufParams;
 
-	int endCapStyle;
-
 	geom::Geometry* resultGeometry;
 
 	void computeGeometry();
@@ -121,11 +126,16 @@
 
 	enum {
 		/// Specifies a round line buffer end cap style.
-		CAP_ROUND,
+		/// @deprecated use BufferParameters
+		CAP_ROUND = BufferParameters::CAP_ROUND,
+
 		/// Specifies a butt (or flat) line buffer end cap style.
-		CAP_BUTT,
+		/// @deprecated use BufferParameters
+		CAP_BUTT = BufferParameters::CAP_FLAT,
+
 		/// Specifies a square line buffer end cap style.
-		CAP_SQUARE
+		/// @deprecated use BufferParameters
+		CAP_SQUARE = BufferParameters::CAP_FLAT
 	};
 
 	/**
@@ -142,8 +152,8 @@
 	static geom::Geometry* bufferOp(const geom::Geometry *g,
 		double distance,
 		int quadrantSegments=
-			OffsetCurveBuilder::DEFAULT_QUADRANT_SEGMENTS,
-		int endCapStyle=BufferOp::CAP_ROUND);
+			BufferParameters::DEFAULT_QUADRANT_SEGMENTS,
+		int endCapStyle=BufferParameters::CAP_ROUND);
 
 	/**
 	 * Initializes a buffer computation for the given geometry
@@ -153,12 +163,29 @@
 	BufferOp(const geom::Geometry *g)
 		:
 		argGeom(g),
-		quadrantSegments(OffsetCurveBuilder::DEFAULT_QUADRANT_SEGMENTS),
-		endCapStyle(BufferOp::CAP_ROUND),
+		bufParams(),
 		resultGeometry(NULL)
-	{}
+	{
+	}
 
 	/**
+	 * Initializes a buffer computation for the given geometry
+	 * with the given set of parameters
+	 *
+	 * @param g the geometry to buffer
+	 * @param params the buffer parameters to use. This class will
+	 *               copy it to private memory.
+	 */
+	BufferOp(const geom::Geometry* g, const BufferParameters& params)
+		:
+		argGeom(g),
+		bufParams(params),
+		resultGeometry(NULL)
+	{
+	}
+
+
+	/**
 	 * Specifies the end cap style of the generated buffer.
 	 * The styles supported are CAP_ROUND, CAP_BUTT, and CAP_SQUARE.
 	 * The default is CAP_ROUND.
@@ -186,26 +213,22 @@
 	 */
 	geom::Geometry* getResultGeometry(double nDistance);
 
-	/**
-	 * Comutes the buffer for a geometry for a given buffer distance
-	 * and accuracy of approximation.
-	 *
-	 * @param g the geometry to buffer
-	 * @param distance the buffer distance
-	 * @param quadrantSegments the number of segments used to
-	 * approximate a quarter circle
-	 * @return the buffer of the input geometry
-	 *
-	 * @deprecated use setQuadrantSegments instead
-	 */
-	geom::Geometry* getResultGeometry(double nDistance, int nQuadrantSegments);
 };
 
 // BufferOp inlines
-void BufferOp::setQuadrantSegments(int q) { quadrantSegments=q; }
-void BufferOp::setEndCapStyle(int s) { endCapStyle=s; }
+void
+BufferOp::setQuadrantSegments(int q)
+{
+	bufParams.setQuadrantSegments(q);
+}
 
+void
+BufferOp::setEndCapStyle(int s)
+{
+	bufParams.setEndCapStyle((BufferParameters::EndCapStyle)s);
+}
 
+
 } // namespace geos::operation::buffer
 } // namespace geos::operation
 } // namespace geos

Modified: trunk/source/headers/geos/operation/buffer/OffsetCurveBuilder.h
===================================================================
--- trunk/source/headers/geos/operation/buffer/OffsetCurveBuilder.h	2009-04-09 10:21:50 UTC (rev 2340)
+++ trunk/source/headers/geos/operation/buffer/OffsetCurveBuilder.h	2009-04-09 11:45:57 UTC (rev 2341)
@@ -25,6 +25,7 @@
 #include <geos/algorithm/LineIntersector.h> // for composition
 #include <geos/geom/Coordinate.h> // for composition
 #include <geos/geom/LineSegment.h> // for composition
+#include <geos/operation/buffer/BufferParameters.h> // for composition
 
 // Forward declarations
 namespace geos {
@@ -70,13 +71,18 @@
 	 */
 	static const int DEFAULT_QUADRANT_SEGMENTS=8;
 
+	/*
+	 * @param nBufParams buffer parameters, this object will
+	 *                   keep a reference to the passed parameters
+	 *                   so caller must make sure the object is
+	 *                   kept alive for the whole lifetime of
+	 *                   the buffer builder.
+	 */
 	OffsetCurveBuilder(const geom::PrecisionModel *newPrecisionModel,
-			int quadrantSegments=DEFAULT_QUADRANT_SEGMENTS);
+			const BufferParameters& bufParams);
 
 	~OffsetCurveBuilder();
 
-	void setEndCapStyle(int newEndCapStyle);
-
 	/**
 	 * This method handles single points as well as lines.
 	 * Lines are assumed to <b>not</b> be closed (the function will not
@@ -135,10 +141,8 @@
 
 	const geom::PrecisionModel* precisionModel;
 
-	int endCapStyle;
+	const BufferParameters& bufParams; 
 
-	//int joinStyle;
-
 	geom::Coordinate s0, s1, s2;
 
 	geom::LineSegment seg0;
@@ -215,12 +219,6 @@
 	std::vector<OffsetCurveVertexList*> vertexLists;
 };
 
-// INLINES
-inline void OffsetCurveBuilder::setEndCapStyle(int newEndCapStyle) {
-	endCapStyle=newEndCapStyle;
-}
-
-
 } // namespace geos::operation::buffer
 } // namespace geos::operation
 } // namespace geos

Modified: trunk/source/operation/buffer/BufferBuilder.cpp
===================================================================
--- trunk/source/operation/buffer/BufferBuilder.cpp	2009-04-09 10:21:50 UTC (rev 2340)
+++ trunk/source/operation/buffer/BufferBuilder.cpp	2009-04-09 11:45:57 UTC (rev 2341)
@@ -14,7 +14,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/buffer/BufferBuilder.java rev. 1.23 (JTS-1.7)
+ * Last port: operation/buffer/BufferBuilder.java rev. 1.30 (JTS-1.9)
  *
  **********************************************************************/
 
@@ -113,8 +113,7 @@
 	// factory must be the same as the one used by the input
 	geomFact=g->getFactory();
 
-	OffsetCurveBuilder curveBuilder(precisionModel, quadrantSegments);
-	curveBuilder.setEndCapStyle(endCapStyle);
+	OffsetCurveBuilder curveBuilder(precisionModel, bufParams);
 	OffsetCurveSetBuilder curveSetBuilder(*g, distance, curveBuilder);
 
 	std::vector<SegmentString*>& bufferSegStrList=curveSetBuilder.getCurves();
@@ -284,7 +283,7 @@
 		Edge* edge = new Edge(cs, new Label(*oldLabel));
 
 		// will take care of the Edge ownership
-		insertEdge(edge);
+		insertUniqueEdge(edge);
 	}
 
 	if ( nodedSegStrings != &bufferSegStrList )
@@ -297,7 +296,7 @@
 
 /*private*/
 void
-BufferBuilder::insertEdge(Edge *e)
+BufferBuilder::insertUniqueEdge(Edge *e)
 {
 	//<FIX> MD 8 Oct 03  speed up identical edge lookup
 	// fast lookup

Modified: trunk/source/operation/buffer/BufferOp.cpp
===================================================================
--- trunk/source/operation/buffer/BufferOp.cpp	2009-04-09 10:21:50 UTC (rev 2340)
+++ trunk/source/operation/buffer/BufferOp.cpp	2009-04-09 11:45:57 UTC (rev 2341)
@@ -4,6 +4,7 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
  *
+ * Copyright (C) 2009  Sandro Santilli <strk at keybit.net>
  * Copyright (C) 2005-2007 Refractions Research Inc.
  * Copyright (C) 2001-2002 Vivid Solutions Inc.
  *
@@ -14,7 +15,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/buffer/BufferOp.java rev. 1.35 (JTS-1.7)
+ * Last port: operation/buffer/BufferOp.java rev. 1.43 (JTS-1.9)
  *
  **********************************************************************/
 
@@ -98,16 +99,6 @@
 	return resultGeometry;
 }
 
-/*public*/
-Geometry*
-BufferOp::getResultGeometry(double nDistance, int nQuadrantSegments)
-{
-	distance=nDistance;
-	setQuadrantSegments(nQuadrantSegments);
-	computeGeometry();
-	return resultGeometry;
-}
-
 /*private*/
 void
 BufferOp::computeGeometry()
@@ -163,9 +154,7 @@
 void
 BufferOp::bufferOriginalPrecision()
 {
-	BufferBuilder bufBuilder;
-	bufBuilder.setQuadrantSegments(quadrantSegments);
-	bufBuilder.setEndCapStyle(endCapStyle);
+	BufferBuilder bufBuilder(bufParams);
 
 	//std::cerr<<"computing with original precision"<<std::endl;
 	try
@@ -221,14 +210,11 @@
 
 	ScaledNoder noder(inoder, fixedPM.getScale());
 
-	BufferBuilder bufBuilder;
+	BufferBuilder bufBuilder(bufParams);
 	bufBuilder.setWorkingPrecisionModel(&fixedPM);
 
 	bufBuilder.setNoder(&noder);
 
-	bufBuilder.setQuadrantSegments(quadrantSegments);
-	bufBuilder.setEndCapStyle(endCapStyle);
-
 	// this may throw an exception, if robustness errors are encountered
 	resultGeometry=bufBuilder.buffer(argGeom, distance);
 }

Modified: trunk/source/operation/buffer/OffsetCurveBuilder.cpp
===================================================================
--- trunk/source/operation/buffer/OffsetCurveBuilder.cpp	2009-04-09 10:21:50 UTC (rev 2340)
+++ trunk/source/operation/buffer/OffsetCurveBuilder.cpp	2009-04-09 11:45:57 UTC (rev 2341)
@@ -25,6 +25,7 @@
 #include <geos/algorithm/CGAlgorithms.h>
 #include <geos/operation/buffer/OffsetCurveBuilder.h>
 #include <geos/operation/buffer/BufferOp.h>
+#include <geos/operation/buffer/BufferParameters.h>
 #include <geos/geomgraph/Position.h>
 #include <geos/geom/CoordinateArraySequence.h>
 #include <geos/geom/CoordinateSequence.h>
@@ -53,14 +54,14 @@
 
 /*public*/
 OffsetCurveBuilder::OffsetCurveBuilder(const PrecisionModel *newPrecisionModel,
-		int quadrantSegments)
+		const BufferParameters& nBufParams)
 		:
 		li(),
 		maxCurveSegmentError(0.0),
 		vertexList(new OffsetCurveVertexList()),
 		distance(0.0),
 		precisionModel(newPrecisionModel),
-		endCapStyle(BufferOp::CAP_ROUND),
+		bufParams(nBufParams),
 		s0(),
 		s1(),
 		s2(),
@@ -71,8 +72,7 @@
 		side(0),
 		vertexLists()
 {
-	int limitedQuadSegs=quadrantSegments<1 ? 1 : quadrantSegments;
-	filletAngleQuantum=PI / 2.0 / limitedQuadSegs;
+	filletAngleQuantum=PI / 2.0 / bufParams.getQuadrantSegments();
 }
 
 /*public*/
@@ -94,14 +94,17 @@
 	init(distance);
 
 	if (inputPts->getSize() < 2) {
-		switch (endCapStyle) {
-			case BufferOp::CAP_ROUND:
+		switch (bufParams.getEndCapStyle()) {
+			case BufferParameters::CAP_ROUND:
 				addCircle(inputPts->getAt(0), distance);
 				break;
-			case BufferOp::CAP_SQUARE:
+			case BufferParameters::CAP_SQUARE:
 				addSquare(inputPts->getAt(0), distance);
 				break;
-			// default is for buffer to be empty (e.g. for a butt line cap);
+			default:
+				// default is for buffer to be empty
+				// (e.g. for a butt line cap);
+				break;
 		}
 	} else {
 		computeLineBufferCurve(*inputPts);
@@ -325,19 +328,19 @@
 	double dx=p1.x-p0.x;
 	double dy=p1.y-p0.y;
 	double angle=atan2(dy, dx);
-	switch (endCapStyle) {
-		case BufferOp::CAP_ROUND:
+	switch (bufParams.getEndCapStyle()) {
+		case BufferParameters::CAP_ROUND:
 			// add offset seg points with a fillet between them
 			vertexList->addPt(offsetL.p1);
 			addFillet(p1, angle+PI/2.0, angle-PI/2.0, CGAlgorithms::CLOCKWISE, distance);
 			vertexList->addPt(offsetR.p1);
 			break;
-		case BufferOp::CAP_BUTT:
+		case BufferParameters::CAP_FLAT:
 			// only offset segment points are added
 			vertexList->addPt(offsetL.p1);
 			vertexList->addPt(offsetR.p1);
 			break;
-		case BufferOp::CAP_SQUARE:
+		case BufferParameters::CAP_SQUARE:
 			// add a square defined by extensions of the offset segment endpoints
 			Coordinate squareCapSideOffset;
 			squareCapSideOffset.x=fabs(distance)*cos(angle);



More information about the geos-commits mailing list