From 3f048c56b628f96f912aac0d27d7e56a3be4f63b Mon Sep 17 00:00:00 2001 From: Pascal Muetschard Date: Tue, 29 Aug 2017 10:11:11 -0700 Subject: [PATCH] Bounding box fixes. --- .../com/google/gapid/glviewer/Geometry.java | 5 +--- .../gapid/glviewer/geo/BoundingBox.java | 26 +++++++------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/gapic/src/main/com/google/gapid/glviewer/Geometry.java b/gapic/src/main/com/google/gapid/glviewer/Geometry.java index b2ccbd39d0..485c177af7 100644 --- a/gapic/src/main/com/google/gapid/glviewer/Geometry.java +++ b/gapic/src/main/com/google/gapid/glviewer/Geometry.java @@ -44,10 +44,7 @@ public Geometry(Model model, boolean zUp) { } public BoundingBox getBounds() { - if (model != null) { - return model.getBounds(); - } - return BoundingBox.INVALID; + return (model == null) ? new BoundingBox() : model.getBounds(); } public Renderable asRenderable(DisplayMode displayMode) { diff --git a/gapic/src/main/com/google/gapid/glviewer/geo/BoundingBox.java b/gapic/src/main/com/google/gapid/glviewer/geo/BoundingBox.java index 991f48deed..ee03c5e8c0 100644 --- a/gapic/src/main/com/google/gapid/glviewer/geo/BoundingBox.java +++ b/gapic/src/main/com/google/gapid/glviewer/geo/BoundingBox.java @@ -24,13 +24,21 @@ * Bounding box of a model aligned to the standard cartesian directions. */ public class BoundingBox { - public static final BoundingBox INVALID = new BoundingBox(); - public final double[] min = new double[] { Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY }; public final double[] max = new double[] { Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY }; + public BoundingBox() { + } + + public BoundingBox copy() { + BoundingBox r = new BoundingBox(); + System.arraycopy(min, 0, r.min, 0, 3); + System.arraycopy(max, 0, r.max, 0, 3); + return r; + } + public void add(VecD vec) { add(vec.x, vec.y, vec.z); } @@ -40,20 +48,6 @@ public void add(double x, double y, double z) { VecD.max(max, x, y, z); } - public BoundingBox() { - this(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE, - Double.MIN_VALUE, Double.MIN_VALUE, Double.MIN_VALUE); - } - - public BoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - min[0] = minX; - min[1] = minY; - min[2] = minZ; - max[0] = maxX; - max[1] = maxY; - max[2] = maxZ; - } - /** * @return a matrix that will center the model at the origin and scale it to the given size. */