mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 00:26:01 +08:00
squared distance for KD Tree can't be in CoordType when using coord_t as template parametre (because of overflow of value range)
This commit is contained in:
parent
40d52994db
commit
9f97d9252c
@ -63,10 +63,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename CoordType>
|
template<typename CoordType>
|
||||||
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);
|
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.
|
// The plane intersects a hypersphere centered at point_coord of search_radius.
|
||||||
((unsigned int)(VisitorReturnMask::CONTINUE_LEFT) | (unsigned int)(VisitorReturnMask::CONTINUE_RIGHT)) :
|
((unsigned int)(VisitorReturnMask::CONTINUE_LEFT) | (unsigned int)(VisitorReturnMask::CONTINUE_RIGHT)) :
|
||||||
// The plane does not intersect the hypersphere.
|
// The plane does not intersect the hypersphere.
|
||||||
@ -290,20 +290,20 @@ std::vector<size_t> find_nearby_points(const KDTreeIndirectType &kdtree, const P
|
|||||||
struct Visitor {
|
struct Visitor {
|
||||||
const KDTreeIndirectType &kdtree;
|
const KDTreeIndirectType &kdtree;
|
||||||
const PointType center;
|
const PointType center;
|
||||||
const CoordType max_distance_squared;
|
const double max_distance_squared;
|
||||||
const FilterFn filter;
|
const FilterFn filter;
|
||||||
std::vector<size_t> result;
|
std::vector<size_t> result;
|
||||||
|
|
||||||
Visitor(const KDTreeIndirectType &kdtree, const PointType& center, const CoordType &max_distance,
|
Visitor(const KDTreeIndirectType &kdtree, const PointType& center, const CoordType &max_distance,
|
||||||
FilterFn filter) :
|
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) {
|
unsigned int operator()(size_t idx, size_t dimension) {
|
||||||
if (this->filter(idx)) {
|
if (this->filter(idx)) {
|
||||||
auto dist = CoordType(0);
|
double dist = 0.;
|
||||||
for (size_t i = 0; i < KDTreeIndirectType::NumDimensions; ++i) {
|
for (size_t i = 0; i < KDTreeIndirectType::NumDimensions; ++i) {
|
||||||
CoordType d = center[i] - kdtree.coordinate(idx, i);
|
CoordType d = center[i] - kdtree.coordinate(idx, i);
|
||||||
dist += d * d;
|
dist += double(d) * d;
|
||||||
}
|
}
|
||||||
if (dist < max_distance_squared) {
|
if (dist < max_distance_squared) {
|
||||||
result.push_back(idx);
|
result.push_back(idx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user