Skip to content

Commit

Permalink
Bounding box fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuetschard committed Aug 29, 2017
1 parent 6f10e95 commit 3f048c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
5 changes: 1 addition & 4 deletions gapic/src/main/com/google/gapid/glviewer/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 10 additions & 16 deletions gapic/src/main/com/google/gapid/glviewer/geo/BoundingBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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.
*/
Expand Down

0 comments on commit 3f048c5

Please sign in to comment.