Some tests for maximum values of 32bit point coordinates.

This commit is contained in:
Vojtech Bubnik 2023-08-29 15:54:51 +02:00
parent 1d3e5a9f24
commit 532913bade
2 changed files with 20 additions and 1 deletions

View File

@ -86,7 +86,13 @@ inline IntPoint IntPoint2d(cInt x, cInt y)
inline cInt Round(double val)
{
return static_cast<cInt>((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<cInt>(v);
}
// Overriding the Eigen operators because we don't want to compare Z coordinate if IntPoint is 3 dimensional.

View File

@ -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