/** * checks one tuple for distance * @param t * @return boolean */ private bool isWithinRadius(Tuple t) { float dist2; float distT; distT = t.getDimensionValue(0) - centerValues[0]; if (tHemisphere && distT < 0) { return(false); } dist2 = distT * distT; if (dist2 > radius2) { return(false); } int dim = bspt.dimMax - 1; do { distT = t.getDimensionValue(dim) - centerValues[dim]; dist2 += distT * distT; if (dist2 > radius2) { return(false); } }while (--dim > 0); this._foundDistance2 = dist2; return(true); }
public override Element addTuple(int level, Tuple tuple) { float dimValue = tuple.getDimensionValue(dim); ++count; bool addLeft; if (dimValue < maxLeft) { addLeft = true; } else if (dimValue > minRight) { addLeft = false; } else if (dimValue == maxLeft) { if (dimValue == minRight) { if (eleLeft.count < eleRight.count) addLeft = true; else addLeft = false; } else addLeft = true; } else if (dimValue == minRight) addLeft = false; else { if (eleLeft.count < eleRight.count) addLeft = true; else addLeft = false; } if (addLeft) { if (dimValue < minLeft) minLeft = dimValue; else if (dimValue > maxLeft) maxLeft = dimValue; eleLeft = eleLeft.addTuple(level + 1, tuple); } else { if (dimValue < minRight) minRight = dimValue; else if (dimValue > maxRight) maxRight = dimValue; eleRight = eleRight.addTuple(level + 1, tuple); } return this; }
/** * initialize to return all points within the sphere defined * by center and radius * * @param center * @param radius */ public void initialize(Tuple center, float radius) { this.center = center; this.radius = radius; this.radius2 = radius * radius; this.tHemisphere = false; for (int dim = bspt.dimMax; --dim >= 0; ) centerValues[dim] = center.getDimensionValue(dim); leaf = null; stack[0] = bspt.eleRoot; sp = 1; findLeftLeaf(); }
/** * initialize to return all points within the sphere defined * by center and radius * * @param center * @param radius */ public void initialize(Tuple center, float radius) { this.center = center; this.radius = radius; this.radius2 = radius * radius; this.tHemisphere = false; for (int dim = bspt.dimMax; --dim >= 0;) { centerValues[dim] = center.getDimensionValue(dim); } leaf = null; stack[0] = bspt.eleRoot; sp = 1; findLeftLeaf(); }
public void sort(int dim) { for (int i = count; --i > 0;) { // this is > not >= Tuple champion = tuples[i]; float championValue = champion.getDimensionValue(dim); for (int j = i; --j >= 0;) { Tuple challenger = tuples[j]; float challengerValue = challenger.getDimensionValue(dim); if (challengerValue > championValue) { tuples[i] = challenger; tuples[j] = champion; champion = challenger; championValue = challengerValue; } } } }
/** * checks one tuple for distance * @param t * @return boolean */ private bool isWithinRadius(Tuple t) { float dist2; float distT; distT = t.getDimensionValue(0) - centerValues[0]; if (tHemisphere && distT < 0) return false; dist2 = distT * distT; if (dist2 > radius2) return false; int dim = bspt.dimMax - 1; do { distT = t.getDimensionValue(dim) - centerValues[dim]; dist2 += distT * distT; if (dist2 > radius2) return false; } while (--dim > 0); this._foundDistance2 = dist2; return true; }
public override Element addTuple(int level, Tuple tuple) { float dimValue = tuple.getDimensionValue(dim); ++count; bool addLeft; if (dimValue < maxLeft) { addLeft = true; } else if (dimValue > minRight) { addLeft = false; } else if (dimValue == maxLeft) { if (dimValue == minRight) { if (eleLeft.count < eleRight.count) { addLeft = true; } else { addLeft = false; } } else { addLeft = true; } } else if (dimValue == minRight) { addLeft = false; } else { if (eleLeft.count < eleRight.count) { addLeft = true; } else { addLeft = false; } } if (addLeft) { if (dimValue < minLeft) { minLeft = dimValue; } else if (dimValue > maxLeft) { maxLeft = dimValue; } eleLeft = eleLeft.addTuple(level + 1, tuple); } else { if (dimValue < minRight) { minRight = dimValue; } else if (dimValue > maxRight) { maxRight = dimValue; } eleRight = eleRight.addTuple(level + 1, tuple); } return(this); }