[geos-commits] r3817 - in trunk: src/operation/buffer tests/unit tests/unit/operation/buffer
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue Jun 11 07:19:38 PDT 2013
Author: mloskot
Date: 2013-06-11 07:19:38 -0700 (Tue, 11 Jun 2013)
New Revision: 3817
Added:
trunk/tests/unit/operation/buffer/BufferBuilderTest.cpp
Modified:
trunk/src/operation/buffer/OffsetCurveBuilder.cpp
trunk/tests/unit/Makefile.am
Log:
* Fix bug in OffsetCurveBuilder case for right-side offset curve used left-side flag to initialise the side segments.
* Corresponding test case attached.
Modified: trunk/src/operation/buffer/OffsetCurveBuilder.cpp
===================================================================
--- trunk/src/operation/buffer/OffsetCurveBuilder.cpp 2013-06-11 12:42:27 UTC (rev 3816)
+++ trunk/src/operation/buffer/OffsetCurveBuilder.cpp 2013-06-11 14:19:38 UTC (rev 3817)
@@ -145,7 +145,7 @@
const CoordinateSequence& simp2 = *simp2_;
int n2 = simp2.size() - 1;
- segGen->initSideSegments(simp2[n2], simp2[n2-1], Position::LEFT);
+ segGen->initSideSegments(simp2[n2], simp2[n2-1], Position::RIGHT);
segGen->addFirstSegment();
for (int i = n2-2; i >= 0; --i) {
segGen->addNextSegment(simp2[i], true);
Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am 2013-06-11 12:42:27 UTC (rev 3816)
+++ trunk/tests/unit/Makefile.am 2013-06-11 14:19:38 UTC (rev 3817)
@@ -80,6 +80,7 @@
noding/SegmentPointComparatorTest.cpp \
noding/snapround/HotPixelTest.cpp \
noding/snapround/MCIndexSnapRounderTest.cpp \
+ operation/buffer/BufferBuilderTest.cpp \
operation/buffer/BufferOpTest.cpp \
operation/buffer/BufferParametersTest.cpp \
operation/distance/DistanceOpTest.cpp \
Added: trunk/tests/unit/operation/buffer/BufferBuilderTest.cpp
===================================================================
--- trunk/tests/unit/operation/buffer/BufferBuilderTest.cpp (rev 0)
+++ trunk/tests/unit/operation/buffer/BufferBuilderTest.cpp 2013-06-11 14:19:38 UTC (rev 3817)
@@ -0,0 +1,119 @@
+//
+// Test Suite for geos::operation::buffer::BufferBuilder class.
+
+// tut
+#include <tut.hpp>
+// geos
+#include <geos/operation/buffer/BufferBuilder.h>
+#include <geos/operation/buffer/BufferParameters.h>
+#include <geos/platform.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/Geometry.h>
+#include <geos/algorithm/PointLocator.h>
+#include <geos/io/WKTReader.h>
+#include <geos/geom/CoordinateSequence.h>
+// std
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used by tests
+ struct test_bufferbuilder_data
+ {
+ geos::geom::GeometryFactory gf;
+ geos::io::WKTReader wktreader;
+ int const default_quadrant_segments;
+
+ typedef geos::geom::Geometry::AutoPtr GeomPtr;
+ typedef std::auto_ptr<geos::geom::CoordinateSequence> CSPtr;
+
+ test_bufferbuilder_data()
+ : gf(), wktreader(&gf), default_quadrant_segments(geos::operation::buffer::BufferParameters::DEFAULT_QUADRANT_SEGMENTS)
+ {
+ ensure_equals(default_quadrant_segments, int(8));
+ }
+ private:
+ // noncopyable
+ test_bufferbuilder_data(test_bufferbuilder_data const& other);
+ test_bufferbuilder_data& operator=(test_bufferbuilder_data const& rhs);
+ };
+
+ typedef test_group<test_bufferbuilder_data> group;
+ typedef group::object object;
+
+ group test_bufferbuilder_group("geos::operation::buffer::BufferBuilder");
+
+ //
+ // Test Cases
+ //
+
+ // Left-side offset curve
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ using geos::operation::buffer::BufferBuilder;
+ using geos::operation::buffer::BufferParameters;
+
+ std::string wkt0("LINESTRING ("
+ "665.7317504882812500 133.0762634277343700,"
+ "1774.4752197265625000 19.9391822814941410,"
+ "756.2413940429687500 466.8306579589843700,"
+ "626.1337890625000000 1898.0147705078125000,"
+ "433.8007202148437500 404.6052856445312500)");
+ GeomPtr g0(wktreader.read(wkt0));
+ double const distance = 57.164000837203;
+ bool const leftSide = true;
+
+ BufferParameters params;
+ params.setJoinStyle(BufferParameters::JOIN_MITRE);
+ params.setMitreLimit(5.57F); // somewhere between 5.5 and 5.6
+ params.setSingleSided(true);
+ BufferBuilder builder(params);
+ GeomPtr gBuffer(builder.bufferLineSingleSided(g0.get(), distance, leftSide ));
+
+ ensure_equals(gBuffer->getGeometryTypeId(), geos::geom::GEOS_LINESTRING);
+ // Left-side offset curve expected with 5 vertices
+ ensure_equals(gBuffer->getNumPoints(), std::size_t(5));
+ }
+
+ // Right-side offset curve
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ using geos::operation::buffer::BufferBuilder;
+ using geos::operation::buffer::BufferParameters;
+
+ std::string wkt0("LINESTRING ("
+ "665.7317504882812500 133.0762634277343700,"
+ "1774.4752197265625000 19.9391822814941410,"
+ "756.2413940429687500 466.8306579589843700,"
+ "626.1337890625000000 1898.0147705078125000,"
+ "433.8007202148437500 404.6052856445312500)");
+ GeomPtr g0(wktreader.read(wkt0));
+
+ double const distance = 57.164000837203;
+ bool const leftSide = false;
+
+ BufferParameters params;
+ params.setJoinStyle(BufferParameters::JOIN_MITRE);
+ params.setMitreLimit(5.57F); // somewhere between 5.5 and 5.6
+ params.setSingleSided(true);
+ BufferBuilder builder(params);
+ GeomPtr gBuffer(builder.bufferLineSingleSided(g0.get(), distance, leftSide));
+
+ ensure_equals(gBuffer->getGeometryTypeId(), geos::geom::GEOS_LINESTRING);
+ // Left-side offset curve expected with 5 vertices
+ ensure_equals(gBuffer->getNumPoints(), std::size_t(5));
+ }
+
+} // namespace tut
+
More information about the geos-commits
mailing list