diff options
author | Lukáš Hejl <hejl.lukas@gmail.com> | 2022-07-11 16:19:48 +0300 |
---|---|---|
committer | Lukáš Hejl <hejl.lukas@gmail.com> | 2022-07-12 14:36:26 +0300 |
commit | e86463a369183134df95d5bc7d7c8a6387117edf (patch) | |
tree | 0c8ba478e8676640fefc5cccfe1951799dada675 | |
parent | f41d72d656e6ecfd2ead92663c35db07e4664690 (diff) |
Fix of #8463 - Crash in SkeletalTrapezoidation::computePointCellRange() when a cell point didn't fit into Vec2i64 because it was too far away.
-rw-r--r-- | src/libslic3r/Arachne/SkeletalTrapezoidation.cpp | 10 | ||||
-rw-r--r-- | src/libslic3r/Arachne/utils/VoronoiUtils.cpp | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp b/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp index 2852d242c..a6ed26904 100644 --- a/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp +++ b/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp @@ -293,7 +293,15 @@ bool SkeletalTrapezoidation::computePointCellRange(vd_t::cell_type& cell, Point& // Check if any point of the cell is inside or outside polygon // Copy whole cell into graph or not at all - + + // If the cell.incident_edge()->vertex0() is far away so much that it doesn't even fit into Vec2i64, then there is no way that it will be inside the input polygon. + assert(x <= double(std::numeric_limits<int64_t>::max()) && x >= std::numeric_limits<int64_t>::lowest()); + assert(y <= double(std::numeric_limits<int64_t>::max()) && y >= std::numeric_limits<int64_t>::lowest()); + if (const vd_t::vertex_type &vert = *cell.incident_edge()->vertex0(); + vert.x() >= double(std::numeric_limits<int64_t>::max()) || vert.x() <= double(std::numeric_limits<int64_t>::lowest()) || + vert.y() >= double(std::numeric_limits<int64_t>::max()) || vert.y() <= double(std::numeric_limits<int64_t>::lowest())) + return false; // Don't copy any part of this cell + const Point source_point = VoronoiUtils::getSourcePoint(cell, segments); const PolygonsPointIndex source_point_index = VoronoiUtils::getSourcePointIndex(cell, segments); Vec2i64 some_point = VoronoiUtils::p(cell.incident_edge()->vertex0()); diff --git a/src/libslic3r/Arachne/utils/VoronoiUtils.cpp b/src/libslic3r/Arachne/utils/VoronoiUtils.cpp index a0f219039..3da556b47 100644 --- a/src/libslic3r/Arachne/utils/VoronoiUtils.cpp +++ b/src/libslic3r/Arachne/utils/VoronoiUtils.cpp @@ -17,7 +17,7 @@ Vec2i64 VoronoiUtils::p(const vd_t::vertex_type *node) const double y = node->y(); assert(x <= double(std::numeric_limits<int64_t>::max()) && x >= std::numeric_limits<int64_t>::lowest()); assert(y <= double(std::numeric_limits<int64_t>::max()) && y >= std::numeric_limits<int64_t>::lowest()); - return Vec2i64(int64_t(x + 0.5 - (x < 0)), int64_t(y + 0.5 - (y < 0))); // Round to the nearest integer coordinates. + return {int64_t(x + 0.5 - (x < 0)), int64_t(y + 0.5 - (y < 0))}; // Round to the nearest integer coordinates. } Point VoronoiUtils::getSourcePoint(const vd_t::cell_type& cell, const std::vector<Segment>& segments) |