diff --git a/vcg/space/index/aabb_binary_tree/closest.h b/vcg/space/index/aabb_binary_tree/closest.h index 285e143b..a9dd6b55 100644 --- a/vcg/space/index/aabb_binary_tree/closest.h +++ b/vcg/space/index/aabb_binary_tree/closest.h @@ -128,12 +128,15 @@ public: ScalarType closestDist = math::Sqrt(minMaxDist) + std::numeric_limits::epsilon(); ScalarType closestDistSq = closestDist * closestDist; + for (NodePtrVector_ci ci=leaves.begin(); ci!=leaves.end(); ++ci) { if ((*ci)->ScalarValue() < closestDistSq) { for (typename TreeType::ObjPtrVectorConstIterator si=(*ci)->oBegin; si!=(*ci)->oEnd; ++si) { if (getPointDistance(*(*si), p, closestDist, closestPoint)) { closestDistSq = closestDist * closestDist; closestObject = (*si); + q = closestPoint; + minDist = closestDist; } } } @@ -141,9 +144,6 @@ public: leaves.clear(); - q = closestPoint; - minDist = closestDist; - return (closestObject); }