ANNdist annBoxDistance( // compute distance from point to box const ANNpoint q, // the point const ANNpoint lo, // low point of box const ANNpoint hi, // high point of box int dim) // dimension of space { //register ANNdist dist = 0.0; // sum of squared distances ANNdist dist = 0.0; // sum of squared distances //register ANNdist t; ANNdist t; //for (register int d = 0; d < dim; d++) { for (int d = 0; d < dim; d++) { if (q[d] < lo[d]) { // q is left of box t = ANNdist(lo[d]) - ANNdist(q[d]); dist = ANN_SUM(dist, ANN_POW(t)); } else if (q[d] > hi[d]) { // q is right of box t = ANNdist(q[d]) - ANNdist(hi[d]); dist = ANN_SUM(dist, ANN_POW(t)); } } ANN_FLOP(4*dim) // increment floating op count return dist; }
ANNdist annDist( // interpoint squared distance int dim, ANNpoint p, ANNpoint q) { register int d; register ANNcoord diff; register ANNcoord dist; dist = 0; for (d = 0; d < dim; d++) { diff = p[d] - q[d]; dist = ANN_SUM(dist, ANN_POW(diff)); } return dist; }