diff --git a/fastlib2/fastlib/tree/bounds.h b/fastlib2/fastlib/tree/bounds.h index 0b595bb167..058077ec85 100644 --- a/fastlib2/fastlib/tree/bounds.h +++ b/fastlib2/fastlib/tree/bounds.h @@ -33,10 +33,10 @@ class DHrectBound { DRange *bounds_; index_t dim_; - OBJECT_TRAVERSAL(DHrectBound) { - OT_OBJ(dim_); - OT_ALLOC(bounds_, dim_); - }; + OT_DEF(DHrectBound) { + OT_MY_OBJECT(dim_); + OT_MALLOC_ARRAY(bounds_, dim_); + } public: /** @@ -85,18 +85,7 @@ class DHrectBound { DEBUG_BOUNDS(i, dim_); return bounds_[i]; } - - /** - * Calculates the maximum distance within the rectangle - */ - double CalculateMaxDistanceSq() const { - double max_distance=0; - for (index_t i = 0; i < dim_; i++) { - max_distance+=math::Sqr(bounds_[i].width()); - } - return max_distance; - } - + /** Calculates the midpoint of the range */ void CalculateMidpoint(Vector *centroid) const { centroid->Init(dim_); @@ -104,13 +93,6 @@ class DHrectBound { (*centroid)[i] = bounds_[i].mid(); } } - /** Calculates the midpoint of the range */ - void CalculateMidpointOverwrite(Vector *centroid) const { - for (index_t i = 0; i < dim_; i++) { - (*centroid)[i] = bounds_[i].mid(); - } - } - /** * Calculates minimum bound-to-point squared distance. @@ -172,7 +154,6 @@ class DHrectBound { return math::Pow<2, t_pow>(sum) / 4; } - /** * Calcualtes minimum bound-to-bound squared distance, with @@ -188,8 +169,8 @@ class DHrectBound { //Add Debug for offset vector for (index_t d = 0; d < mdim; d++) { - double v1 = b[d].lo + offset[d] - a[d].hi; - double v2 = a[d].lo - offset[d] - b[d].lo; + double v1 = b[d].lo - offset[d] - a[d].hi; + double v2 = a[d].lo + offset[d] - b[d].lo; double v = (v1 + fabs(v1)) + (v2 + fabs(v2)); @@ -199,7 +180,7 @@ class DHrectBound { return math::Pow<2, t_pow>(sum) / 4; } - + /** * Calculates maximum bound-to-point squared distance. */ @@ -245,13 +226,37 @@ class DHrectBound { DEBUG_SAME_SIZE(dim_, other.dim_); for (index_t d = 0; d < dim_; d++) { - double v = std::max(b[d].hi + offset[d] - a[d].lo, - a[d].hi - offset[d] - b[d].lo); + double v = std::max(b[d].hi - offset[d] - a[d].lo, + a[d].hi + offset[d] - b[d].lo); sum += math::PowAbs(v); // v is non-negative } return math::Pow<2, t_pow>(sum); - } + } + + double PeriodicMinDistanceSq(const DHrectBound& other, const Vector& box_size) + const { + double sum = 0; + const DRange *a = this->bounds_; + const DRange *b = other.bounds_; + + DEBUG_SAME_SIZE(dim_, other.dim_); + + for (index_t d = 0; d < dim_; d++){ + double v = 0; + bool i,j,k,l; + i = a[d].lo < a[d].hi; + j = b[d].lo < b[d].hi; + k = a[d].hi > b[d].lo; + l = b[d].hi > a[d].lo; + v = ((i^j) & !(k | l)) * std::min(a[d].lo - b[d].hi, b[d].lo - a[d].hi); + v = v + (i & j & (k ^ l)) * std::min(a[d].lo - b[d].hi + l*box_size[d], + b[d].lo - a[d].hi + k*box_size[d]); + sum += math::PowAbs(v); + } + + return math::Pow<2, t_pow>(sum); + } /** @@ -460,9 +465,9 @@ class DBallBound { double radius_; TPoint center_; - OBJECT_TRAVERSAL(DBallBound) { - OT_OBJ(radius_); - OT_OBJ(center_); + OT_DEF(DBallBound) { + OT_MY_OBJECT(radius_); + OT_MY_OBJECT(center_); } public: @@ -497,7 +502,7 @@ class DBallBound { * is needed. */ void CalculateMidpoint(Point *centroid) const { - ot::InitCopy(center_, centroid); + ot::Copy(center_, centroid); } /**