jhasse / poly2tri

2D constrained Delaunay triangulation library
BSD 3-Clause "New" or "Revised" License
439 stars 89 forks source link

Triangulation fails with a very simple polygon #10

Closed mattbeghin closed 2 years ago

mattbeghin commented 4 years ago

I've been using this library since a while without problems, after having handled constraints, but I found this very simple polygon which makes the library (current master) crash:

std::vector<p2t::Point*> polyline = {
    new p2t::Point(-0.611580879999999993401615938637,0.0104235565411950892311665484158),
    new p2t::Point(-0.611580879999999993401615938637,0.1483950316905975341796875),
    new p2t::Point(-0.578899596898762469621146919962,0.227294628589359948289683188705),
    new p2t::Point(-0.5,0.259975911690597527581303438637),
    new p2t::Point(0.5,0.259975911690597527581303438637),
    new p2t::Point(0.578899596898762469621146919962,0.227294628589359948289683188705),
    new p2t::Point(0.611580879999999993401615938637,0.1483950316905975341796875),
    new p2t::Point(0.611580879999999993401615938637,0.0104235565411950614755909327869),
    new p2t::Point(0.388419120000000006598384061363,0.0104235565411950892311665484158),
    new p2t::Point(0.388419120000000006598384061363,0.0368141516905975130224959457337),
    new p2t::Point(-0.388419120000000006598384061363,0.0368141516905975269002837535481),
    new p2t::Point(-0.388419120000000006598384061363,0.0104235565411950892311665484158)
};

p2t::CDT cdt(polyline);
cdt.Triangulate();
Screenshot 2019-12-05 at 13 20 21

You can check the WKT of the polygon (for instance here http://dev.openlayers.org/examples/vector-formats.html): POLYGON((-0.611580879999999993401615938637 0.0104235565411950892311665484158,-0.611580879999999993401615938637 0.1483950316905975341796875,-0.578899596898762469621146919962 0.227294628589359948289683188705,-0.5 0.259975911690597527581303438637,0.5 0.259975911690597527581303438637,0.578899596898762469621146919962 0.227294628589359948289683188705,0.611580879999999993401615938637 0.1483950316905975341796875,0.611580879999999993401615938637 0.0104235565411950614755909327869,0.388419120000000006598384061363 0.0104235565411950892311665484158,0.388419120000000006598384061363 0.0368141516905975130224959457337,-0.388419120000000006598384061363 0.0368141516905975269002837535481,-0.388419120000000006598384061363 0.0104235565411950892311665484158,-0.611580879999999993401615938637 0.0104235565411950892311665484158))

mattbeghin commented 3 years ago

Still the same issue with this simple example:

LINESTRING(0.9636984967276516 0.7676550649687783,0.9636984967276516 -0.7676550649687641,-0.3074475690811459 -0.7676550649687641,0.09401654924378076 -0.2590574983578904,0.10567230819363671 -0.09864698028880525,-0.03901177977841874 -0.028405214140875046,-0.428964921810446 -0.08483619470406722,-0.5128305980156834 -0.12847817634298053,-0.5512747518916774 -0.2148501697175078,-0.5917836778064418 -0.7037530067555622,-0.5520451065921502 -0.7676550649687641,-0.9636984967276516 -0.7676550649687641,-0.9636984967276516 0.7676550649687783)
Screenshot 2021-07-07 at 15 30 25
mattbeghin commented 3 years ago

Even simplier: LINESTRING(0.9776422201600001 0.9776422201599928,0.9776422201599999 -0.977642220160007,-0.12788518519240472 -0.9776422201599928,-0.3913394510746002 -0.33861494064331055,-0.47812835166211676 -0.9776422201599928,-0.9776422201600001 -0.9776422201599928,-0.9776422201600001 0.977642220160007)

Screenshot 2021-07-07 at 15 43 13
pierre-dejoue commented 2 years ago

Hello,

Thanks to recent changes in the library, notably the patch on the collinearity check, the examples above are now passing.

I've created PR #44 to add those examples as part of the unit tests.