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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
//
// Test Suite for C-API GEOSOffsetCurve
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
// std
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "capi_test_utils.h"
namespace tut {
//
// Test Group
//
// Common data used in test cases.
struct test_capioffsetcurve_data : public capitest::utility {
test_capioffsetcurve_data() {
}
void debugOutput (const char* label, GEOSGeometry* geom)
{
if (geom) {
char* wkt_c = GEOSWKTWriter_write(wktw_, geom);
printf("%s: %s\n", label, wkt_c);
if (wkt_c) GEOSFree(wkt_c);
}
else {
printf("%s: NULL\n", label);
}
}
void checkOffset(
const char* wkt, const char* expected,
double width, int quadSegs, int joinStyle, double mitreLimit,
double checkTolerance)
{
static int debug = 0;
// input
geom1_ = GEOSGeomFromWKT(wkt);
ensure(nullptr != geom1_);
if (debug) debugOutput("Input", geom1_);
// result
geom2_ = GEOSOffsetCurve(geom1_, width, quadSegs, joinStyle, mitreLimit);
ensure(nullptr != geom2_);
if (debug) debugOutput("Result", geom2_);
// expected
if (expected) {
geom3_ = GEOSGeomFromWKT(expected);
if (debug) debugOutput("Expected", geom3_);
ensure(nullptr != geom3_);
ensure_geometry_equals(geom2_, geom3_, checkTolerance);
}
}
};
typedef test_group<test_capioffsetcurve_data> group;
typedef group::object object;
group test_capioffsetcurve_group("capi::GEOSOffsetCurve");
//
// Test Cases
//
// Straight, left
template<>
template<>
void object::test<1>()
{
checkOffset(
"LINESTRING(0 0, 10 0)",
"LINESTRING (0 2, 10 2)",
2, 0, GEOSBUF_JOIN_ROUND, 2,
0.000001
);
}
// Straight, right
template<>
template<>
void object::test<2>()
{
checkOffset(
"LINESTRING(0 0, 10 0)",
"LINESTRING (10 -2, 0 -2)",
-2, 0, GEOSBUF_JOIN_ROUND, 2,
0.000001
);
}
// Outside curve
template<>
template<>
void object::test<3>()
{
checkOffset(
"LINESTRING(0 0, 10 0, 10 10)",
"LINESTRING (0 -2, 10 -2, 10.3901806 -1.9615705, 10.76536686 -1.8477590, 11.11114046 -1.66293922, 11.41421356 -1.41421356, 11.66293922 -1.11114046, 11.84775906 -0.76536686, 11.96157056 -0.3901806, 12 0, 12 10)",
-2, 1, GEOSBUF_JOIN_ROUND, 2,
0.000001
);
}
// Inside curve
template<>
template<>
void object::test<4>()
{
checkOffset(
"LINESTRING(0 0, 10 0, 10 10)",
"LINESTRING (0 2, 8 2, 8 10)",
2, 1, GEOSBUF_JOIN_ROUND, 2,
0.000001
);
}
// See http://trac.osgeo.org/postgis/ticket/413
template<>
template<>
void object::test<5>()
{
checkOffset(
"LINESTRING(33282908 6005055,33282900 6005050,33282892 6005042,33282876 6005007,33282863 6004982,33282866 6004971,33282876 6004975,33282967 6005018,33282999 6005031)",
// Old algorithm
// "LINESTRING EMPTY",
"LINESTRING (33282951.601378817 6005059.236579252, 33282982.439409934 6005071.764529393)",
44, 1, GEOSBUF_JOIN_MITRE, 1,
0.000001
);
}
// 0 distance
// See http://trac.osgeo.org/postgis/ticket/454
template<>
template<>
void object::test<6>()
{
checkOffset(
"LINESTRING(0 0, 10 0)",
"LINESTRING (0 0, 10 0)",
0, 0, GEOSBUF_JOIN_ROUND, 2,
0.000001
);
}
// left-side and right-side curve
// See http://trac.osgeo.org/postgis/ticket/633
template<>
template<>
void object::test<7>()
{
const char* wkt0 = "LINESTRING ("
"665.7317504882812500 133.0762634277343700,"
"1774.4752197265625000 19.9391822814941410,"
"756.2413940429687500 466.8306579589843700,"
"626.1337890625000000 1898.0147705078125000,"
"433.8007202148437500 404.6052856445312500)";
double width = 57.164000837203;
// left-sided
checkOffset(
wkt0,
NULL,
width, 8, GEOSBUF_JOIN_MITRE, 5.57,
0.000001
);
ensure(GEOSGeomGetNumPoints(geom2_) >= GEOSGeomGetNumPoints(geom1_));
}
// left-side and right-side curve
// See http://trac.osgeo.org/postgis/ticket/633
template<>
template<>
void object::test<8>()
{
const char* wkt0 = "LINESTRING ("
"665.7317504882812500 133.0762634277343700,"
"1774.4752197265625000 19.9391822814941410,"
"756.2413940429687500 466.8306579589843700,"
"626.1337890625000000 1898.0147705078125000,"
"433.8007202148437500 404.6052856445312500)";
double width = 57.164000837203;
// right-sided
checkOffset(
wkt0,
NULL,
-1 * width, 8, GEOSBUF_JOIN_MITRE, 5.57,
0.000001
);
ensure(GEOSGeomGetNumPoints(geom2_) >= GEOSGeomGetNumPoints(geom1_));
}
// Test duplicated inner vertex in input
// See http://trac.osgeo.org/postgis/ticket/602
template<>
template<>
void object::test<9>()
{
checkOffset(
"LINESTRING(0 0,0 10,0 10,10 10)",
"LINESTRING (10 9, 1 9, 1 0)",
-1, 8, GEOSBUF_JOIN_ROUND, 0,
0.000001
);
}
// Test duplicated final vertex in input
// See http://trac.osgeo.org/postgis/ticket/602
template<>
template<>
void object::test<10>()
{
checkOffset(
"LINESTRING(0 0,0 10,0 10)",
"LINESTRING (1 10, 1 0)",
-1, 8, GEOSBUF_JOIN_ROUND, 0,
0.000001
);
}
// Test only duplicated vertex in input
// See http://trac.osgeo.org/postgis/ticket/602
template<>
template<>
void object::test<11>()
{
checkOffset(
"LINESTRING(0 10, 0 10, 0 10)",
"LINESTRING EMPTY",
-1, 8, GEOSBUF_JOIN_ROUND, 0,
0.000001
);
}
// Test negative offset
// See https://github.com/libgeos/geos/issues/897
template<>
template<>
void object::test<12>()
{
checkOffset(
"LINESTRING (292671.05 7336734.42, 292624.85 7336739.72, 292623.53 7336739.92, 292622.36 7336740.2, 292621.35 7336740.57, 292620.94 7336740.78, 292620.61 7336740.97, 292620.33 7336741.14, 292620.13 7336741.29, 292619.79 7336741.57, 292619.48 7336741.86, 292619.34 7336742.01, 292619.21 7336742.17, 292619.09 7336742.34, 292618.98 7336742.51, 292618.8 7336742.88, 292618.63 7336743.25, 292618.57 7336743.43, 292618.52 7336743.58, 292618.48 7336743.71, 292618.46 7336743.8, 292618.44 7336743.98, 292618.42 7336744.15, 292618.41 7336744.33, 292618.4 7336744.51, 292618.39 7336744.69, 292618.38 7336744.88, 292618.38 7336744.91, 292618.38 7336744.95, 292618.38 7336744.99, 292618.38 7336745.02, 292618.38 7336745.06, 292618.38 7336745.1, 292618.38 7336745.13, 292618.38 7336745.17, 292618.38 7336745.21, 292618.38 7336745.25, 292618.38 7336745.43, 292618.41 7336746.92)",
"LINESTRING (292672.7595667329 7336749.322260955, 292631.53009245027 7336754.052049131)",
-15, 8, GEOSBUF_JOIN_ROUND, 0,
0.000001
);
}
template<>
template<>
void object::test<13>()
{
input_ = fromWKT("CIRCULARSTRING (0 0, 1 1, 2 0)");
ensure(input_);
result_ = GEOSOffsetCurve(input_, 1, 8, GEOSBUF_JOIN_ROUND, 0);
ensure("curved geometries not supported", result_ == nullptr);
}
} // namespace tut
|