1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
//
// Test Suite for geos::coverage::TPVWSimplifier class.
#include <tut/tut.hpp>
#include <utility.h>
// geos
#include <geos/coverage/TPVWSimplifier.h>
using namespace geos::geom;
using geos::coverage::TPVWSimplifier;
namespace tut {
//
// Test Group
//
// Common data used by all tests
struct test_tpvwsimplifier_data {
WKTReader r;
WKTWriter w;
test_tpvwsimplifier_data() {
}
void
checkNoop(
const std::string& wkt,
double tolerance)
{
std::unique_ptr<Geometry> geom = r.read(wkt);
const MultiLineString* mls = static_cast<const MultiLineString*>(geom.get());
std::unique_ptr<Geometry> actual = TPVWSimplifier::simplify(mls, tolerance);
ensure_equals_geometry(actual.get(), geom.get());
}
void
checkSimplify(
const std::string& wkt,
double tolerance,
const std::string& wktExpected)
{
auto mls = r.read<MultiLineString>(wkt);
std::unique_ptr<Geometry> actual = TPVWSimplifier::simplify(mls.get(), tolerance);
std::unique_ptr<Geometry> expected = r.read(wktExpected);
ensure_equals_geometry(actual.get(), expected.get());
}
void
checkSimplify(
const std::string& wkt,
const std::vector<std::size_t> freeRingIndex,
double tolerance,
const std::string& wktExpected)
{
checkSimplify(wkt, freeRingIndex, "", tolerance, wktExpected);
}
void
checkSimplify(
const std::string& wkt,
const std::vector<std::size_t> freeRingIndex,
const std::string& wktConstraints,
double tolerance,
const std::string& wktExpected)
{
auto lines = r.read<MultiLineString>(wkt);
std::vector<bool> freeRings(lines->getNumGeometries(), false);
for (std::size_t index : freeRingIndex) {
freeRings[index] = true;
}
std::unique_ptr<MultiLineString> constraints(nullptr);
if (wktConstraints.length() > 0) {
constraints = r.read<MultiLineString>(wktConstraints);
}
std::unique_ptr<Geometry> actual = TPVWSimplifier::simplify(lines.get(), freeRings, constraints.get(), tolerance);
std::unique_ptr<Geometry> expected = r.read(wktExpected);
// std::cout << "-- actual" << std::endl;
// std::cout << w.write(*actual) << std::endl;
// std::cout << "-- expected" << std::endl;
// std::cout << w.write(*expected) << std::endl;
ensure_equals_geometry(actual.get(), expected.get());
}
};
typedef test_group<test_tpvwsimplifier_data> group;
typedef group::object object;
group test_tpvwsimplifier_data("geos::coverage::TPVWSimplifier");
// testSimpleNoop
template<>
template<>
void object::test<1> ()
{
checkNoop(
"MULTILINESTRING ((9 9, 3 9, 1 4, 4 1, 9 1), (9 1, 2 4, 9 9))",
2);
}
// testSimple
template<>
template<>
void object::test<2> ()
{
checkSimplify(
"MULTILINESTRING ((9 9, 3 9, 1 4, 4 1, 9 1), (9 1, 6 3, 2 4, 5 7, 9 9))",
2,
"MULTILINESTRING ((9 9, 3 9, 1 4, 4 1, 9 1), (9 1, 2 4, 9 9))"
);
}
// testFreeRing
template<>
template<>
void object::test<3> ()
{
checkSimplify(
"MULTILINESTRING ((1 9, 9 9, 9 1), (1 9, 1 1, 9 1), (7 5, 8 8, 2 8, 2 2, 8 2, 7 5))",
{ 2 },
2,
"MULTILINESTRING ((1 9, 1 1, 9 1), (1 9, 9 9, 9 1), (8 8, 2 8, 2 2, 8 2, 8 8))"
);
}
// testNoFreeRing
template<>
template<>
void object::test<4> ()
{
checkSimplify(
"MULTILINESTRING ((1 9, 9 9, 9 1), (1 9, 1 1, 9 1), (5 5, 4 8, 2 8, 2 2, 4 2, 5 5), (5 5, 6 8, 8 8, 8 2, 6 2, 5 5))",
{},
2,
"MULTILINESTRING ((1 9, 1 1, 9 1), (1 9, 9 9, 9 1), (5 5, 2 2, 2 8, 5 5), (5 5, 8 2, 8 8, 5 5))"
);
}
// testConstraint
template<>
template<>
void object::test<5> ()
{
checkSimplify(
"MULTILINESTRING ((6 8, 2 8, 2.1 5, 2 2, 6 2, 5.9 5, 6 8))",
{},
"MULTILINESTRING ((1 9, 9 9, 6 5, 9 1), (1 9, 1 1, 9 1))",
1,
"MULTILINESTRING ((6 8, 2 8, 2 2, 6 2, 5.9 5, 6 8))"
);
}
} // namespace tut
|