@@ -304,32 +304,29 @@ inline size_t approximateResultsSize(const Box<ArrayType>& iBoxIndex,
304304 const auto wBoundsIndex = static_cast <const Box<double >>(iBoxIndex);
305305 const auto wBoundsSearch = static_cast <const Box<double >>(iBoxSearch);
306306
307- // Calculate intersection area
308- const auto wWidth = std::min (wBoundsIndex.mMaxX , wBoundsSearch.mMaxX ) -
309- std::max (wBoundsIndex.mMinX , wBoundsSearch.mMinX );
310- const auto wHeight = std::min (wBoundsIndex.mMaxY , wBoundsSearch.mMaxY ) -
311- std::max (wBoundsIndex.mMinY , wBoundsSearch.mMinY );
312- const auto wIntersectionArea = wWidth * wHeight;
307+ // Calculate index area
308+ const auto wIndexWidth = wBoundsIndex.mMaxX - wBoundsIndex.mMinX ;
309+ const auto wIndexHeight = wBoundsIndex.mMaxY - wBoundsIndex.mMinY ;
310+ const auto wIndexArea = wIndexWidth * wIndexHeight;
313311
314- // Calculate search area
312+ // Calculate intersection area
315313 const auto wSearchWidth = wBoundsSearch.mMaxX - wBoundsSearch.mMinX ;
316314 const auto wSearchHeight = wBoundsSearch.mMaxY - wBoundsSearch.mMinY ;
317315 const auto wSearchArea = wSearchWidth * wSearchHeight;
318316
319- if (wWidth <= 0 || wHeight <= 0 || wIntersectionArea <= 0 || wSearchWidth <= 0 ||
317+ if (wIndexWidth <= 0 || wIndexHeight <= 0 || wIndexArea <= 0 || wSearchWidth <= 0 ||
320318 wSearchHeight <= 0 || !std::isfinite (wSearchWidth) || !std::isfinite (wSearchHeight) ||
321319 !std::isfinite (wSearchArea) || wSearchArea <= 0 ) {
322320 return 0UL ;
323321 }
324322
325323 // Approximate results size based as ratio of areas, assuming uniform distribution
326- const auto wAreaRatio = wSearchArea / wIntersectionArea;
327-
324+ const auto wAreaRatio = wSearchArea / wIndexArea;
328325 if (!std::isfinite (wAreaRatio) || wAreaRatio > 1.0 ) {
329326 return iNumItems;
330327 }
331328
332- return static_cast <size_t >(wAreaRatio * static_cast < double >(iNumItems ));
329+ return iNumItems * static_cast <size_t >(std::min ( 1.0 , wAreaRatio * 1.8 ));
333330}
334331
335332template <typename ArrayType>
0 commit comments