/**
   * <code>mergeLocal</code> combines this sphere with a second bounding sphere locally. Altering
   * this sphere to contain both the original and the additional sphere volumes;
   *
   * @param volume the sphere to combine with this sphere.
   * @return this
   */
  public BoundingVolume mergeLocal(BoundingVolume volume) {
    if (volume == null) {
      return this;
    }

    switch (volume.getType()) {
      case Sphere:
        {
          BoundingSphere sphere = (BoundingSphere) volume;
          float temp_radius = sphere.getRadius();
          Vector3f temp_center = sphere.center;
          return merge(temp_radius, temp_center, this);
        }

      case AABB:
        {
          BoundingBox box = (BoundingBox) volume;
          Vector3f radVect = Vector3f.newInstance();
          radVect.set(box.xExtent, box.yExtent, box.zExtent);
          Vector3f temp_center = box.center;
          float len = radVect.length();
          Vector3f.recycle(radVect);
          return merge(len, temp_center, this);
        }

        // case OBB: {
        // return mergeOBB((OrientedBoundingBox) volume);
        // }
      default:
        return null;
    }
  }
  /**
   * <code>merge</code> combines this sphere with a second bounding sphere. This new sphere contains
   * both bounding spheres and is returned.
   *
   * @param volume the sphere to combine with this sphere.
   * @return a new sphere
   */
  public BoundingVolume merge(BoundingVolume volume) {
    if (volume == null) {
      return this;
    }

    switch (volume.getType()) {
      case Sphere:
        {
          BoundingSphere sphere = (BoundingSphere) volume;
          float temp_radius = sphere.getRadius();
          Vector3f temp_center = sphere.center;
          BoundingSphere rVal = new BoundingSphere();
          return merge(temp_radius, temp_center, rVal);
        }

      case AABB:
        {
          BoundingBox box = (BoundingBox) volume;
          Vector3f radVect = new Vector3f(box.xExtent, box.yExtent, box.zExtent);
          Vector3f temp_center = box.center;
          BoundingSphere rVal = new BoundingSphere();
          return merge(radVect.length(), temp_center, rVal);
        }

        // case OBB: {
        // OrientedBoundingBox box = (OrientedBoundingBox) volume;
        // BoundingSphere rVal = (BoundingSphere) this.clone(null);
        // return rVal.mergeOBB(box);
        // }
      default:
        return null;
    }
  }
  /*
   * (non-Javadoc)
   * @see com.jme.bounding.BoundingVolume#intersectsSphere(com.jme.bounding.BoundingSphere)
   */
  public boolean intersectsSphere(BoundingSphere bs) {
    assert Vector3f.isValidVector(center) && Vector3f.isValidVector(bs.center);

    Vector3f vect1 = Vector3f.newInstance();
    Vector3f diff = center.subtract(bs.center, vect1);
    float rsum = getRadius() + bs.getRadius();
    boolean eq = (diff.dot(diff) <= rsum * rsum);
    Vector3f.recycle(vect1);
    return eq;
  }