Skip to content

Commit 2ea885e

Browse files
janherlingmetameta-codesync[bot]
authored andcommitted
Seed the KdTree nearest-neighbour distance with the squared-distance type's max
Summary: `nearestNeighbor()` writes its result into a `SquareValueTyper<T>::Type`, but seeded the sentinel from `T`. For floating point the two types are identical, so nothing was wrong there. For every integer instantiation they differ and the sentinel is far too small - `SquareValueTyper<short>::Type` is `unsigned int` (max 4294967295) while `numeric_limits<short>::max()` is 32767. The recursive helper only assigns `nearest` inside `if (localDistance < distance)`, so any tree whose closest point sits farther than that sentinel returned no candidate at all. For `short` that is any coordinate delta beyond about 181. ___ Differential Revision: D114541610 fbshipit-source-id: 4745518e0e6fce1e18ccb6808ff9250b04973ed8
1 parent 6a021ef commit 2ea885e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

impl/ocean/base/KdTree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ const T* KdTree<T>::nearestNeighbor(const T* value, typename SquareValueTyper<T>
340340
{
341341
ocean_assert(value);
342342

343-
distance = std::numeric_limits<T>::max();
343+
distance = std::numeric_limits<typename SquareValueTyper<T>::Type>::max();
344344

345345
if (!root_)
346346
{

0 commit comments

Comments
 (0)