diff --git a/src/libnest2d/include/libnest2d/geometry_traits.hpp b/src/libnest2d/include/libnest2d/geometry_traits.hpp index 134ec73a0b..a179e4c941 100644 --- a/src/libnest2d/include/libnest2d/geometry_traits.hpp +++ b/src/libnest2d/include/libnest2d/geometry_traits.hpp @@ -871,7 +871,7 @@ template auto rcend(const P& p) -> decltype(_backward(cbegin(p))) template TPoint

front(const P& p) { return *shapelike::cbegin(p); } template TPoint

back (const P& p) { - return *backward(shapelike::cend(p)); + return *std::prev(shapelike::cend(p)); } // Optional, does nothing by default diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp index 5b5311d90f..a17d549822 100644 --- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp @@ -157,26 +157,34 @@ template class EdgeCache { void createCache(const RawShape& sh) { { // For the contour - auto first = shapelike::cbegin(sh); - auto next = std::next(first); - auto endit = shapelike::cend(sh); + auto first = sl::cbegin(sh); + auto endit = sl::cend(sh); + auto next = first == endit ? endit : std::next(first); - contour_.distances.reserve(shapelike::contourVertexCount(sh)); + contour_.distances.reserve(sl::contourVertexCount(sh)); while(next != endit) { contour_.emap.emplace_back(*(first++), *(next++)); contour_.full_distance += length(contour_.emap.back()); contour_.distances.emplace_back(contour_.full_distance); } + + if constexpr (ClosureTypeV == Closure::OPEN) { + if (sl::contourVertexCount(sh) > 0) { + contour_.emap.emplace_back(sl::back(sh), sl::front(sh)); + contour_.full_distance += length(contour_.emap.back()); + contour_.distances.emplace_back(contour_.full_distance); + } + } } for(auto& h : shapelike::holes(sh)) { // For the holes - auto first = h.begin(); - auto next = std::next(first); - auto endit = h.end(); + auto first = sl::cbegin(h); + auto endit = sl::cend(h); + auto next = first == endit ? endit :std::next(first); ContourCache hc; - hc.distances.reserve(endit - first); + hc.distances.reserve(sl::contourVertexCount(h)); while(next != endit) { hc.emap.emplace_back(*(first++), *(next++)); @@ -184,6 +192,14 @@ template class EdgeCache { hc.distances.emplace_back(hc.full_distance); } + if constexpr (ClosureTypeV == Closure::OPEN) { + if (sl::contourVertexCount(h) > 0) { + hc.emap.emplace_back(sl::back(sh), sl::front(sh)); + hc.full_distance += length(hc.emap.back()); + hc.distances.emplace_back(hc.full_distance); + } + } + holes_.emplace_back(std::move(hc)); } } @@ -206,7 +222,6 @@ template class EdgeCache { contour_.corners.reserve(N / S + 1); contour_.corners.emplace_back(0.0); auto N_1 = N-1; - contour_.corners.emplace_back(0.0); for(size_t i = 0; i < N_1; i += S) { contour_.corners.emplace_back( contour_.distances.at(i) / contour_.full_distance);