diff --git a/NEWS.md b/NEWS.md index b44df5a5..cf7c8cd8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ - Fix: bug with `set_parallel_strategy(nested(ncores = 4, ncores2 = 4))` - Fix: attribute `datatime` is `datetime` in VPC files. +- Fix: #25 triangulation with 0 point crashed. 0 point is possible with a filter. # lasR 0.4.3 diff --git a/inst/extdata/las14_pdrf6.laz b/inst/extdata/las14_pdrf6.laz new file mode 100644 index 00000000..d387b100 Binary files /dev/null and b/inst/extdata/las14_pdrf6.laz differ diff --git a/src/LASRstages/triangulate.cpp b/src/LASRstages/triangulate.cpp index bd441ad5..e609af93 100644 --- a/src/LASRstages/triangulate.cpp +++ b/src/LASRstages/triangulate.cpp @@ -66,6 +66,12 @@ bool LASRtriangulate::process(LAS*& las) } } + if (coords.size() < 3) + { + last_error = "impossible to construct a Delaunay triangulation with " + std::to_string(coords.size()) + " points"; + return false; + } + this->las = las; d = new delaunator::Delaunator(coords); diff --git a/tests/testthat/test-triangulation.R b/tests/testthat/test-triangulation.R index 16557b3e..862ff8d1 100644 --- a/tests/testthat/test-triangulation.R +++ b/tests/testthat/test-triangulation.R @@ -38,3 +38,11 @@ test_that("triangulate works with intensity", expect_equal(range(u$rasterize[], na.rm = T), c(165.72, 2368.14), tolerance = 0.01) }) + + +test_that("triangulate fails with 0 points (#25)", +{ + f <- system.file("extdata", "las14_pdrf6.laz", package="lasR") + pipeline <- reader_las() + dtm() + expect_error(suppressWarnings(exec(pipeline, on = f)), "impossible to construct a Delaunay triangulation with 0 points") +})