[geos-commits] r3491 - trunk/tests/unit/simplify
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Sep 28 13:23:17 EDT 2011
Author: mloskot
Date: 2011-09-28 10:23:17 -0700 (Wed, 28 Sep 2011)
New Revision: 3491
Modified:
trunk/tests/unit/simplify/DouglasPeuckerSimplifierTest.cpp
Log:
* Added interesting test<11> case to Douglas-Peucker unit
* Visual C++ build on Windows x86-32 is all green and happy throwing ok:737
Modified: trunk/tests/unit/simplify/DouglasPeuckerSimplifierTest.cpp
===================================================================
--- trunk/tests/unit/simplify/DouglasPeuckerSimplifierTest.cpp 2011-09-27 16:02:42 UTC (rev 3490)
+++ trunk/tests/unit/simplify/DouglasPeuckerSimplifierTest.cpp 2011-09-28 17:23:17 UTC (rev 3491)
@@ -4,10 +4,14 @@
#include <tut.hpp>
// geos
#include <geos/io/WKTReader.h>
+#include <geos/io/WKTWriter.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Geometry.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequenceFilter.h>
#include <geos/simplify/DouglasPeuckerSimplifier.h>
+#include <geos/util.h>
// std
#include <string>
#include <memory>
@@ -26,12 +30,13 @@
geos::geom::PrecisionModel pm;
geos::geom::GeometryFactory gf;
geos::io::WKTReader wktreader;
+ geos::io::WKTWriter wktwriter;
typedef geos::geom::Geometry::AutoPtr GeomPtr;
test_dpsimp_data()
:
- pm(1.0),
+ pm(geos::geom::PrecisionModel::FLOATING),
gf(&pm),
wktreader(&gf)
{}
@@ -268,5 +273,67 @@
ensure( simplified->equalsExact(g.get()) );
}
+ // 11 - A kind of reversed simplification
+ template<>
+ template<>
+ void object::test<11>()
+ {
+ using namespace geos::geom;
+
+ std::string wkt("MULTIPOLYGON(((0.561648 1,1 1,1 0,0.468083 0,0.52758 0.00800554,0.599683 0.0280924, 0.601611 0.265374, \
+ 0.622693 0.316765,0.69507 0.357497,0.695623 0.429711,0.655111 0.502298, 0.696467 0.543147,0.840712 0.593546, \
+ 0.882583 0.66546,0.852357 0.748213,0.84264 0.789567,0 .832667 0.841202,0.832667 0.841202,0.740538 0.873004, \
+ 0.617349 0.905045,0.566576 0.977697,0.561648 1)),((0 0.801979,0.0308575 0.786234,0.0705513 0.631135, \
+ 0.141616 0.527248,0.233985 0.505872,0.264777 0.526263,0.336631 0.505009,0.356603 0.422321,0.355803 0.350038, \
+ 0.375252 0.205364,0.415206 0.0709182,0.45479 0,0 0,0 0,0 0.801979)))");
+
+ GeomPtr g(wktreader.read(wkt));
+ std::size_t const gN = g->getNumPoints();
+ ensure_equals(gN, std::size_t(37));
+
+ // 1) Simplify with 1/2048
+ double const d1 = 1/2048.0;
+ GeomPtr simplified1 = DouglasPeuckerSimplifier::simplify(g.get(), d1);
+ ensure(simplified1->isValid());
+ ensure(simplified1->equals(g.get()));
+ std::size_t const simplifiedN1 = simplified1->getNumPoints();
+ ensure_equals(simplifiedN1, std::size_t(36));
+ //std::string const simplifiedWkd = wktwriter.write(simplified1.get());
+
+ // 2) Multiply points by 2047
+ struct Multiplier : public CoordinateSequenceFilter
+ {
+ double f;
+ Multiplier(double f) : f(f) {}
+ void filter_rw(CoordinateSequence& seq, std::size_t i)
+ {
+ seq.setOrdinate(i, CoordinateSequence::X, seq[i].x * f);
+ seq.setOrdinate(i, CoordinateSequence::Y, seq[i].y * f);
+ }
+ void filter_ro(const CoordinateSequence& seq, std::size_t i)
+ {
+ ::geos::ignore_unused_variable_warning(seq);
+ ::geos::ignore_unused_variable_warning(i);
+ }
+ bool isDone() const { return false; }
+ bool isGeometryChanged() const { return true; }
+ };
+
+ Multiplier m(2047);
+ g->apply_rw(m);
+ std::size_t const multipliedN = g->getNumPoints();
+ ensure_equals(multipliedN, std::size_t(37));
+ //std::string const multipliedWkt = wktwriter.write(g.get());
+
+ // 3) Simplify with 1.0
+ double const d2 = 1.0;
+ GeomPtr simplified2 = DouglasPeuckerSimplifier::simplify(g.get(), d2);
+ ensure(simplified2->isValid());
+ ensure(simplified2->equals(g.get()));
+ std::size_t const simplifiedN2 = simplified2->getNumPoints();
+ ensure_equals(simplifiedN2, std::size_t(36));
+ //std::string const simplifiedWkt2 = wktwriter.write(simplified2.get());
+ }
+
} // namespace tut
More information about the geos-commits
mailing list