From d75835796900cac602f7e5789601ffba0a27efe2 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 6 May 2011 14:39:17 +0200 Subject: Graph: More std. functionality (equals, clone) / Better in-place transformation (cubic -> quadratic) Impl. more of John Pritchard proposal https://github.com/syntelos/jogl/commit/05a7ec92d30e1e688b1eb7cc317cad83a0e8fd60 +++ More std. functionality (equals, deep clone) of AABBox, Vertex, Outline and OutlineShape. Simplify Vertex: - Remove 2 component constructor - Add on-curve in Vertex.Factory / Constructor - Adding equals(Object) - Remove Comparable/compareTo, since we only can make an equals statement Outline/OutlineShape: Handle dirty flag for boundary (new set/remove operation) OutlineShape: Better in-place transformation (cubic -> quadratic) --- src/jogl/classes/com/jogamp/graph/geom/AABBox.java | 66 ++++++++++++++-------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'src/jogl/classes/com/jogamp/graph/geom/AABBox.java') diff --git a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java index 7051e9110..87f084919 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java +++ b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java @@ -35,7 +35,7 @@ import com.jogamp.graph.math.VectorUtil; * right corner of the box. * */ -public class AABBox { +public class AABBox implements Cloneable { private float[] low = new float[3]; private float[] high = new float[3]; private float[] center = new float[3]; @@ -79,7 +79,7 @@ public class AABBox { } /** resets this box to the inverse low/high, allowing the next {@link #resize(float, float, float)} command to hit. */ - public void reset() { + public final void reset() { setLow(Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE); setHigh(-1*Float.MAX_VALUE,-1*Float.MAX_VALUE,-1*Float.MAX_VALUE); center[0] = 0f; @@ -90,11 +90,11 @@ public class AABBox { /** Get the max xyz-coordinates * @return a float array containing the max xyz coordinates */ - public float[] getHigh() { + public final float[] getHigh() { return high; } - private void setHigh(float hx, float hy, float hz) { + private final void setHigh(float hx, float hy, float hz) { this.high[0] = hx; this.high[1] = hy; this.high[2] = hz; @@ -103,11 +103,11 @@ public class AABBox { /** Get the min xyz-coordinates * @return a float array containing the min xyz coordinates */ - public float[] getLow() { + public final float[] getLow() { return low; } - private void setLow(float lx, float ly, float lz) { + private final void setLow(float lx, float ly, float lz) { this.low[0] = lx; this.low[1] = ly; this.low[2] = lz; @@ -116,7 +116,7 @@ public class AABBox { /** Resize the AABBox to encapsulate another AABox * @param newBox AABBox to be encapsulated in */ - public void resize(AABBox newBox) { + public final void resize(AABBox newBox) { float[] newLow = newBox.getLow(); float[] newHigh = newBox.getHigh(); @@ -139,7 +139,7 @@ public class AABBox { computeCenter(); } - private void computeCenter() { + private final void computeCenter() { center[0] = (high[0] + low[0])/2; center[1] = (high[1] + low[1])/2; center[2] = (high[2] + low[2])/2; @@ -151,7 +151,7 @@ public class AABBox { * @param y y-axis coordinate value * @param z z-axis coordinate value */ - public void resize(float x, float y, float z) { + public final void resize(float x, float y, float z) { /** test low */ if (x < low[0]) low[0] = x; @@ -171,6 +171,15 @@ public class AABBox { computeCenter(); } + /** Resize the AABBox to encapsulate the passed + * xyz-coordinates. + * @param xyz xyz-axis coordinate values + * @param offset of the array + */ + public final void resize(float[] xyz, int offset) { + resize(xyz[0+offset], xyz[1+offset], xyz[2+offset]); + } + /** Check if the x & y coordinates are bounded/contained * by this AABBox * @param x x-axis coordinate value @@ -178,7 +187,7 @@ public class AABBox { * @return true if x belong to (low.x, high.x) and * y belong to (low.y, high.y) */ - public boolean contains(float x, float y) { + public final boolean contains(float x, float y) { if(xhigh[0]){ return false; } @@ -196,7 +205,7 @@ public class AABBox { * @return true if x belong to (low.x, high.x) and * y belong to (low.y, high.y) and z belong to (low.z, high.z) */ - public boolean contains(float x, float y, float z) { + public final boolean contains(float x, float y, float z) { if(xhigh[0]){ return false; } @@ -217,7 +226,7 @@ public class AABBox { * @param h hight * @return true if this AABBox might have a common region with this 2D region */ - public boolean intersects(float x, float y, float w, float h) { + public final boolean intersects(float x, float y, float w, float h) { if (w <= 0 || h <= 0) { return false; } @@ -241,21 +250,21 @@ public class AABBox { * length of the vector between low and high. * @return a float representing the size of the AABBox */ - public float getSize() { + public final float getSize() { return VectorUtil.computeLength(low, high); } /**Get the Center of the AABBox * @return the xyz-coordinates of the center of the AABBox */ - public float[] getCenter() { + public final float[] getCenter() { return center; } /** Scale the AABBox by a constant * @param size a constant float value */ - public void scale(float size) { + public final void scale(float size) { float[] diffH = new float[3]; diffH[0] = high[0] - center[0]; diffH[1] = high[1] - center[1]; @@ -274,30 +283,43 @@ public class AABBox { low = VectorUtil.vectorAdd(center, diffL); } - public float getMinX() { + public final float getMinX() { return low[0]; } - public float getMinY() { + public final float getMinY() { return low[1]; } - public float getWidth(){ + public final float getWidth(){ return high[0] - low[0]; } - public float getHeight() { + public final float getHeight() { return high[1] - low[1]; } - public float getDepth() { + public final float getDepth() { return high[2] - low[2]; } - public AABBox clone() { + + public final AABBox clone() { return new AABBox(this.low, this.high); } - public String toString() { + public final boolean equals(Object obj) { + if( obj == this ) { + return true; + } + if( null == obj || !(obj instanceof AABBox) ) { + return false; + } + final AABBox other = (AABBox) obj; + return VectorUtil.checkEquality(low, other.low) && + VectorUtil.checkEquality(high, other.high) ; + } + + public final String toString() { return "[ "+low[0]+"/"+low[1]+"/"+low[1]+" .. "+high[0]+"/"+high[0]+"/"+high[0]+", ctr "+ center[0]+"/"+center[1]+"/"+center[1]+" ]"; } -- cgit v1.2.3