Skip to content

Commit

Permalink
Add missing data test
Browse files Browse the repository at this point in the history
Reproduces the failure from [1], which seems to be because the graph was
not correctly noded, which is one of the requirements to use the Geos
Polygonizer.

[1] #87
  • Loading branch information
Notgnoshi committed Apr 7, 2023
1 parent 962c8b6 commit 3c11270
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/polygonizer-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,51 @@ TEST(PolygonizerTests, SimplePolygonWithDangles)
EXPECT_TRUE(dangles.at(0)->equals(dangle1.get()));
EXPECT_TRUE(dangles.at(1)->equals(dangle2.get()));
}

TEST(PolygonizerTests, DISABLED_MissingData)
{
const auto* factory = geos::geom::GeometryFactory::getDefaultInstance();
auto graph = generative::noding::GeometryGraph(*factory);

std::vector<generative::noding::GeometryGraph::Node> nodes;
nodes.emplace_back(
0, std::unique_ptr<geos::geom::Point>(factory->createPoint(geos::geom::Coordinate(0, 0))));
nodes.emplace_back(
1, std::unique_ptr<geos::geom::Point>(factory->createPoint(geos::geom::Coordinate(1, 0))));
nodes.emplace_back(
2, std::unique_ptr<geos::geom::Point>(factory->createPoint(geos::geom::Coordinate(2, 0))));
nodes.emplace_back(
3, std::unique_ptr<geos::geom::Point>(factory->createPoint(geos::geom::Coordinate(0, 1))));
nodes.emplace_back(
4, std::unique_ptr<geos::geom::Point>(factory->createPoint(geos::geom::Coordinate(1, 1))));
graph.set_nodes(std::move(nodes));

graph.add_edge(0, 1);
// TODO: This is the culprit - I think this edge is incorrectly noded.
graph.add_edge(0, 2);
graph.add_edge(1, 2);
graph.add_edge(1, 3);
graph.add_edge(2, 4);
graph.add_edge(3, 4);

const auto owned_edges = graph.get_edges();
std::vector<const geos::geom::Geometry*> edges;
std::transform(
owned_edges.begin(),
owned_edges.end(),
std::back_inserter(edges),
[](const std::unique_ptr<geos::geom::LineString>& edge) -> const geos::geom::Geometry* {
return edge.get();
});

auto polygonizer = geos::operation::polygonize::Polygonizer();
polygonizer.add(&edges);

ASSERT_FALSE(polygonizer.hasInvalidRingLines());

const auto polys = polygonizer.getPolygons();
const auto dangles = polygonizer.getDangles();

EXPECT_THAT(polys, SizeIs(1));
EXPECT_THAT(dangles, SizeIs(1));
}

0 comments on commit 3c11270

Please sign in to comment.