85 HyperRect(
int dim,
const double *min,
const double *max)
88 fMin =
new double[fDim];
89 fMax =
new double[fDim];
90 size_t size = fDim *
sizeof(double);
91 memcpy(fMin, min, size);
92 memcpy(fMax, max, size);
105 fMin =
new double[fDim];
106 fMax =
new double[fDim];
107 size_t size = fDim *
sizeof(double);
108 memcpy(fMin, rect.
fMin, size);
109 memcpy(fMax, rect.
fMax, size);
116 for (i=0; i < fDim; i++)
118 if (pos[i] < fMin[i])
122 if (pos[i] > fMax[i])
133 for (
int i=0; i < fDim; i++)
135 if (pos[i] < fMin[i])
137 result +=
sqr(fMin[i] - pos[i]);
139 else if (pos[i] > fMax[i])
141 result +=
sqr(fMax[i] - pos[i]);
144 if(result >= *bestmatch)
return false ;
162 if(
this == &rhs)
return *
this;
180 if(fRoot) __Clear_Rec(fRoot);
226 fRoot =
new G4KDNode(
this,pos,data,0, 0);
233 if((node=fRoot->
Insert(pos, data)))
267 int ret(-1), added_res(0);
269 if(node->
GetData() && node != source_node)
271 bool do_break = false ;
273 for(
int i=0; i<fDim; i++)
276 if(dist_sq > range_sq)
282 if(!do_break && dist_sq <= range_sq)
284 list.
Insert(dist_sq, node);
291 ret = __NearestInRange(dx <= 0.0 ? node->GetLeft() : node->
GetRight(), pos, range_sq, range, list, ordered, source_node);
292 if(ret >= 0 && fabs(dx) <= range)
295 ret = __NearestInRange(dx <= 0.0 ? node->GetRight() : node->
GetLeft(), pos, range_sq, range, list, ordered, source_node);
313 double dummy(0.), dist_sq(-1.);
314 G4KDNode *nearer_subtree(0), *farther_subtree (0);
315 double *nearer_hyperrect_coord(0),*farther_hyperrect_coord(0);
321 nearer_subtree = node->
GetLeft();
324 nearer_hyperrect_coord = rect->
GetMax() +
dir;
325 farther_hyperrect_coord = rect->
GetMin() +
dir;
330 farther_subtree = node->
GetLeft();
331 nearer_hyperrect_coord = rect->
GetMin() +
dir;
332 farther_hyperrect_coord = rect->
GetMax() +
dir;
338 dummy = *nearer_hyperrect_coord;
341 __NearestToPosition(nearer_subtree, pos, result, result_dist_sq, rect);
343 *nearer_hyperrect_coord = dummy;
351 bool do_break = false ;
352 for(i=0; i < fDim; i++)
355 if(dist_sq > *result_dist_sq)
361 if (!do_break && dist_sq < *result_dist_sq)
364 *result_dist_sq = dist_sq;
371 dummy = *farther_hyperrect_coord;
379 __NearestToPosition(farther_subtree, pos, result, result_dist_sq, rect);
382 *farther_hyperrect_coord = dummy;
390 if (!fRect)
return 0;
400 __NearestToPosition(fRoot, pos, result, &dist_sq, newrect);
409 rset->Insert(dist_sq, result);
421 const double *pos, std::vector<G4KDNode*>& result,
double *result_dist_sq,
425 double dummy, dist_sq;
426 G4KDNode *nearer_subtree (0), *farther_subtree (0);
427 double *nearer_hyperrect_coord (0), *farther_hyperrect_coord (0);
433 nearer_subtree = node->
GetLeft();
435 nearer_hyperrect_coord = rect->
GetMax() +
dir;
436 farther_hyperrect_coord = rect->
GetMin() +
dir;
441 farther_subtree = node->
GetLeft();
442 nearer_hyperrect_coord = rect->
GetMin() +
dir;
443 farther_hyperrect_coord = rect->
GetMax() +
dir;
449 dummy = *nearer_hyperrect_coord;
452 __NearestToNode(source_node, nearer_subtree, pos, result, result_dist_sq, rect, nbresult);
454 *nearer_hyperrect_coord = dummy;
459 if(node->
GetData() && node != source_node)
462 bool do_break =
false;
463 for(
int i=0; i < fDim; i++)
466 if(dist_sq > *result_dist_sq)
474 if (dist_sq < *result_dist_sq)
478 result.push_back(node);
479 *result_dist_sq = dist_sq;
481 else if(dist_sq == *result_dist_sq)
483 result.push_back(node);
492 dummy = *farther_hyperrect_coord;
501 __NearestToNode(source_node, farther_subtree, pos, result, result_dist_sq, rect, nbresult);
504 *farther_hyperrect_coord = dummy;
518 std::vector<G4KDNode*> result;
527 __NearestToNode(node, fRoot, pos, result, &dist_sq, newrect, nbresult);
539 rset->Insert(dist_sq, result[j]);
565 const double range_sq =
sqr(range) ;
568 if((ret = __NearestInRange(fRoot, pos, range_sq, range, *(rset()), 0)) == -1)
587 return NearestInRange(buf, range);
597 const double range_sq =
sqr(range) ;
599 if((ret = __NearestInRange(fRoot, node->
GetPosition(), range_sq, range, *rset, 0, node)) == -1)