42 #define PA(i,d) (pa[pidx[(i)]][(d)])
44 #define PP(i) (pa[pidx[(i)]])
59 for (
int d = 0; d <
dim; d++) {
60 length = bnd_box.
hi[d] - bnd_box.
lo[d];
61 if (length < min_length) min_length = length;
62 if (length > max_length) max_length = length;
64 return max_length/min_length;
80 for (
int d = 0; d <
dim; d++) {
83 for (
int i = 0; i < n; i++) {
84 if (
PA(i,d) < lo_bnd) lo_bnd =
PA(i,d);
85 else if (
PA(i,d) > hi_bnd) hi_bnd =
PA(i,d);
104 for (d = 0; d <
dim; d++) {
110 for (d = 0; d <
dim; d++) {
112 ANNcoord half_diff = (max_len - len) / 2;
113 bnds.
lo[d] -= half_diff;
114 bnds.
hi[d] += half_diff;
133 for (
register int d = 0; d <
dim; d++) {
138 else if (q[d] > hi[d]) {
162 for (
int i = 1; i < n; i++) {
164 if (c < min) min = c;
165 else if (c > max) max = c;
180 for (
int i = 1; i < n; i++) {
182 if (c < min) min = c;
183 else if (c > max) max = c;
198 for (
int d = 0; d <
dim; d++) {
228 #define PASWAP(a,b) { int tmp = pidx[a]; pidx[a] = pidx[b]; pidx[b] = tmp; }
241 register int i = (r+l)/2;
244 if (
PA(i,d) >
PA(r,d))
252 while (
PA(++i,d) < c) ;
253 while (
PA(--k,d) > c) ;
254 if (i < k)
PASWAP(i,k)
else break;
258 if (k > n_lo) r = k-1;
259 else if (k < n_lo) l = k+1;
265 for (
int i = 1; i < n_lo; i++) {
274 cv = (
PA(n_lo-1,d) +
PA(n_lo,d))/2.0;
303 while (l < n &&
PA(l,d) < cv) l++;
304 while (r >= 0 &&
PA(r,d) >= cv) r--;
312 while (l < n &&
PA(l,d) <= cv) l++;
313 while (r >= br1 &&
PA(r,d) > cv) r--;
343 while (l < n && box.
inside(dim,
PP(l))) l++;
344 while (r >= 0 && !box.
inside(dim,
PP(r))) r--;
368 for(
int i = 0; i < n; i++) {
369 if (
PA(i,d) < cv) n_lo++;
393 for (i = 0; i <
dim; i++) {
394 if (inner_box.
lo[i] > bnd_box.
lo[i])
396 if (inner_box.
hi[i] < bnd_box.
hi[i])
403 for (i = 0; i <
dim; i++) {
404 if (inner_box.
lo[i] > bnd_box.
lo[i]) {
406 bnds[j].
cv = inner_box.
lo[i];
410 if (inner_box.
hi[i] < bnd_box.
hi[i]) {
412 bnds[j].
cv = inner_box.
hi[i];
435 for (
int i = 0; i < n_bnds; i++) {
void annMinMax(ANNpointArray pa, ANNidxArray pidx, int n, int d, ANNcoord &min, ANNcoord &max)
void annEnclCube(ANNpointArray pa, ANNidxArray pidx, int n, int dim, ANNorthRect &bnds)
int annSplitBalance(ANNpointArray pa, ANNidxArray pidx, int n, int d, ANNcoord cv)
ANNbool inside(int dim, ANNpoint p)
void annAssignRect(int dim, ANNorthRect &dest, const ANNorthRect &source)
ANNcoord annSpread(ANNpointArray pa, ANNidxArray pidx, int n, int d)
void project(ANNpoint &q)
void annMedianSplit(ANNpointArray pa, ANNidxArray pidx, int n, int d, ANNcoord &cv, int n_lo)
double annAspectRatio(int dim, const ANNorthRect &bnd_box)
void annBox2Bnds(const ANNorthRect &inner_box, const ANNorthRect &bnd_box, int dim, int &n_bnds, ANNorthHSArray &bnds)
int annMaxSpread(ANNpointArray pa, ANNidxArray pidx, int n, int dim)
void annEnclRect(ANNpointArray pa, ANNidxArray pidx, int n, int dim, ANNorthRect &bnds)
void annPlaneSplit(ANNpointArray pa, ANNidxArray pidx, int n, int d, ANNcoord cv, int &br1, int &br2)
void annBnds2Box(const ANNorthRect &bnd_box, int dim, int n_bnds, ANNorthHSArray bnds, ANNorthRect &inner_box)
ANNdist annBoxDistance(const ANNpoint q, const ANNpoint lo, const ANNpoint hi, int dim)
void annBoxSplit(ANNpointArray pa, ANNidxArray pidx, int n, int dim, ANNorthRect &box, int &n_in)