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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
//
// Test Suite for C-API GEOSDensify
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
#include "capi_test_utils.h"
namespace tut {
//
// Test Group
//
struct test_capigeosdensify_data : public capitest::utility
{
void testDensify(
const std::string &wkt_input,
const std::string &wkt_output,
double tolerance)
{
int srid = 3857;
input_ = fromWKT(wkt_input.c_str());
GEOSSetSRID(input_, srid);
expected_ = fromWKT(wkt_output.c_str());
result_ = GEOSDensify(input_, tolerance);
ensure("result not NULL", result_ != nullptr);
ensure_geometry_equals_identical(result_, expected_);
ensure_equals("result SRID == expected SRID", GEOSGetSRID(result_), srid);
}
};
typedef test_group<test_capigeosdensify_data> group;
typedef group::object object;
group test_capigeosdensify_group("capi::GEOSDensify");
//
// Test Cases
//
// Densify with a tolerance greater than or equal to length of all edges.
// Result should match inputs.
template <>
template <>
void object::test<1>()
{
testDensify(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))",
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))",
10.0
);
}
// Densify with a tolerance that evenly subdivides all outer and inner edges.
template <>
template <>
void object::test<2>()
{
testDensify(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 7, 7 7, 7 1, 1 1))",
"POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0), (1 1, 1 4, 1 7, 4 7, 7 7, 7 4, 7 1, 4 1, 1 1))",
5.0
);
}
// Densify a LINESTRING
template <>
template <>
void object::test<3>()
{
testDensify(
"LINESTRING (0 0, 0 6 )",
"LINESTRING (0 0, 0 3, 0 6)",
3.0
);
}
// Ensure that tolerance results in the right number of subdivisions
// ceil(6 / 2.9999999) = 3 new segments; 2 new vertices
template <>
template <>
void object::test<4>()
{
testDensify(
"LINESTRING (0 0, 0 6 )",
"LINESTRING (0 0, 0 2, 0 4, 0 6)",
2.9999999
);
}
// Densify a LINEARRING
template <>
template <>
void object::test<5>()
{
testDensify(
"LINEARRING (0 0, 0 6, 6 6, 0 0)",
"LINEARRING (0 0, 0 3, 0 6, 3 6, 6 6, 4 4, 2 2, 0 0)",
3.0
);
}
// Densify a POINT
// Results should match inputs
template <>
template <>
void object::test<6>()
{
testDensify(
"POINT (0 0)",
"POINT (0 0)",
3.0
);
}
// Densify a MULTIPOINT
// Results should match inputs
template <>
template <>
void object::test<7>()
{
testDensify(
"MULTIPOINT ((0 0), (10 10))",
"MULTIPOINT ((0 0), (10 10))",
3.0
);
}
// Densify an empty polygon
// Results should match inputs
template <>
template <>
void object::test<8>()
{
testDensify(
"POLYGON EMPTY",
"POLYGON EMPTY",
3.0
);
}
// Densify with an invalid tolerances should fail
// Note: this raises "IllegalArgumentException: Tolerance must be positive:
template <>
template <>
void object::test<9>()
{
input_ = fromWKT("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))");
result_ = GEOSDensify(input_, 0.0);
ensure("result expected to be NULL", result_ == nullptr);
result_ = GEOSDensify(input_, -1.0);
ensure("result expected to be NULL", result_ == nullptr);
}
template<>
template<>
void object::test<10>()
{
input_ = fromWKT("CIRCULARSTRING (0 0, 1 1, 2 0)");
ensure(input_);
result_ = GEOSDensify(input_, 0.1);
ensure("curved geometries not supported", result_ == nullptr);
}
// Densify a LINESTRING Z, check that Z gets interpolated
template <>
template <>
void object::test<11>()
{
testDensify(
"LINESTRING Z (0 0 0, 0 6 2)",
"LINESTRING Z (0 0 0, 0 3 1, 0 6 2)",
3.0
);
}
// Densify a LINEARRING Z
template <>
template <>
void object::test<12>()
{
testDensify(
"LINEARRING Z (0 0 0, 0 6 2, 6 6 12, 0 0 0)",
"LINEARRING Z (0 0 0, 0 3 1, 0 6 2, 3 6 7, 6 6 12, 4 4 8, 2 2 4, 0 0 0)",
3.0
);
}
// Densify a POLYGON Z
template <>
template <>
void object::test<13>()
{
testDensify(
"POLYGON Z ((0 0 0, 10 0 2, 10 10 10, 0 10 2, 0 0 0), (1 1 0, 1 7 0, 7 7 0, 7 1 0, 1 1 0))",
"POLYGON Z ((0 0 0, 5 0 1, 10 0 2, 10 5 6, 10 10 10, 5 10 6, 0 10 2, 0 5 1, 0 0 0), (1 1 0, 1 4 0, 1 7 0, 4 7 0, 7 7 0, 7 4 0, 7 1 0, 4 1 0, 1 1 0))",
5.0
);
}
} // namespace tut
|