Skip to content

Commit

Permalink
Don't crash on empty input
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Oct 7, 2015
1 parent b96bf77 commit bfbe17d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/earcut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void Earcut<Coord, N>::operator()(const Polygon& points) {
vertices = 0;
nodes = std::make_unique<boost::object_pool<Node>>();

if (points.empty()) return;

auto outerNode = filterPoints(linkedList(points[0], true));
if (!outerNode) return;

Expand Down
8 changes: 8 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ void areaTest(const char *name, const Polygon &polygon, double earcutDeviation =
int main() {
Tap tap;

{
Tap::Test t("empty");
EarcutTesselator<int, mapbox::fixtures::IntegerPolygon> tesselator(mapbox::fixtures::IntegerPolygon {});
tesselator.run();
t.ok(tesselator.indices().empty(), "empty input produces empty result");
t.end();
}

areaTest<int>("bad_hole", mapbox::fixtures::bad_hole, 0.042, 0.0022);
areaTest<int>("building", mapbox::fixtures::building);
areaTest<int>("degenerate", mapbox::fixtures::degenerate);
Expand Down

0 comments on commit bfbe17d

Please sign in to comment.