public void put(Vector3 point) {
   if (depth == 0) {
     this.point = point;
   } else if (point.x < position.x
       || point.x > position.x + range
       || point.y < position.y
       || point.y > position.y + range
       || point.z < position.z
       || point.z > position.z + range) {
     throw new IllegalArgumentException(
         "Outside of range: "
             + point.toString()
             + " does not belong to "
             + position.toString()
             + " with range "
             + range);
   } else {
     if (point.x < position.x + halfRange) {
       if (point.y < position.y + halfRange) {
         if (point.z < position.z + halfRange) {
           put(point, 0, position.x, position.y, position.z);
         } else {
           put(point, 1, position.x, position.y, position.z + halfRange);
         }
       } else {
         if (point.z < position.z + halfRange) {
           put(point, 2, position.x, position.y + halfRange, position.z);
         } else {
           put(point, 3, position.x, position.y + halfRange, position.z + halfRange);
         }
       }
     } else {
       if (point.y < position.y + halfRange) {
         if (point.z < position.z + halfRange) {
           put(point, 4, position.x + halfRange, position.y, position.z);
         } else {
           put(point, 5, position.x + halfRange, position.y, position.z + halfRange);
         }
       } else {
         if (point.z < position.z + halfRange) {
           put(point, 6, position.x + halfRange, position.y + halfRange, position.z);
         } else {
           put(point, 7, position.x + halfRange, position.y + halfRange, position.z + halfRange);
         }
       }
     }
   }
 }
 private Vector3 findPointNear(Vector3 searchPosition) {
   if (depth == 0) {
     return point;
   } else if (searchPosition.x < position.x
       || searchPosition.x > position.x + range
       || searchPosition.y < position.y
       || searchPosition.y > position.y + range
       || searchPosition.z < position.z
       || searchPosition.z > position.z + range) {
     throw new IllegalArgumentException(
         "Outside of range: "
             + searchPosition.toString()
             + " does not belong to "
             + position.toString()
             + " with range "
             + range);
   } else {
     if (searchPosition.x < position.x + halfRange) {
       if (searchPosition.y < position.y + halfRange) {
         if (searchPosition.z < position.z + halfRange) {
           return findPointNear(searchPosition, 0);
         } else {
           return findPointNear(searchPosition, 1);
         }
       } else {
         if (searchPosition.z < position.z + halfRange) {
           return findPointNear(searchPosition, 2);
         } else {
           return findPointNear(searchPosition, 3);
         }
       }
     } else {
       if (searchPosition.y < position.y + halfRange) {
         if (searchPosition.z < position.z + halfRange) {
           return findPointNear(searchPosition, 4);
         } else {
           return findPointNear(searchPosition, 5);
         }
       } else {
         if (searchPosition.z < position.z + halfRange) {
           return findPointNear(searchPosition, 6);
         } else {
           return findPointNear(searchPosition, 7);
         }
       }
     }
   }
 }