src/classify/kdtree.cpp
float DistanceSquared(int k, PARAM_DESC *dim, float p1[], float p2[]) {
  float total_distance = 0;

  for (; k > 0; k--, p1++, p2++, dim++) {
    if (dim->NonEssential) {
      continue;
    }

    float dimension_distance = *p1 - *p2;

    /* if this dimension is circular - check wraparound distance */
    if (dim->Circular) {
      dimension_distance = Magnitude(dimension_distance);
      float wrap_distance = dim->Max - dim->Min - dimension_distance;
      dimension_distance = std::min(dimension_distance, wrap_distance);
    }

    total_distance += dimension_distance * dimension_distance;
  }
  return total_distance;
}
/*---------------------------------------------------------------------------*/
/**
 *Returns the Euclidean distance squared between p1 and p2 for all essential
 * dimensions.
 * @param k      keys are in k-space
 * @param dim    dimension descriptions (essential, circular, etc)
 * @param p1,p2  two different points in K-D space
 */
Returns the Euclidean distance squared between p1 and p2 for all essential
dimensions.
@param k      keys are in k-space
@param dim    dimension descriptions (essential, circular, etc)
@param p1,p2  two different points in K-D space
Returns the Euclidean distance squared between p1 and p2 for all essential dimensions . @param k keys are in k - space @param dim dimension descriptions ( essential circular etc ) @param p1 p2 two different points in K - D space
float DistanceSquared(int k, PARAM_DESC *dim, float p1[], float p2[]) {
  float total_distance = 0;
  for (; k > 0; k--, p1++, p2++, dim++) {
    if (dim->NonEssential) {
      continue;
    }
    float dimension_distance = *p1 - *p2;
    if (dim->Circular) {
      dimension_distance = Magnitude(dimension_distance);
      float wrap_distance = dim->Max - dim->Min - dimension_distance;
      dimension_distance = std::min(dimension_distance, wrap_distance);
    }
    total_distance += dimension_distance * dimension_distance;
  }
  return total_distance;
}
float DistanceSquared ( int k , PARAM_DESC * dim , float p1 [ ] , float p2 [ ] ) { float total_distance = 0 ; for ( ; k > 0 ; k -- , p1 ++ , p2 ++ , dim ++ ) { if ( dim -> NonEssential ) { continue ; } float dimension_distance = * p1 - * p2 ; if ( dim -> Circular ) { dimension_distance = Magnitude ( dimension_distance ) ; float wrap_distance = dim -> Max - dim -> Min - dimension_distance ; dimension_distance = std :: min ( dimension_distance , wrap_distance ) ; } total_distance += dimension_distance * dimension_distance ; } return total_distance ; }
Returns the Euclidean distance squared between p1 and p2 for all essential
 dimensions.
Returns the Euclidean distance squared between p1 and p2 for all essential dimensions .
/* if this dimension is circular - check wraparound distance */