Program: 45462
Project: 45462
Buggy source:
/** 
 * Returns the distance away to play a Cell so that its horizontal bounds are entirely in-view. Takes the bounding volume of the Cell and a field- of-view of the viewer (in degrees). Assumes the bounding volume is either a sphere or box, if not, assumes it has a radius of 1.0. <p> This method assumes the Cell is rotated so that, with respect to the viewer, the +x axis is to the right, the +y axis is up, and the +z axis is towards the viewer. <p> This distance returned is at least 'minDistance' away from the viewer and at most 'maxDistance' away from the viewer. If the value for the minimum distance is -1, there is no minimum distance. If the maximum distance is -1, there is no maximum distance. Note that the maximum distance takes precendence over the minimum distance: that is, the Cell may be placed closer than the minimum distance if it exceeds the maximum distance.
 * @param bounds The bounding volume of the Cell
 * @param fieldOfView The field-of-view of the viewer (in degrees)
 * @param minDistance The minimum distance away from the viewer that thefront face of the Cell may be, or -1 for no minimum distance
 * @param maxDistance The maximum distance away from the viewer that thefront face of the Cell may be, or -1 for no maximim distance
 * @return The distance away to place the Cell so that the horizontal boundsare entirely within view.
 */
public static float getDistance(BoundingVolume bounds,float fieldOfView,float minDistance,float maxDistance){
  float alongRadius=1.0f;
  float crossRadius=1.0f;
  if (bounds instanceof BoundingSphere) {
    alongRadius=crossRadius=((BoundingSphere)bounds).radius;
  }
 else   if (bounds instanceof BoundingBox) {
    alongRadius=((BoundingBox)bounds).xExtent;
    crossRadius=((BoundingBox)bounds).zExtent;
  }
  double eyeDist=alongRadius / Math.tan(fieldOfView / 2.0);
  eyeDist+=crossRadius;
  if (minDistance != -1) {
    eyeDist=Math.max(eyeDist,minDistance);
  }
  if (maxDistance != -1) {
    eyeDist=Math.min(eyeDist,maxDistance);
  }
  return (float)eyeDist;
}

Fixed version (ground truth):
/** 
 * Returns the distance away to play a Cell so that its horizontal bounds are entirely in-view. Takes the bounding volume of the Cell and a field- of-view of the viewer (in degrees). Assumes the bounding volume is either a sphere or box, if not, assumes it has a radius of 1.0. <p> This method assumes the Cell is rotated so that, with respect to the viewer, the +x axis is to the right, the +y axis is up, and the +z axis is towards the viewer. <p> This distance returned is at least 'minDistance' away from the viewer and at most 'maxDistance' away from the viewer. If the value for the minimum distance is -1, there is no minimum distance. If the maximum distance is -1, there is no maximum distance. Note that the maximum distance takes precendence over the minimum distance: that is, the Cell may be placed closer than the minimum distance if it exceeds the maximum distance.
 * @param bounds The bounding volume of the Cell
 * @param fieldOfView The field-of-view of the viewer (in degrees)
 * @param minDistance The minimum distance away from the viewer that thefront face of the Cell may be, or -1 for no minimum distance
 * @param maxDistance The maximum distance away from the viewer that thefront face of the Cell may be, or -1 for no maximim distance
 * @return The distance away to place the Cell so that the horizontal boundsare entirely within view.
 */
public static float getDistance(BoundingVolume bounds,float fieldOfView,float minDistance,float maxDistance){
  float alongRadius=1.0f;
  float crossRadius=1.0f;
  if (bounds instanceof BoundingSphere) {
    alongRadius=crossRadius=((BoundingSphere)bounds).radius;
  }
 else   if (bounds instanceof BoundingBox) {
    alongRadius=((BoundingBox)bounds).xExtent;
    crossRadius=((BoundingBox)bounds).zExtent;
  }
  double eyeDist=alongRadius / Math.tan(Math.toRadians(fieldOfView / 2.0));
  eyeDist+=crossRadius;
  if (minDistance != -1) {
    eyeDist=Math.max(eyeDist,minDistance);
  }
  if (maxDistance != -1) {
    eyeDist=Math.min(eyeDist,maxDistance);
  }
  return (float)eyeDist;
}