From 9f97d9252c0bacec32c5a0173446a93b11f264a4 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 18 Sep 2024 15:22:27 +0200 Subject: [PATCH] squared distance for KD Tree can't be in CoordType when using coord_t as template parametre (because of overflow of value range) --- src/libslic3r/KDTreeIndirect.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/KDTreeIndirect.hpp b/src/libslic3r/KDTreeIndirect.hpp index 65441e72f6..e6f3ba03e9 100644 --- a/src/libslic3r/KDTreeIndirect.hpp +++ b/src/libslic3r/KDTreeIndirect.hpp @@ -63,10 +63,10 @@ public: } template - unsigned int descent_mask(const CoordType &point_coord, const CoordType &search_radius, size_t idx, size_t dimension) const + unsigned int descent_mask(const CoordType &point_coord, const double &search_radius, size_t idx, size_t dimension) const { CoordType dist = point_coord - this->coordinate(idx, dimension); - return (dist * dist < search_radius + CoordType(EPSILON)) ? + return (double(dist) * dist < search_radius + EPSILON) ? // The plane intersects a hypersphere centered at point_coord of search_radius. ((unsigned int)(VisitorReturnMask::CONTINUE_LEFT) | (unsigned int)(VisitorReturnMask::CONTINUE_RIGHT)) : // The plane does not intersect the hypersphere. @@ -290,20 +290,20 @@ std::vector find_nearby_points(const KDTreeIndirectType &kdtree, const P struct Visitor { const KDTreeIndirectType &kdtree; const PointType center; - const CoordType max_distance_squared; + const double max_distance_squared; const FilterFn filter; std::vector result; Visitor(const KDTreeIndirectType &kdtree, const PointType& center, const CoordType &max_distance, FilterFn filter) : - kdtree(kdtree), center(center), max_distance_squared(max_distance*max_distance), filter(filter) { + kdtree(kdtree), center(center), max_distance_squared(double(max_distance)*max_distance), filter(filter) { } unsigned int operator()(size_t idx, size_t dimension) { if (this->filter(idx)) { - auto dist = CoordType(0); + double dist = 0.; for (size_t i = 0; i < KDTreeIndirectType::NumDimensions; ++i) { CoordType d = center[i] - kdtree.coordinate(idx, i); - dist += d * d; + dist += double(d) * d; } if (dist < max_distance_squared) { result.push_back(idx);