Example #1
0
 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();
 }
        /**
         * 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;
        }