From e4641e304fbc64a5d185a39c6ca6357cc678e013 Mon Sep 17 00:00:00 2001 From: Sven Gothel <sgothel@jausoft.com> Date: Sat, 15 Mar 2014 05:47:01 +0100 Subject: Bug 801: Outline/OutlineShape tranform and sort fixes ; Quaternion: Reduce muls in rotateVector Quaternion: - rotateVector(..): Reduce multiplication count by 17 Graph: - Outline - add: transform - fix compareTo .. use EPSILON - OutlineShape - add transform - fix compareTo .. use EPSILON - use Comparator<Outline> in sortOutlines to avoid reversal of list - Extract OutlineShapeXForm, pairing { OutlineShape, AffineTransform } --- .../classes/com/jogamp/graph/geom/Outline.java | 44 +++++++++++++++------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'src/jogl/classes/com/jogamp/graph/geom/Outline.java') diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java index 2d9d74966..b299524c0 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java +++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java @@ -29,7 +29,10 @@ package com.jogamp.graph.geom; import java.util.ArrayList; +import jogamp.graph.geom.plane.AffineTransform; + import com.jogamp.graph.geom.Vertex; +import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.VectorUtil; import com.jogamp.opengl.math.geom.AABBox; @@ -181,21 +184,18 @@ public class Outline implements Cloneable, Comparable<Outline> { return false; } - /** Compare two outlines with Bounding Box area - * as criteria. - * @see java.lang.Comparable#compareTo(java.lang.Object) + /** + * Return a transformed instance with all vertices are copied and transformed. */ - @Override - public final int compareTo(Outline outline) { - float size = getBounds().getSize(); - float newSize = outline.getBounds().getSize(); - if(size < newSize){ - return -1; - } - else if(size > newSize){ - return 1; + public final Outline transform(AffineTransform t) { + final Outline newOutline = new Outline(); + final int vsize = vertices.size(); + for(int i=0; i<vsize; i++) { + final Vertex v = vertices.get(i); + newOutline.addVertex(t.transform(v, null)); } - return 0; + newOutline.closed = this.closed; + return newOutline; } private final void validateBoundingBox() { @@ -213,6 +213,24 @@ public class Outline implements Cloneable, Comparable<Outline> { return bbox; } + /** + * Compare two outline's Bounding Box size. + * @see AABBox#getSize() + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public final int compareTo(final Outline other) { + final float thisSize = getBounds().getSize(); + final float otherSize = other.getBounds().getSize(); + if( FloatUtil.equals(thisSize, otherSize, FloatUtil.EPSILON) ) { + return 0; + } else if(thisSize < otherSize){ + return -1; + } else { + return 1; + } + } + /** * @param obj the Object to compare this Outline with * @return true if {@code obj} is an Outline, not null, equals bounds and equal vertices in the same order -- cgit v1.2.3