From 4d3ac0ff00d0fc7653f9c2b746d1012e81929f2e Mon Sep 17 00:00:00 2001 From: Garry Boyer Date: Sat, 28 Jul 2007 03:46:02 +0000 Subject: [PATCH] hi --- fastlib/u/garryb/nbr/allnn.cc | 2 +- fastlib/u/garryb/nbr/spbounds.h | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/fastlib/u/garryb/nbr/allnn.cc b/fastlib/u/garryb/nbr/allnn.cc index 36ed23981b..13daac6704 100644 --- a/fastlib/u/garryb/nbr/allnn.cc +++ b/fastlib/u/garryb/nbr/allnn.cc @@ -218,7 +218,7 @@ class Allnn { */ static double Heuristic(const Param& param, const QNode& q_node, const RNode& r_node, const Delta& delta) { - return q_node.bound().MidDistanceSq(r_node.bound()); + return r_node.bound().MinToMidSq(q_node.bound()); } }; }; diff --git a/fastlib/u/garryb/nbr/spbounds.h b/fastlib/u/garryb/nbr/spbounds.h index 020aa7ac15..aeae062433 100644 --- a/fastlib/u/garryb/nbr/spbounds.h +++ b/fastlib/u/garryb/nbr/spbounds.h @@ -554,6 +554,40 @@ class SpHrectBound { return math::Pow<2, t_pow>(sumsq) / 4; } + /** + * Calculates closest-to-their-midpoint bounding box distance, + * i.e. calculates their midpoint and finds the minimum box-to-point + * distance. + * + * Equivalent to: + * + * other.CalcMidpoint(&other_midpoint) + * return MinDistanceSqToPoint(other_midpoint) + * + */ + double MinToMidSq(const SpHrectBound& other) const { + double sumsq = 0; + const SpRange *a = this->bounds_; + const SpRange *b = other.bounds_; + + DEBUG_ASSERT(dim_ == other.dim_); + + for (index_t d = 0; d < dim_; d++) { + double v = b->mid(); + double v1 = a->lo - v; + double v2 = v - a->hi; + + v = (v1 + fabs(v1)) + (v2 + fabs(v2)); + + a++; + b++; + + sumsq += math::Pow(v); + } + + return math::Pow<2, t_pow>(sumsq) / 4; + } + /** * Calculates maximum bound-to-point squared distance, * to the specified power.