Skip to content

Commit

Permalink
Rectangle use accessors too.
Browse files Browse the repository at this point in the history
  • Loading branch information
rainwoodman committed Jan 8, 2017
1 parent 2e5e6e6 commit ca8a9d1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
8 changes: 4 additions & 4 deletions scipy/spatial/ckdtree/src/distance.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ struct Dist1D {
/* Compute the minimum/maximum distance along dimension k between points in
* two hyperrectangles.
*/
*min = dmax(0, dmax(rect1.mins[k] - rect2.maxes[k],
rect2.mins[k] - rect1.maxes[k]));
*max = dmax(rect1.maxes[k] - rect2.mins[k],
rect2.maxes[k] - rect1.mins[k]);
*min = dmax(0, dmax(rect1.mins()[k] - rect2.maxes()[k],
rect2.mins()[k] - rect1.maxes()[k]));
*max = dmax(rect1.maxes()[k] - rect2.mins()[k],
rect2.maxes()[k] - rect1.mins()[k]);
}

static inline npy_float64
Expand Down
4 changes: 2 additions & 2 deletions scipy/spatial/ckdtree/src/distance_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ struct BoxDist1D {
/* Compute the minimum/maximum distance along dimension k between points in
* two hyperrectangles.
*/
_interval_interval_1d(rect1.mins[k] - rect2.maxes[k],
rect1.maxes[k] - rect2.mins[k], min, max,
_interval_interval_1d(rect1.mins()[k] - rect2.maxes()[k],
rect1.maxes()[k] - rect2.mins()[k], min, max,
tree->raw_boxsize_data[k], tree->raw_boxsize_data[k + rect1.m]);
}

Expand Down
4 changes: 2 additions & 2 deletions scipy/spatial/ckdtree/src/query_ball_point.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ traverse_checking(const ckdtree *self,
lnode = node;
const npy_float64 p = tracker->p;
const npy_float64 tub = tracker->upper_bound;
const npy_float64 *tpt = tracker->rect1.mins;
const npy_float64 *tpt = tracker->rect1.mins();
const npy_float64 *data = self->raw_data;
const npy_intp *indices = self->raw_indices;
const npy_intp m = self->m;
Expand Down Expand Up @@ -127,7 +127,7 @@ query_ball_point(const ckdtree *self, const npy_float64 *x,
Rectangle point(m, x + i * m, x + i * m);
int j;
for(j=0; j<m; ++j) {
point.maxes[j] = point.mins[j] = _wrap(point.mins[j], self->raw_boxsize_data[j]);
point.maxes()[j] = point.mins()[j] = _wrap(point.mins()[j], self->raw_boxsize_data[j]);
}
HANDLE(NPY_LIKELY(p == 2), BoxMinkowskiDistP2)
HANDLE(p == 1, BoxMinkowskiDistP1)
Expand Down
43 changes: 19 additions & 24 deletions scipy/spatial/ckdtree/src/rectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,27 @@ struct Rectangle {

const npy_intp m;

std::vector<npy_float64> buf;

npy_float64 * maxes;
npy_float64 * mins;
npy_float64 * side_distances;
/* the last const is to allow const Rectangle to use these functions;
* also notice we had to mark buf mutable to avoid writing non const version
* of the same accessors. */
npy_float64 * const maxes() const { return &buf[0]; }
npy_float64 * const mins() const { return &buf[0] + m; }
npy_float64 * const side_distances() const { return &buf[0] + m + m; }

Rectangle(const npy_intp _m,
const npy_float64 *_mins,
const npy_float64 *_maxes) : m(_m), buf(3 * m) {

/* copy array data */
mins = &buf[0];
maxes = &buf[m];
side_distances = &buf[2 * m];

/* FIXME: use std::vector ? */
std::memcpy((void*)mins, (void*)_mins, m*sizeof(npy_float64));
std::memcpy((void*)maxes, (void*)_maxes, m*sizeof(npy_float64));
std::memcpy((void*)mins(), (void*)_mins, m*sizeof(npy_float64));
std::memcpy((void*)maxes(), (void*)_maxes, m*sizeof(npy_float64));
};

Rectangle(const Rectangle& rect) : m(rect.m), buf(rect.buf) {
mins = &buf[0];
maxes = &buf[m];
side_distances = &buf[2 * m];
};
Rectangle(const Rectangle& rect) : m(rect.m), buf(rect.buf) {};

private:
mutable std::vector<npy_float64> buf;
};

#include "ckdtree_methods.h"
Expand Down Expand Up @@ -191,8 +186,8 @@ template<typename MinMaxDist>
item->split_dim = split_dim;
item->min_distance = min_distance;
item->max_distance = max_distance;
item->min_along_dim = rect->mins[split_dim];
item->max_along_dim = rect->maxes[split_dim];
item->min_along_dim = rect->mins()[split_dim];
item->max_along_dim = rect->maxes()[split_dim];

/* update min/max distances */
npy_float64 min, max;
Expand All @@ -203,9 +198,9 @@ template<typename MinMaxDist>
max_distance -= max;

if (direction == LESS)
rect->maxes[split_dim] = split_val;
rect->maxes()[split_dim] = split_val;
else
rect->mins[split_dim] = split_val;
rect->mins()[split_dim] = split_val;

MinMaxDist::interval_interval_p(tree, rect1, rect2, split_dim, p, &min, &max);

Expand Down Expand Up @@ -239,12 +234,12 @@ template<typename MinMaxDist>
max_distance = item->max_distance;

if (item->which == 1) {
rect1.mins[item->split_dim] = item->min_along_dim;
rect1.maxes[item->split_dim] = item->max_along_dim;
rect1.mins()[item->split_dim] = item->min_along_dim;
rect1.maxes()[item->split_dim] = item->max_along_dim;
}
else {
rect2.mins[item->split_dim] = item->min_along_dim;
rect2.maxes[item->split_dim] = item->max_along_dim;
rect2.mins()[item->split_dim] = item->min_along_dim;
rect2.maxes()[item->split_dim] = item->max_along_dim;
}
};

Expand Down

0 comments on commit ca8a9d1

Please sign in to comment.