|
9 | 9 |
|
10 | 10 | #include <catch.hpp> |
11 | 11 |
|
| 12 | +#include "common-buffer.hpp" |
| 13 | + |
| 14 | +#include "geom-from-osm.hpp" |
12 | 15 | #include "geom-functions.hpp" |
13 | 16 | #include "geom.hpp" |
14 | 17 |
|
@@ -63,3 +66,77 @@ TEST_CASE("geom::polygon_t", "[NoDB]") |
63 | 66 | REQUIRE(geometry_type(geom) == "POLYGON"); |
64 | 67 | REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1.5, 1.5}}); |
65 | 68 | } |
| 69 | + |
| 70 | +TEST_CASE("create_polygon from OSM data", "[NoDB]") |
| 71 | +{ |
| 72 | + test_buffer_t buffer; |
| 73 | + buffer.add_way("w20 Nn1x1y1,n2x2y1,n3x2y2,n4x1y2,n1x1y1"); |
| 74 | + |
| 75 | + auto const geom = geom::create_polygon(buffer.buffer().get<osmium::Way>(0)); |
| 76 | + |
| 77 | + REQUIRE(geom.is_polygon()); |
| 78 | + REQUIRE(geometry_type(geom) == "POLYGON"); |
| 79 | + REQUIRE(num_geometries(geom) == 1); |
| 80 | + REQUIRE(area(geom) == Approx(1.0)); |
| 81 | + REQUIRE( |
| 82 | + geom.get<geom::polygon_t>() == |
| 83 | + geom::polygon_t{geom::ring_t{{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}); |
| 84 | + REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1.5, 1.5}}); |
| 85 | +} |
| 86 | + |
| 87 | +TEST_CASE("create_polygon from OSM data (reverse)", "[NoDB]") |
| 88 | +{ |
| 89 | + test_buffer_t buffer; |
| 90 | + buffer.add_way("w20 Nn1x1y1,n2x1y2,n3x2y2,n4x2y1,n1x1y1"); |
| 91 | + |
| 92 | + auto const geom = geom::create_polygon(buffer.buffer().get<osmium::Way>(0)); |
| 93 | + |
| 94 | + REQUIRE(geom.is_polygon()); |
| 95 | + REQUIRE(geometry_type(geom) == "POLYGON"); |
| 96 | + REQUIRE(num_geometries(geom) == 1); |
| 97 | + REQUIRE(area(geom) == Approx(1.0)); |
| 98 | + REQUIRE( |
| 99 | + geom.get<geom::polygon_t>() == |
| 100 | + geom::polygon_t{geom::ring_t{{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}); |
| 101 | + REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1.5, 1.5}}); |
| 102 | +} |
| 103 | + |
| 104 | +TEST_CASE("create_polygon from OSM data without locations", "[NoDB]") |
| 105 | +{ |
| 106 | + test_buffer_t buffer; |
| 107 | + buffer.add_way("w20 Nn1,n2,n3,n1"); |
| 108 | + |
| 109 | + auto const geom = geom::create_polygon(buffer.buffer().get<osmium::Way>(0)); |
| 110 | + |
| 111 | + REQUIRE(geom.is_null()); |
| 112 | +} |
| 113 | + |
| 114 | +TEST_CASE("create_polygon from invalid OSM data (single node)", "[NoDB]") |
| 115 | +{ |
| 116 | + test_buffer_t buffer; |
| 117 | + buffer.add_way("w20 Nn1x1y1"); |
| 118 | + |
| 119 | + auto const geom = geom::create_polygon(buffer.buffer().get<osmium::Way>(0)); |
| 120 | + |
| 121 | + REQUIRE(geom.is_null()); |
| 122 | +} |
| 123 | + |
| 124 | +TEST_CASE("create_polygon from invalid OSM data (way node closed)", "[NoDB]") |
| 125 | +{ |
| 126 | + test_buffer_t buffer; |
| 127 | + buffer.add_way("w20 Nn1x1y1,n2x2y2"); |
| 128 | + |
| 129 | + auto const geom = geom::create_polygon(buffer.buffer().get<osmium::Way>(0)); |
| 130 | + |
| 131 | + REQUIRE(geom.is_null()); |
| 132 | +} |
| 133 | + |
| 134 | +TEST_CASE("create_polygon from invalid OSM data (self-intersection)", "[NoDB]") |
| 135 | +{ |
| 136 | + test_buffer_t buffer; |
| 137 | + buffer.add_way("w20 Nn1x1y1,n2x1y2,n3x2y1,n4x2y2,n1x1y1"); |
| 138 | + |
| 139 | + auto const geom = geom::create_polygon(buffer.buffer().get<osmium::Way>(0)); |
| 140 | + |
| 141 | + REQUIRE(geom.is_null()); |
| 142 | +} |
0 commit comments