diff --git a/src/clipper/clipper.cpp b/src/clipper/clipper.cpp index 3691877eea..cd51ccc103 100644 --- a/src/clipper/clipper.cpp +++ b/src/clipper/clipper.cpp @@ -86,7 +86,13 @@ inline IntPoint IntPoint2d(cInt x, cInt y) inline cInt Round(double val) { - return static_cast((val < 0) ? (val - 0.5) : (val + 0.5)); + double v = val < 0 ? val - 0.5 : val + 0.5; +#if defined(CLIPPERLIB_INT32) && ! defined(NDEBUG) + static constexpr const double hi = 65536 * 16383; + if (v > hi || -v > hi) + throw clipperException("Coordinate outside allowed range"); +#endif + return static_cast(v); } // Overriding the Eigen operators because we don't want to compare Z coordinate if IntPoint is 3 dimensional. diff --git a/src/libslic3r/Geometry/MedialAxis.cpp b/src/libslic3r/Geometry/MedialAxis.cpp index 0f9d81da66..362fa9f635 100644 --- a/src/libslic3r/Geometry/MedialAxis.cpp +++ b/src/libslic3r/Geometry/MedialAxis.cpp @@ -450,6 +450,19 @@ MedialAxis::MedialAxis(double min_width, double max_width, const ExPolygon &expo void MedialAxis::build(ThickPolylines* polylines) { +#ifndef NDEBUG + // Verify the scaling of the coordinates of input line segments. + for (const Line& l : m_lines) { + auto test = [](int32_t v) { + static constexpr const int32_t hi = 65536 * 16383; + assert(v <= hi && -v < hi); + }; + test(l.a.x()); + test(l.a.y()); + test(l.b.x()); + test(l.b.y()); + } +#endif // NDEBUG construct_voronoi(m_lines.begin(), m_lines.end(), &m_vd); Slic3r::Voronoi::annotate_inside_outside(m_vd, m_lines); // static constexpr double threshold_alpha = M_PI / 12.; // 30 degrees