|
| 1 | +// |
| 2 | +// Test Suite for geos::operation::overlayng::OverlayNG coordinate dimension handling |
| 3 | +// for EMPTY geometries |
| 4 | + |
| 5 | +#include <tut/tut.hpp> |
| 6 | +#include <utility.h> |
| 7 | + |
| 8 | +// geos |
| 9 | +#include <geos/operation/overlayng/OverlayNG.h> |
| 10 | + |
| 11 | +// std |
| 12 | +#include <memory> |
| 13 | + |
| 14 | +using namespace geos::geom; |
| 15 | +using namespace geos::operation::overlayng; |
| 16 | +using geos::io::WKTReader; |
| 17 | +using geos::io::WKTWriter; |
| 18 | + |
| 19 | +namespace tut { |
| 20 | +// |
| 21 | +// Test Group |
| 22 | +// |
| 23 | + |
| 24 | +// Common data used by all tests |
| 25 | +struct test_overlayngcemptyoorddim_data { |
| 26 | + |
| 27 | + WKTReader r; |
| 28 | + WKTWriter w; |
| 29 | + |
| 30 | + void |
| 31 | + testOverlay(const std::string& a, const std::string& b, int opCode, const std::string& expected) |
| 32 | + { |
| 33 | + std::unique_ptr<Geometry> geom_a = r.read(a); |
| 34 | + std::unique_ptr<Geometry> geom_b = r.read(b); |
| 35 | + std::unique_ptr<Geometry> geom_expected = r.read(expected); |
| 36 | + std::unique_ptr<Geometry> geom_result = OverlayNG::overlay(geom_a.get(), geom_b.get(), opCode); |
| 37 | + // std::string wkt_result = w.write(geom_result.get()); |
| 38 | + // std::cout << std::endl << wkt_result << std::endl; |
| 39 | + ensure_equals_geometry(geom_expected.get(), geom_result.get()); |
| 40 | + ensure_equals( "Coordinate dimension: ", |
| 41 | + (int) geom_result.get()->getCoordinateDimension(), |
| 42 | + (int) geom_expected.get()->getCoordinateDimension() |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | +}; |
| 47 | + |
| 48 | +typedef test_group<test_overlayngcemptyoorddim_data> group; |
| 49 | +typedef group::object object; |
| 50 | + |
| 51 | +group test_overlayngcoorddim_group("geos::operation::overlayng::OverlayNGEmptyCoordDim"); |
| 52 | + |
| 53 | +// |
| 54 | +// Test Cases |
| 55 | +// |
| 56 | + |
| 57 | +//--------- POINT / POINT |
| 58 | + |
| 59 | +// test ZM dim for empty POINT union |
| 60 | +template<> |
| 61 | +template<> |
| 62 | +void object::test<1> () |
| 63 | +{ |
| 64 | + testOverlay("POINT ZM EMPTY", "POINT ZM EMPTY", |
| 65 | + OverlayNG::UNION, "POINT ZM EMPTY"); |
| 66 | +} |
| 67 | + |
| 68 | +// test ZM dim for empty POINT intersection |
| 69 | +template<> |
| 70 | +template<> |
| 71 | +void object::test<2> () |
| 72 | +{ |
| 73 | + testOverlay("POINT ZM EMPTY", "POINT ZM EMPTY", |
| 74 | + OverlayNG::INTERSECTION, "POINT ZM EMPTY"); |
| 75 | +} |
| 76 | + |
| 77 | +// test mixed ZM and XY dim for empty POINT union |
| 78 | +template<> |
| 79 | +template<> |
| 80 | +void object::test<3> () |
| 81 | +{ |
| 82 | + testOverlay("POINT ZM EMPTY", "POINT EMPTY", |
| 83 | + OverlayNG::UNION, "POINT EMPTY"); |
| 84 | +} |
| 85 | + |
| 86 | +// test mixed ZM and Z dim for empty POINT union |
| 87 | +template<> |
| 88 | +template<> |
| 89 | +void object::test<4> () |
| 90 | +{ |
| 91 | + testOverlay("POINT ZM EMPTY", "POINT Z EMPTY", |
| 92 | + OverlayNG::UNION, "POINT Z EMPTY"); |
| 93 | +} |
| 94 | + |
| 95 | +//--------- LINESTRING / POINT |
| 96 | + |
| 97 | +template<> |
| 98 | +template<> |
| 99 | +void object::test<5> () |
| 100 | +{ |
| 101 | + testOverlay("POINT ZM EMPTY", "LINESTRING ZM EMPTY", |
| 102 | + OverlayNG::UNION, "LINESTRING ZM EMPTY"); |
| 103 | +} |
| 104 | + |
| 105 | +template<> |
| 106 | +template<> |
| 107 | +void object::test<6> () |
| 108 | +{ |
| 109 | + testOverlay("POINT ZM EMPTY", "LINESTRING Z EMPTY", |
| 110 | + OverlayNG::UNION, "LINESTRING Z EMPTY"); |
| 111 | +} |
| 112 | + |
| 113 | +template<> |
| 114 | +template<> |
| 115 | +void object::test<7> () |
| 116 | +{ |
| 117 | + testOverlay("POINT ZM EMPTY", "LINESTRING EMPTY", |
| 118 | + OverlayNG::UNION, "LINESTRING EMPTY"); |
| 119 | +} |
| 120 | + |
| 121 | +//-- ensure coord dim is lowest of either operand |
| 122 | +template<> |
| 123 | +template<> |
| 124 | +void object::test<8> () |
| 125 | +{ |
| 126 | + testOverlay("POINT EMPTY", "LINESTRING ZM EMPTY", |
| 127 | + OverlayNG::UNION, "LINESTRING EMPTY"); |
| 128 | +} |
| 129 | + |
| 130 | +//--------- LINESTRING / LINESTRING |
| 131 | + |
| 132 | +// test ZM dim for empty LINESTRING union |
| 133 | +template<> |
| 134 | +template<> |
| 135 | +void object::test<9> () |
| 136 | +{ |
| 137 | + testOverlay("LINESTRING ZM EMPTY", "LINESTRING ZM EMPTY", |
| 138 | + OverlayNG::UNION, "LINESTRING ZM EMPTY"); |
| 139 | +} |
| 140 | + |
| 141 | +// test mixed ZM and XY dim for empty LINESTRING union |
| 142 | +template<> |
| 143 | +template<> |
| 144 | +void object::test<10> () |
| 145 | +{ |
| 146 | + testOverlay("LINESTRING ZM EMPTY", "LINESTRING Z EMPTY", |
| 147 | + OverlayNG::UNION, "LINESTRING Z EMPTY"); |
| 148 | +} |
| 149 | + |
| 150 | +// test mixed ZM and Z dim for empty LINESTRING union |
| 151 | +template<> |
| 152 | +template<> |
| 153 | +void object::test<11> () |
| 154 | +{ |
| 155 | + testOverlay("LINESTRING ZM EMPTY", "LINESTRING EMPTY", |
| 156 | + OverlayNG::UNION, "LINESTRING EMPTY"); |
| 157 | +} |
| 158 | + |
| 159 | +//--------- GEOMETRYCOLLECTION |
| 160 | + |
| 161 | +//-- coord dim of GC (ZM) EMPTY is always 2 |
| 162 | +template<> |
| 163 | +template<> |
| 164 | +void object::test<12> () |
| 165 | +{ |
| 166 | + testOverlay("GEOMETRYCOLLECTION ZM EMPTY", |
| 167 | + "POINT ZM EMPTY", |
| 168 | + OverlayNG::UNION, "POINT EMPTY"); |
| 169 | +} |
| 170 | + |
| 171 | +//-- coord dim of GC containing EMPTYs is lowest coord dim of elements |
| 172 | +template<> |
| 173 | +template<> |
| 174 | +void object::test<13> () |
| 175 | +{ |
| 176 | + testOverlay("GEOMETRYCOLLECTION (POINT ZM EMPTY)", |
| 177 | + "GEOMETRYCOLLECTION (POINT ZM EMPTY, LINESTRING ZM EMPTY)", |
| 178 | + OverlayNG::UNION, "LINESTRING ZM EMPTY"); |
| 179 | +} |
| 180 | + |
| 181 | +template<> |
| 182 | +template<> |
| 183 | +void object::test<14> () |
| 184 | +{ |
| 185 | + testOverlay("GEOMETRYCOLLECTION (POINT Z EMPTY)", |
| 186 | + "GEOMETRYCOLLECTION (POINT ZM EMPTY, LINESTRING ZM EMPTY)", |
| 187 | + OverlayNG::UNION, "LINESTRING Z EMPTY"); |
| 188 | +} |
| 189 | + |
| 190 | +template<> |
| 191 | +template<> |
| 192 | +void object::test<15> () |
| 193 | +{ |
| 194 | + testOverlay("GEOMETRYCOLLECTION (POINT EMPTY)", |
| 195 | + "GEOMETRYCOLLECTION (POINT ZM EMPTY, LINESTRING ZM EMPTY)", |
| 196 | + OverlayNG::UNION, "LINESTRING EMPTY"); |
| 197 | +} |
| 198 | + |
| 199 | +} // namespace tut |
0 commit comments