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
|
//
// test suite for c-api GEOSLineSubstring
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
#include "capi_test_utils.h"
namespace tut {
//
// test group
//
// common data used in test cases.
struct test_capigeoslinesubstring_data : public capitest::utility {
};
typedef test_group<test_capigeoslinesubstring_data> group;
typedef group::object object;
group test_capigeoslinesubstring_group("capi::GEOSLineSubstring");
//
// test cases
//
// basic LineString input
template<>
template<>
void object::test<1>
()
{
input_ = GEOSGeomFromWKT("LINESTRING (0 0, 2 2)");
result_ = GEOSLineSubstring(input_, 0, 0.5);
expected_ = GEOSGeomFromWKT("LINESTRING (0 0, 1 1)");
ensure_geometry_equals(result_, expected_);
}
// MultiLineString also accepted
template<>
template<>
void object::test<2>
()
{
input_ = GEOSGeomFromWKT("MULTILINESTRING((0 0, 0 100),(0 -5, 0 0))");
result_ = GEOSLineSubstring(input_, 0.5, 1);
expected_ = GEOSGeomFromWKT("MULTILINESTRING ((0 52.5, 0 100), (0 -5, 0 0))");
ensure_geometry_equals(result_, expected_);
}
// collapse returns zero-length linestring
template<>
template<>
void object::test<3>
()
{
input_ = GEOSGeomFromWKT("LINESTRING (0 0, 2 2)");
result_ = GEOSLineSubstring(input_, 0.5, 0.5);
expected_ = GEOSGeomFromWKT("LINESTRING (1 1, 1 1)");
ensure_geometry_equals(result_, expected_);
}
// fractions out of range throw an error
template<>
template<>
void object::test<4>
()
{
input_ = GEOSGeomFromWKT("LINESTRING (0 0, 2 2)");
result_ = GEOSLineSubstring(input_, 0.5, 1.5);
ensure(result_ == nullptr);
result_ = GEOSLineSubstring(input_, 0.5, -0.1);
ensure(result_ == nullptr);
}
// Z dimension is interpolated
template<>
template<>
void object::test<5>
()
{
input_ = GEOSGeomFromWKT("LINESTRINGZ (0 0 0, 2 2 5)");
result_ = GEOSLineSubstring(input_, 0, 0.5);
expected_ = GEOSGeomFromWKT("LINESTRING (0 0 0, 1 1 2.5)");
ensure_geometry_equals(result_, expected_);
// check 3rd dimension that isgnored by ensure_geometry_equals
ensure(GEOSHasZ(result_));
auto seq = GEOSGeom_getCoordSeq(expected_);
double z0, z1;
GEOSCoordSeq_getZ(seq, 0, &z0);
GEOSCoordSeq_getZ(seq, 1, &z1);
ensure_equals(z0, 0);
ensure_equals(z1, 2.5);
}
// reversed fractions give a reversed substring
template<>
template<>
void object::test<6>
()
{
input_ = GEOSGeomFromWKT("LINESTRING (0 0, 1 1)");
result_ = GEOSLineSubstring(input_, 0.5, 0);
expected_ = GEOSGeomFromWKT("LINESTRING(0.5 0.5, 0 0)");
ensure_geometry_equals(result_, expected_);
}
template<>
template<>
void object::test<7>()
{
input_ = fromWKT("CIRCULARSTRING (0 0, 1 1, 2 0)");
ensure(input_);
result_ = GEOSLineSubstring(input_, 0.5, 0);
ensure("curved geometries not supported", result_ == nullptr);
}
// NaN start fraction
// https://github.com/libgeos/geos/issues/1077
template<>
template<>
void object::test<8>
()
{
input_ = fromWKT("LINESTRING EMPTY");
double start = std::numeric_limits<double>::quiet_NaN();
double end = 0.1;
result_ = GEOSLineSubstring(input_, start, end);
ensure(result_ == nullptr);
}
template<>
template<>
void object::test<9>
()
{
input_ = fromWKT("POLYGON ((0 0, 1 0, 1 1, 0 0))");
result_ = GEOSLineSubstring(input_, 0.2, 0.3);
ensure(result_ == nullptr);
}
} // namespace tut
|