BoundingBox { public double distanceTo(Vec3 point) { if (point == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "BoundingBox", "distanceTo", "missingPoint")); } double minDist2 = Double.POSITIVE_INFINITY; double dist2 = this.center.distanceToSquared(point); if (minDist2 > dist2) { minDist2 = dist2; } dist2 = this.bottomCenter.distanceToSquared(point); if (minDist2 > dist2) { minDist2 = dist2; } dist2 = this.topCenter.distanceToSquared(point); if (minDist2 > dist2) { minDist2 = dist2; } this.endPoint1.x = this.center.x - (0.5 * this.s.x); this.endPoint1.y = this.center.y - (0.5 * this.s.y); this.endPoint1.z = this.center.z - (0.5 * this.s.z); dist2 = this.endPoint1.distanceToSquared(point); if (minDist2 > dist2) { minDist2 = dist2; } this.endPoint1.x = this.center.x + (0.5 * this.s.x); this.endPoint1.y = this.center.y + (0.5 * this.s.y); this.endPoint1.z = this.center.z + (0.5 * this.s.z); dist2 = this.endPoint1.distanceToSquared(point); if (minDist2 > dist2) { minDist2 = dist2; } return Math.sqrt(minDist2); } BoundingBox(); @Override String toString(); boolean isUnitBox(); BoundingBox setToUnitBox(); BoundingBox setToPoints(float[] array, int count, int stride); BoundingBox setToSector(Sector sector, Globe globe, float minHeight, float maxHeight); BoundingBox translate(double x, double y, double z); double distanceTo(Vec3 point); boolean intersectsFrustum(Frustum frustum);  }
@Test public void testDistanceTo() throws Exception { BoundingBox boundingBox = new BoundingBox(); double radius = globe.getEquatorialRadius(); float minElevation = 0; float maxElevation = 1000; Sector sector = Sector.fromDegrees(-0.5, -0.5, 1d, 1d); boundingBox.setToSector(sector, globe, minElevation, maxElevation); Vec3 point = globe.geographicToCartesian(0, 0, 0, new Vec3()); double result = boundingBox.distanceTo(point); assertEquals(boundingBox.center.z - radius, result, 1e-3); }