@@ -69,7 +69,7 @@ class span {
6969namespace flatbush {
7070
7171constexpr auto gMaxHilbert = std::numeric_limits<uint16_t >::max();
72- constexpr auto gMaxDistance = std::numeric_limits<double >::max();
72+ constexpr auto gMaxDistance = 1.34078e+154 ; // std::sqrt(std:: numeric_limits<double>::max())
7373constexpr auto gMaxResults = std::numeric_limits<size_t >::max();
7474constexpr auto gInvalidArrayType = std::numeric_limits<uint8_t >::max();
7575constexpr uint16_t gMinNodeSize = 2 ;
@@ -416,6 +416,7 @@ class Flatbush {
416416
417417 inline bool canDoNeighbors (const Point<ArrayType>& iPoint,
418418 size_t iMaxResults,
419+ double iMaxDistance,
419420 double iMaxDistSquared) const {
420421#if defined(_WIN32) || defined(_WIN64)
421422 // On Windows, isnan throws on anything that is not float, double or long double
@@ -429,8 +430,8 @@ class Flatbush {
429430 const auto wDistY = axisDistance (iPoint.mY , mBounds .mMinY , mBounds .mMaxY );
430431 const auto wDistance = wDistX * wDistX + wDistY * wDistY;
431432
432- return !wIsNanPoint && iMaxResults != 0UL && !std::isnan (iMaxDistSquared ) &&
433- iMaxDistSquared >= 0.0 && wDistance < iMaxDistSquared;
433+ return !wIsNanPoint && iMaxResults != 0UL && iMaxDistance > 0.0 && !std::isnan (wDistance ) &&
434+ std::isnormal ( iMaxDistSquared) && wDistance <= iMaxDistSquared;
434435 }
435436
436437 Flatbush (uint32_t iNumItems, uint16_t iNodeSize) noexcept ;
@@ -758,7 +759,7 @@ std::vector<size_t> Flatbush<ArrayType>::neighbors(const Point<ArrayType>& iPoin
758759 double iMaxDistance,
759760 const FilterCb& iFilterFn) const noexcept {
760761 const auto wMaxDistSquared = iMaxDistance * iMaxDistance;
761- const auto wCanLoop = canDoNeighbors (iPoint, iMaxResults, wMaxDistSquared);
762+ const auto wCanLoop = canDoNeighbors (iPoint, iMaxResults, iMaxDistance, wMaxDistSquared);
762763 const auto wNumItems = numItems ();
763764 const auto wNodeSize = nodeSize ();
764765 auto wNodeIndex = mBoxes .size () - 1UL ;
0 commit comments