diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/jogamp/graph/geom/plane/AffineTransform.java | 330 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/plane/IllegalPathStateException.java | 2 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/plane/NoninvertibleTransformException.java | 2 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/plane/Path2D.java (renamed from src/com/jogamp/graph/geom/plane/GeneralPath.java) | 121 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/plane/PathIterator.java | 4 | ||||
-rw-r--r-- | src/jogamp/graph/math/plane/Crossing.java | 258 |
6 files changed, 325 insertions, 392 deletions
diff --git a/src/com/jogamp/graph/geom/plane/AffineTransform.java b/src/com/jogamp/graph/geom/plane/AffineTransform.java index 065ad94b2..321551edc 100644 --- a/src/com/jogamp/graph/geom/plane/AffineTransform.java +++ b/src/com/jogamp/graph/geom/plane/AffineTransform.java @@ -17,19 +17,23 @@ /** * @author Denis M. Kishenko */ -package java.awt.geom; +package com.jogamp.graph.geom.plane; -import java.awt.Shape; import java.io.IOException; import java.io.Serializable; -import org.apache.harmony.awt.internal.nls.Messages; +import jogamp.graph.math.MathFloat; import org.apache.harmony.misc.HashCode; +import com.jogamp.graph.geom.Point; +import com.jogamp.graph.geom.Point.Factory; + public class AffineTransform implements Cloneable, Serializable { private static final long serialVersionUID = 1330973210523860834L; + static final String determinantIsZero = "Determinant is zero"; + public static final int TYPE_IDENTITY = 0; public static final int TYPE_TRANSLATION = 1; public static final int TYPE_UNIFORM_SCALE = 2; @@ -49,30 +53,34 @@ public class AffineTransform implements Cloneable, Serializable { /** * The min value equivalent to zero. If absolute value less then ZERO it considered as zero. */ - static final double ZERO = 1E-10; + static final float ZERO = (float) 1E-10; + private final Point.Factory<? extends Point> pointFactory; + /** * The values of transformation matrix */ - double m00; - double m10; - double m01; - double m11; - double m02; - double m12; + float m00; + float m10; + float m01; + float m11; + float m02; + float m12; /** * The transformation <code>type</code> */ transient int type; - public AffineTransform() { + public AffineTransform(Factory<? extends Point> factory) { + pointFactory = factory; type = TYPE_IDENTITY; - m00 = m11 = 1.0; - m10 = m01 = m02 = m12 = 0.0; + m00 = m11 = 1.0f; + m10 = m01 = m02 = m12 = 0.0f; } public AffineTransform(AffineTransform t) { + this.pointFactory = t.pointFactory; this.type = t.type; this.m00 = t.m00; this.m10 = t.m10; @@ -82,7 +90,8 @@ public class AffineTransform implements Cloneable, Serializable { this.m12 = t.m12; } - public AffineTransform(float m00, float m10, float m01, float m11, float m02, float m12) { + public AffineTransform(Point.Factory<? extends Point> factory, float m00, float m10, float m01, float m11, float m02, float m12) { + pointFactory = factory; this.type = TYPE_UNKNOWN; this.m00 = m00; this.m10 = m10; @@ -92,29 +101,8 @@ public class AffineTransform implements Cloneable, Serializable { this.m12 = m12; } - public AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) { - this.type = TYPE_UNKNOWN; - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - } - - public AffineTransform(float[] matrix) { - this.type = TYPE_UNKNOWN; - m00 = matrix[0]; - m10 = matrix[1]; - m01 = matrix[2]; - m11 = matrix[3]; - if (matrix.length > 4) { - m02 = matrix[4]; - m12 = matrix[5]; - } - } - - public AffineTransform(double[] matrix) { + public AffineTransform(Point.Factory<? extends Point> factory, float[] matrix) { + pointFactory = factory; this.type = TYPE_UNKNOWN; m00 = matrix[0]; m10 = matrix[1]; @@ -169,8 +157,8 @@ public class AffineTransform implements Cloneable, Serializable { type |= TYPE_FLIP; } - double dx = m00 * m00 + m10 * m10; - double dy = m01 * m01 + m11 * m11; + float dx = m00 * m00 + m10 * m10; + float dy = m01 * m01 + m11 * m11; if (dx != dy) { type |= TYPE_GENERAL_SCALE; } else @@ -190,27 +178,27 @@ public class AffineTransform implements Cloneable, Serializable { return type; } - public double getScaleX() { + public float getScaleX() { return m00; } - public double getScaleY() { + public float getScaleY() { return m11; } - public double getShearX() { + public float getShearX() { return m01; } - public double getShearY() { + public float getShearY() { return m10; } - public double getTranslateX() { + public float getTranslateX() { return m02; } - public double getTranslateY() { + public float getTranslateY() { return m12; } @@ -218,7 +206,7 @@ public class AffineTransform implements Cloneable, Serializable { return getType() == TYPE_IDENTITY; } - public void getMatrix(double[] matrix) { + public void getMatrix(float[] matrix) { matrix[0] = m00; matrix[1] = m10; matrix[2] = m01; @@ -229,11 +217,11 @@ public class AffineTransform implements Cloneable, Serializable { } } - public double getDeterminant() { + public float getDeterminant() { return m00 * m11 - m01 * m10; } - public void setTransform(double m00, double m10, double m01, double m11, double m02, double m12) { + public void setTransform(float m00, float m10, float m01, float m11, float m02, float m12) { this.type = TYPE_UNKNOWN; this.m00 = m00; this.m10 = m10; @@ -250,128 +238,130 @@ public class AffineTransform implements Cloneable, Serializable { public void setToIdentity() { type = TYPE_IDENTITY; - m00 = m11 = 1.0; - m10 = m01 = m02 = m12 = 0.0; + m00 = m11 = 1.0f; + m10 = m01 = m02 = m12 = 0.0f; } - public void setToTranslation(double mx, double my) { - m00 = m11 = 1.0; - m01 = m10 = 0.0; + public void setToTranslation(float mx, float my) { + m00 = m11 = 1.0f; + m01 = m10 = 0.0f; m02 = mx; m12 = my; - if (mx == 0.0 && my == 0.0) { + if (mx == 0.0f && my == 0.0f) { type = TYPE_IDENTITY; } else { type = TYPE_TRANSLATION; } } - public void setToScale(double scx, double scy) { + public void setToScale(float scx, float scy) { m00 = scx; m11 = scy; - m10 = m01 = m02 = m12 = 0.0; - if (scx != 1.0 || scy != 1.0) { + m10 = m01 = m02 = m12 = 0.0f; + if (scx != 1.0f || scy != 1.0f) { type = TYPE_UNKNOWN; } else { type = TYPE_IDENTITY; } } - public void setToShear(double shx, double shy) { - m00 = m11 = 1.0; - m02 = m12 = 0.0; + public void setToShear(float shx, float shy) { + m00 = m11 = 1.0f; + m02 = m12 = 0.0f; m01 = shx; m10 = shy; - if (shx != 0.0 || shy != 0.0) { + if (shx != 0.0f || shy != 0.0f) { type = TYPE_UNKNOWN; } else { type = TYPE_IDENTITY; } } - public void setToRotation(double angle) { - double sin = Math.sin(angle); - double cos = Math.cos(angle); - if (Math.abs(cos) < ZERO) { - cos = 0.0; - sin = sin > 0.0 ? 1.0 : -1.0; + public void setToRotation(float angle) { + float sin = MathFloat.sin(angle); + float cos = MathFloat.cos(angle); + if (MathFloat.abs(cos) < ZERO) { + cos = 0.0f; + sin = sin > 0.0f ? 1.0f : -1.0f; } else - if (Math.abs(sin) < ZERO) { - sin = 0.0; - cos = cos > 0.0 ? 1.0 : -1.0; + if (MathFloat.abs(sin) < ZERO) { + sin = 0.0f; + cos = cos > 0.0f ? 1.0f : -1.0f; } m00 = m11 = cos; m01 = -sin; m10 = sin; - m02 = m12 = 0.0; + m02 = m12 = 0.0f; type = TYPE_UNKNOWN; } - public void setToRotation(double angle, double px, double py) { + public void setToRotation(float angle, float px, float py) { setToRotation(angle); - m02 = px * (1.0 - m00) + py * m10; - m12 = py * (1.0 - m00) - px * m10; + m02 = px * (1.0f - m00) + py * m10; + m12 = py * (1.0f - m00) - px * m10; type = TYPE_UNKNOWN; } - public static AffineTransform getTranslateInstance(double mx, double my) { - AffineTransform t = new AffineTransform(); + public static <T extends Point> AffineTransform getTranslateInstance(Point.Factory<? extends Point> factory, float mx, float my) { + AffineTransform t = new AffineTransform(factory); t.setToTranslation(mx, my); return t; } - public static AffineTransform getScaleInstance(double scx, double scY) { - AffineTransform t = new AffineTransform(); + public static <T extends Point> AffineTransform getScaleInstance(Point.Factory<? extends Point> factory, float scx, float scY) { + AffineTransform t = new AffineTransform(factory); t.setToScale(scx, scY); return t; } - public static AffineTransform getShearInstance(double shx, double shy) { - AffineTransform m = new AffineTransform(); - m.setToShear(shx, shy); - return m; + public static <T extends Point> AffineTransform getShearInstance(Point.Factory<? extends Point> factory, float shx, float shy) { + AffineTransform t = new AffineTransform(factory); + t.setToShear(shx, shy); + return t; } - public static AffineTransform getRotateInstance(double angle) { - AffineTransform t = new AffineTransform(); + public static <T extends Point> AffineTransform getRotateInstance(Point.Factory<? extends Point> factory, float angle) { + AffineTransform t = new AffineTransform(factory); t.setToRotation(angle); return t; } - public static AffineTransform getRotateInstance(double angle, double x, double y) { - AffineTransform t = new AffineTransform(); + public static <T extends Point> AffineTransform getRotateInstance(Point.Factory<? extends Point> factory, float angle, float x, float y) { + AffineTransform t = new AffineTransform(factory); t.setToRotation(angle, x, y); return t; } - public void translate(double mx, double my) { - concatenate(AffineTransform.getTranslateInstance(mx, my)); + public void translate(float mx, float my) { + concatenate(AffineTransform.getTranslateInstance(pointFactory, mx, my)); } - public void scale(double scx, double scy) { - concatenate(AffineTransform.getScaleInstance(scx, scy)); + public void scale(float scx, float scy) { + concatenate(AffineTransform.getScaleInstance(pointFactory, scx, scy)); } - public void shear(double shx, double shy) { - concatenate(AffineTransform.getShearInstance(shx, shy)); + public void shear(float shx, float shy) { + concatenate(AffineTransform.getShearInstance(pointFactory, shx, shy)); } - public void rotate(double angle) { - concatenate(AffineTransform.getRotateInstance(angle)); + public void rotate(float angle) { + concatenate(AffineTransform.getRotateInstance(pointFactory, angle)); } - public void rotate(double angle, double px, double py) { - concatenate(AffineTransform.getRotateInstance(angle, px, py)); + public void rotate(float angle, float px, float py) { + concatenate(AffineTransform.getRotateInstance(pointFactory, angle, px, py)); } /** - * Multiply matrix of two AffineTransform objects + * Multiply matrix of two AffineTransform objects. + * The first argument's {@link Point.Factory} is being used. + * * @param t1 - the AffineTransform object is a multiplicand * @param t2 - the AffineTransform object is a multiplier * @return an AffineTransform object that is a result of t1 multiplied by matrix t2. */ AffineTransform multiply(AffineTransform t1, AffineTransform t2) { - return new AffineTransform( + return new AffineTransform(t1.pointFactory, t1.m00 * t2.m00 + t1.m10 * t2.m01, // m00 t1.m00 * t2.m10 + t1.m10 * t2.m11, // m01 t1.m01 * t2.m00 + t1.m11 * t2.m01, // m10 @@ -389,12 +379,12 @@ public class AffineTransform implements Cloneable, Serializable { } public AffineTransform createInverse() throws NoninvertibleTransformException { - double det = getDeterminant(); - if (Math.abs(det) < ZERO) { - // awt.204=Determinant is zero - throw new NoninvertibleTransformException(Messages.getString("awt.204")); //$NON-NLS-1$ + float det = getDeterminant(); + if (MathFloat.abs(det) < ZERO) { + throw new NoninvertibleTransformException(determinantIsZero); } return new AffineTransform( + this.pointFactory, m11 / det, // m00 -m10 / det, // m10 -m01 / det, // m01 @@ -404,57 +394,32 @@ public class AffineTransform implements Cloneable, Serializable { ); } - public Point2D transform(Point2D src, Point2D dst) { + public Point transform(Point src, Point dst) { if (dst == null) { - if (src instanceof Point2D.Double) { - dst = new Point2D.Double(); - } else { - dst = new Point2D.Float(); - } + dst = pointFactory.create(); } - double x = src.getX(); - double y = src.getY(); + float x = src.getX(); + float y = src.getY(); - dst.setLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); + dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); return dst; } - public void transform(Point2D[] src, int srcOff, Point2D[] dst, int dstOff, int length) { + public void transform(Point[] src, int srcOff, Point[] dst, int dstOff, int length) { while (--length >= 0) { - Point2D srcPoint = src[srcOff++]; - double x = srcPoint.getX(); - double y = srcPoint.getY(); - Point2D dstPoint = dst[dstOff]; + Point srcPoint = src[srcOff++]; + float x = srcPoint.getX(); + float y = srcPoint.getY(); + Point dstPoint = dst[dstOff]; if (dstPoint == null) { - if (srcPoint instanceof Point2D.Double) { - dstPoint = new Point2D.Double(); - } else { - dstPoint = new Point2D.Float(); - } + throw new IllegalArgumentException("dst["+dstOff+"] is null"); } - dstPoint.setLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); + dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); dst[dstOff++] = dstPoint; } } - public void transform(double[] src, int srcOff, double[] dst, int dstOff, int length) { - int step = 2; - if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) { - srcOff = srcOff + length * 2 - 2; - dstOff = dstOff + length * 2 - 2; - step = -2; - } - while (--length >= 0) { - double x = src[srcOff + 0]; - double y = src[srcOff + 1]; - dst[dstOff + 0] = x * m00 + y * m01 + m02; - dst[dstOff + 1] = x * m10 + y * m11 + m12; - srcOff += step; - dstOff += step; - } - } - public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length) { int step = 2; if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) { @@ -465,104 +430,75 @@ public class AffineTransform implements Cloneable, Serializable { while (--length >= 0) { float x = src[srcOff + 0]; float y = src[srcOff + 1]; - dst[dstOff + 0] = (float)(x * m00 + y * m01 + m02); - dst[dstOff + 1] = (float)(x * m10 + y * m11 + m12); + dst[dstOff + 0] = x * m00 + y * m01 + m02; + dst[dstOff + 1] = x * m10 + y * m11 + m12; srcOff += step; dstOff += step; } } - public void transform(float[] src, int srcOff, double[] dst, int dstOff, int length) { - while (--length >= 0) { - float x = src[srcOff++]; - float y = src[srcOff++]; - dst[dstOff++] = x * m00 + y * m01 + m02; - dst[dstOff++] = x * m10 + y * m11 + m12; - } - } - - public void transform(double[] src, int srcOff, float[] dst, int dstOff, int length) { - while (--length >= 0) { - double x = src[srcOff++]; - double y = src[srcOff++]; - dst[dstOff++] = (float)(x * m00 + y * m01 + m02); - dst[dstOff++] = (float)(x * m10 + y * m11 + m12); - } - } - - public Point2D deltaTransform(Point2D src, Point2D dst) { + public Point deltaTransform(Point src, Point dst) { if (dst == null) { - if (src instanceof Point2D.Double) { - dst = new Point2D.Double(); - } else { - dst = new Point2D.Float(); - } + dst = pointFactory.create(); } - double x = src.getX(); - double y = src.getY(); + float x = src.getX(); + float y = src.getY(); - dst.setLocation(x * m00 + y * m01, x * m10 + y * m11); + dst.setCoord(x * m00 + y * m01, x * m10 + y * m11); return dst; } - public void deltaTransform(double[] src, int srcOff, double[] dst, int dstOff, int length) { + public void deltaTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) { while (--length >= 0) { - double x = src[srcOff++]; - double y = src[srcOff++]; + float x = src[srcOff++]; + float y = src[srcOff++]; dst[dstOff++] = x * m00 + y * m01; dst[dstOff++] = x * m10 + y * m11; } } - public Point2D inverseTransform(Point2D src, Point2D dst) throws NoninvertibleTransformException { - double det = getDeterminant(); - if (Math.abs(det) < ZERO) { - // awt.204=Determinant is zero - throw new NoninvertibleTransformException(Messages.getString("awt.204")); //$NON-NLS-1$ + public Point inverseTransform(Point src, Point dst) throws NoninvertibleTransformException { + float det = getDeterminant(); + if (MathFloat.abs(det) < ZERO) { + throw new NoninvertibleTransformException(determinantIsZero); } - if (dst == null) { - if (src instanceof Point2D.Double) { - dst = new Point2D.Double(); - } else { - dst = new Point2D.Float(); - } + dst = pointFactory.create(); } - double x = src.getX() - m02; - double y = src.getY() - m12; + float x = src.getX() - m02; + float y = src.getY() - m12; - dst.setLocation((x * m11 - y * m01) / det, (y * m00 - x * m10) / det); + dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det); return dst; } - public void inverseTransform(double[] src, int srcOff, double[] dst, int dstOff, int length) + public void inverseTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) throws NoninvertibleTransformException { - double det = getDeterminant(); - if (Math.abs(det) < ZERO) { - // awt.204=Determinant is zero - throw new NoninvertibleTransformException(Messages.getString("awt.204")); //$NON-NLS-1$ + float det = getDeterminant(); + if (MathFloat.abs(det) < ZERO) { + throw new NoninvertibleTransformException(determinantIsZero); } while (--length >= 0) { - double x = src[srcOff++] - m02; - double y = src[srcOff++] - m12; + float x = src[srcOff++] - m02; + float y = src[srcOff++] - m12; dst[dstOff++] = (x * m11 - y * m01) / det; dst[dstOff++] = (y * m00 - x * m10) / det; } } - public Shape createTransformedShape(Shape src) { + public Path2D createTransformedShape(Path2D src) { if (src == null) { return null; } - if (src instanceof GeneralPath) { - return ((GeneralPath)src).createTransformedShape(this); + if (src instanceof Path2D) { + return ((Path2D)src).createTransformedShape(this); } - PathIterator path = src.getPathIterator(this); - GeneralPath dst = new GeneralPath(path.getWindingRule()); + PathIterator path = src.iterator(this); + Path2D dst = new Path2D(path.getWindingRule()); dst.append(path, false); return dst; } diff --git a/src/com/jogamp/graph/geom/plane/IllegalPathStateException.java b/src/com/jogamp/graph/geom/plane/IllegalPathStateException.java index 9d667e510..15f629b88 100644 --- a/src/com/jogamp/graph/geom/plane/IllegalPathStateException.java +++ b/src/com/jogamp/graph/geom/plane/IllegalPathStateException.java @@ -17,7 +17,7 @@ /** * @author Denis M. Kishenko */ -package java.awt.geom; +package com.jogamp.graph.geom.plane; public class IllegalPathStateException extends RuntimeException { diff --git a/src/com/jogamp/graph/geom/plane/NoninvertibleTransformException.java b/src/com/jogamp/graph/geom/plane/NoninvertibleTransformException.java index eee170ec1..cd1ec8d16 100644 --- a/src/com/jogamp/graph/geom/plane/NoninvertibleTransformException.java +++ b/src/com/jogamp/graph/geom/plane/NoninvertibleTransformException.java @@ -17,7 +17,7 @@ /** * @author Denis M. Kishenko */ -package java.awt.geom; +package com.jogamp.graph.geom.plane; public class NoninvertibleTransformException extends java.lang.Exception { diff --git a/src/com/jogamp/graph/geom/plane/GeneralPath.java b/src/com/jogamp/graph/geom/plane/Path2D.java index 6d6282ef1..031450c8e 100644 --- a/src/com/jogamp/graph/geom/plane/GeneralPath.java +++ b/src/com/jogamp/graph/geom/plane/Path2D.java @@ -17,20 +17,24 @@ /** * @author Denis M. Kishenko */ -package java.awt.geom; +package com.jogamp.graph.geom.plane; -import java.awt.Rectangle; -import java.awt.Shape; import java.util.NoSuchElementException; -import org.apache.harmony.awt.gl.Crossing; -import org.apache.harmony.awt.internal.nls.Messages; +import com.jogamp.graph.geom.AABBox; +import com.jogamp.graph.geom.Point; +import com.jogamp.graph.geom.opengl.Vertex; -public final class GeneralPath implements Shape, Cloneable { +import jogamp.graph.math.plane.Crossing; + +public final class Path2D implements Cloneable { public static final int WIND_EVEN_ODD = PathIterator.WIND_EVEN_ODD; public static final int WIND_NON_ZERO = PathIterator.WIND_NON_ZERO; + static final String invalidWindingRuleValue = "Invalid winding rule value"; + static final String iteratorOutOfBounds = "Iterator out of bounds"; + /** * The buffers size */ @@ -94,7 +98,7 @@ public final class GeneralPath implements Shape, Cloneable { /** * The source GeneralPath object */ - GeneralPath p; + Path2D p; /** * The path iterator transformation @@ -105,7 +109,7 @@ public final class GeneralPath implements Shape, Cloneable { * Constructs a new GeneralPath.Iterator for given general path * @param path - the source GeneralPath object */ - Iterator(GeneralPath path) { + Iterator(Path2D path) { this(path, null); } @@ -114,7 +118,7 @@ public final class GeneralPath implements Shape, Cloneable { * @param path - the source GeneralPath object * @param at - the AffineTransform object to apply rectangle path */ - Iterator(GeneralPath path, AffineTransform at) { + Iterator(Path2D path, AffineTransform at) { this.p = path; this.t = at; } @@ -131,30 +135,12 @@ public final class GeneralPath implements Shape, Cloneable { typeIndex++; } - public int currentSegment(double[] coords) { - if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ - } - int type = p.types[typeIndex]; - int count = GeneralPath.pointShift[type]; - for (int i = 0; i < count; i++) { - coords[i] = p.points[pointIndex + i]; - } - if (t != null) { - t.transform(coords, 0, coords, 0, count / 2); - } - pointIndex += count; - return type; - } - public int currentSegment(float[] coords) { if (isDone()) { - // awt.4B=Iterator out of bounds - throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$ + throw new NoSuchElementException(iteratorOutOfBounds); } int type = p.types[typeIndex]; - int count = GeneralPath.pointShift[type]; + int count = Path2D.pointShift[type]; System.arraycopy(p.points, pointIndex, coords, 0, count); if (t != null) { t.transform(coords, 0, coords, 0, count / 2); @@ -165,31 +151,30 @@ public final class GeneralPath implements Shape, Cloneable { } - public GeneralPath() { + public Path2D() { this(WIND_NON_ZERO, BUFFER_SIZE); } - public GeneralPath(int rule) { + public Path2D(int rule) { this(rule, BUFFER_SIZE); } - public GeneralPath(int rule, int initialCapacity) { + public Path2D(int rule, int initialCapacity) { setWindingRule(rule); types = new byte[initialCapacity]; points = new float[initialCapacity * 2]; } - public GeneralPath(Shape shape) { + public Path2D(Path2D path) { this(WIND_NON_ZERO, BUFFER_SIZE); - PathIterator p = shape.getPathIterator(null); + PathIterator p = path.iterator(null); setWindingRule(p.getWindingRule()); append(p, false); } public void setWindingRule(int rule) { if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) { - // awt.209=Invalid winding rule value - throw new java.lang.IllegalArgumentException(Messages.getString("awt.209")); //$NON-NLS-1$ + throw new NoSuchElementException(invalidWindingRuleValue); } this.rule = rule; } @@ -204,8 +189,7 @@ public final class GeneralPath implements Shape, Cloneable { */ void checkBuf(int pointCount, boolean checkMove) { if (checkMove && typeSize == 0) { - // awt.20A=First segment should be SEG_MOVETO type - throw new IllegalPathStateException(Messages.getString("awt.20A")); //$NON-NLS-1$ + throw new IllegalPathStateException("First segment should be SEG_MOVETO type"); } if (typeSize == types.length) { byte tmp[] = new byte[typeSize + BUFFER_CAPACITY]; @@ -258,15 +242,27 @@ public final class GeneralPath implements Shape, Cloneable { points[pointSize++] = y3; } + final public int size() { + return typeSize; + } + + final public boolean isClosed() { + return typeSize > 0 && types[typeSize - 1] == PathIterator.SEG_CLOSE ; + } + public void closePath() { - if (typeSize == 0 || types[typeSize - 1] != PathIterator.SEG_CLOSE) { + if (!isClosed()) { checkBuf(0, true); types[typeSize++] = PathIterator.SEG_CLOSE; } } + + public String toString() { + return "[size "+size()+", closed "+isClosed()+"]"; + } - public void append(Shape shape, boolean connect) { - PathIterator p = shape.getPathIterator(null); + public void append(Path2D path, boolean connect) { + PathIterator p = path.iterator(null); append(p, connect); } @@ -304,7 +300,7 @@ public final class GeneralPath implements Shape, Cloneable { } } - public Point2D getCurrentPoint() { + public Vertex getCurrentPoint() { if (typeSize == 0) { return null; } @@ -319,7 +315,7 @@ public final class GeneralPath implements Shape, Cloneable { j -= pointShift[type]; } } - return new Point2D.Float(points[j], points[j + 1]); + return new Vertex(points[j], points[j + 1]); } public void reset() { @@ -331,15 +327,15 @@ public final class GeneralPath implements Shape, Cloneable { t.transform(points, 0, points, 0, pointSize / 2); } - public Shape createTransformedShape(AffineTransform t) { - GeneralPath p = (GeneralPath)clone(); + public Path2D createTransformedShape(AffineTransform t) { + Path2D p = (Path2D)clone(); if (t != null) { p.transform(t); } return p; } - public Rectangle2D getBounds2D() { + public final synchronized AABBox getBounds2D() { float rx1, ry1, rx2, ry2; if (pointSize == 0) { rx1 = ry1 = rx2 = ry2 = 0.0f; @@ -364,11 +360,9 @@ public final class GeneralPath implements Shape, Cloneable { } } } - return new Rectangle2D.Float(rx1, ry1, rx2 - rx1, ry2 - ry1); - } - - public Rectangle getBounds() { - return getBounds2D().getBounds(); + // FIXME: Rami's code had this in, but AABBox uses upper left - lower right - right ? + // return new AABBox(rx1, ry1, 0f, rx2 - rx1, ry2 - ry1, 0f); + return new AABBox(rx1, ry1, 0f, rx2, ry2, 0f); } /** @@ -383,44 +377,48 @@ public final class GeneralPath implements Shape, Cloneable { return Crossing.isInsideEvenOdd(cross); } - public boolean contains(double px, double py) { + public boolean contains(float px, float py) { return isInside(Crossing.crossShape(this, px, py)); } - public boolean contains(double rx, double ry, double rw, double rh) { + public boolean contains(float rx, float ry, float rw, float rh) { int cross = Crossing.intersectShape(this, rx, ry, rw, rh); return cross != Crossing.CROSSING && isInside(cross); } - public boolean intersects(double rx, double ry, double rw, double rh) { + public boolean intersects(float rx, float ry, float rw, float rh) { int cross = Crossing.intersectShape(this, rx, ry, rw, rh); return cross == Crossing.CROSSING || isInside(cross); } - public boolean contains(Point2D p) { + public boolean contains(Point p) { return contains(p.getX(), p.getY()); } - public boolean contains(Rectangle2D r) { + public boolean contains(AABBox r) { return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); } - public boolean intersects(Rectangle2D r) { + public boolean intersects(AABBox r) { return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); } - public PathIterator getPathIterator(AffineTransform t) { + public PathIterator iterator() { + return new Iterator(this); + } + + public PathIterator iterator(AffineTransform t) { return new Iterator(this, t); } - public PathIterator getPathIterator(AffineTransform t, double flatness) { + /* public PathIterator getPathIterator(AffineTransform t, float flatness) { return new FlatteningPathIterator(getPathIterator(t), flatness); - } + } */ @Override public Object clone() { try { - GeneralPath p = (GeneralPath) super.clone(); + Path2D p = (Path2D) super.clone(); p.types = types.clone(); p.points = points.clone(); return p; @@ -428,6 +426,5 @@ public final class GeneralPath implements Shape, Cloneable { throw new InternalError(); } } - } diff --git a/src/com/jogamp/graph/geom/plane/PathIterator.java b/src/com/jogamp/graph/geom/plane/PathIterator.java index 22b897841..b4681df0a 100644 --- a/src/com/jogamp/graph/geom/plane/PathIterator.java +++ b/src/com/jogamp/graph/geom/plane/PathIterator.java @@ -17,7 +17,7 @@ /** * @author Denis M. Kishenko */ -package java.awt.geom; +package com.jogamp.graph.geom.plane; public interface PathIterator { @@ -38,7 +38,5 @@ public interface PathIterator { public int currentSegment(float[] coords); - public int currentSegment(double[] coords); - } diff --git a/src/jogamp/graph/math/plane/Crossing.java b/src/jogamp/graph/math/plane/Crossing.java index 7da1c466e..5620da73a 100644 --- a/src/jogamp/graph/math/plane/Crossing.java +++ b/src/jogamp/graph/math/plane/Crossing.java @@ -17,22 +17,24 @@ /** * @author Denis M. Kishenko */ -package org.apache.harmony.awt.gl; +package jogamp.graph.math.plane; -import java.awt.Shape; -import java.awt.geom.PathIterator; +import jogamp.graph.math.MathFloat; + +import com.jogamp.graph.geom.plane.Path2D; +import com.jogamp.graph.geom.plane.PathIterator; public class Crossing { /** * Allowable tolerance for bounds comparison */ - static final double DELTA = 1E-5; + static final float DELTA = (float) 1E-5; /** * If roots have distance less then <code>ROOT_DELTA</code> they are double */ - static final double ROOT_DELTA = 1E-10; + static final float ROOT_DELTA = (float) 1E-10; /** * Rectangle cross segment @@ -50,10 +52,10 @@ public class Crossing { * @param res - the roots of the equation * @return a number of roots */ - public static int solveQuad(double eqn[], double res[]) { - double a = eqn[2]; - double b = eqn[1]; - double c = eqn[0]; + public static int solveQuad(float eqn[], float res[]) { + float a = eqn[2]; + float b = eqn[1]; + float c = eqn[0]; int rc = 0; if (a == 0.0) { if (b == 0.0) { @@ -61,16 +63,16 @@ public class Crossing { } res[rc++] = -c / b; } else { - double d = b * b - 4.0 * a * c; + float d = b * b - 4.0f * a * c; // d < 0.0 if (d < 0.0) { return 0; } - d = Math.sqrt(d); - res[rc++] = (- b + d) / (a * 2.0); + d = MathFloat.sqrt(d); + res[rc++] = (- b + d) / (a * 2.0f); // d != 0.0 if (d != 0.0) { - res[rc++] = (- b - d) / (a * 2.0); + res[rc++] = (- b - d) / (a * 2.0f); } } return fixRoots(res, rc); @@ -82,32 +84,32 @@ public class Crossing { * @param res - the roots of the equation * @return a number of roots */ - public static int solveCubic(double eqn[], double res[]) { - double d = eqn[3]; + public static int solveCubic(float eqn[], float res[]) { + float d = eqn[3]; if (d == 0) { return solveQuad(eqn, res); } - double a = eqn[2] / d; - double b = eqn[1] / d; - double c = eqn[0] / d; + float a = eqn[2] / d; + float b = eqn[1] / d; + float c = eqn[0] / d; int rc = 0; - double Q = (a * a - 3.0 * b) / 9.0; - double R = (2.0 * a * a * a - 9.0 * a * b + 27.0 * c) / 54.0; - double Q3 = Q * Q * Q; - double R2 = R * R; - double n = - a / 3.0; + float Q = (a * a - 3.0f * b) / 9.0f; + float R = (2.0f * a * a * a - 9.0f * a * b + 27.0f * c) / 54.0f; + float Q3 = Q * Q * Q; + float R2 = R * R; + float n = - a / 3.0f; if (R2 < Q3) { - double t = Math.acos(R / Math.sqrt(Q3)) / 3.0; - double p = 2.0 * Math.PI / 3.0; - double m = -2.0 * Math.sqrt(Q); - res[rc++] = m * Math.cos(t) + n; - res[rc++] = m * Math.cos(t + p) + n; - res[rc++] = m * Math.cos(t - p) + n; + float t = MathFloat.acos(R / MathFloat.sqrt(Q3)) / 3.0f; + float p = 2.0f * MathFloat.PI / 3.0f; + float m = -2.0f * MathFloat.sqrt(Q); + res[rc++] = m * MathFloat.cos(t) + n; + res[rc++] = m * MathFloat.cos(t + p) + n; + res[rc++] = m * MathFloat.cos(t - p) + n; } else { // Debug.println("R2 >= Q3 (" + R2 + "/" + Q3 + ")"); - double A = Math.pow(Math.abs(R) + Math.sqrt(R2 - Q3), 1.0 / 3.0); + float A = MathFloat.pow(MathFloat.abs(R) + MathFloat.sqrt(R2 - Q3), 1.0f / 3.0f); if (R > 0.0) { A = -A; } @@ -115,12 +117,12 @@ public class Crossing { if (-ROOT_DELTA < A && A < ROOT_DELTA) { res[rc++] = n; } else { - double B = Q / A; + float B = Q / A; res[rc++] = A + B + n; // if (R2 == Q3) { - double delta = R2 - Q3; + float delta = R2 - Q3; if (-ROOT_DELTA < delta && delta < ROOT_DELTA) { - res[rc++] = - (A + B) / 2.0 + n; + res[rc++] = - (A + B) / 2.0f + n; } } @@ -129,12 +131,12 @@ public class Crossing { } /** - * Excludes double roots. Roots are double if they lies enough close with each other. + * Excludes float roots. Roots are float if they lies enough close with each other. * @param res - the roots * @param rc - the roots count * @return new roots count */ - static int fixRoots(double res[], int rc) { + static int fixRoots(float res[], int rc) { int tc = 0; for(int i = 0; i < rc; i++) { out: { @@ -154,10 +156,10 @@ public class Crossing { */ public static class QuadCurve { - double ax, ay, bx, by; - double Ax, Ay, Bx, By; + float ax, ay, bx, by; + float Ax, Ay, Bx, By; - public QuadCurve(double x1, double y1, double cx, double cy, double x2, double y2) { + public QuadCurve(float x1, float y1, float cx, float cy, float x2, float y2) { ax = x2 - x1; ay = y2 - y1; bx = cx - x1; @@ -170,11 +172,11 @@ public class Crossing { Ay = ay - By; // Ay = ay - 2.0 * by } - int cross(double res[], int rc, double py1, double py2) { + int cross(float res[], int rc, float py1, float py2) { int cross = 0; for (int i = 0; i < rc; i++) { - double t = res[i]; + float t = res[i]; // CURVE-OUTSIDE if (t < -DELTA || t > 1 + DELTA) { @@ -195,10 +197,10 @@ public class Crossing { continue; } // CURVE-INSIDE - double ry = t * (t * Ay + By); + float ry = t * (t * Ay + By); // ry = t * t * Ay + t * By if (ry > py2) { - double rxt = t * Ax + bx; + float rxt = t * Ax + bx; // rxt = 2.0 * t * Ax + Bx = 2.0 * t * Ax + 2.0 * bx if (rxt > -DELTA && rxt < DELTA) { continue; @@ -210,12 +212,12 @@ public class Crossing { return cross; } - int solvePoint(double res[], double px) { - double eqn[] = {-px, Bx, Ax}; + int solvePoint(float res[], float px) { + float eqn[] = {-px, Bx, Ax}; return solveQuad(eqn, res); } - int solveExtrem(double res[]) { + int solveExtrem(float res[]) { int rc = 0; if (Ax != 0.0) { res[rc++] = - Bx / (Ax + Ax); @@ -226,11 +228,11 @@ public class Crossing { return rc; } - int addBound(double bound[], int bc, double res[], int rc, double minX, double maxX, boolean changeId, int id) { + int addBound(float bound[], int bc, float res[], int rc, float minX, float maxX, boolean changeId, int id) { for(int i = 0; i < rc; i++) { - double t = res[i]; + float t = res[i]; if (t > -DELTA && t < 1 + DELTA) { - double rx = t * (t * Ax + Bx); + float rx = t * (t * Ax + Bx); if (minX <= rx && rx <= maxX) { bound[bc++] = t; bound[bc++] = rx; @@ -252,11 +254,11 @@ public class Crossing { */ public static class CubicCurve { - double ax, ay, bx, by, cx, cy; - double Ax, Ay, Bx, By, Cx, Cy; - double Ax3, Bx2; + float ax, ay, bx, by, cx, cy; + float Ax, Ay, Bx, By, Cx, Cy; + float Ax3, Bx2; - public CubicCurve(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2) { + public CubicCurve(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2) { ax = x2 - x1; ay = y2 - y1; bx = cx1 - x1; @@ -276,10 +278,10 @@ public class Crossing { Bx2 = Bx + Bx; } - int cross(double res[], int rc, double py1, double py2) { + int cross(float res[], int rc, float py1, float py2) { int cross = 0; for (int i = 0; i < rc; i++) { - double t = res[i]; + float t = res[i]; // CURVE-OUTSIDE if (t < -DELTA || t > 1 + DELTA) { @@ -300,10 +302,10 @@ public class Crossing { continue; } // CURVE-INSIDE - double ry = t * (t * (t * Ay + By) + Cy); + float ry = t * (t * (t * Ay + By) + Cy); // ry = t * t * t * Ay + t * t * By + t * Cy if (ry > py2) { - double rxt = t * (t * Ax3 + Bx2) + Cx; + float rxt = t * (t * Ax3 + Bx2) + Cx; // rxt = 3.0 * t * t * Ax + 2.0 * t * Bx + Cx if (rxt > -DELTA && rxt < DELTA) { rxt = t * (Ax3 + Ax3) + Bx2; @@ -321,26 +323,26 @@ public class Crossing { return cross; } - int solvePoint(double res[], double px) { - double eqn[] = {-px, Cx, Bx, Ax}; + int solvePoint(float res[], float px) { + float eqn[] = {-px, Cx, Bx, Ax}; return solveCubic(eqn, res); } - int solveExtremX(double res[]) { - double eqn[] = {Cx, Bx2, Ax3}; + int solveExtremX(float res[]) { + float eqn[] = {Cx, Bx2, Ax3}; return solveQuad(eqn, res); } - int solveExtremY(double res[]) { - double eqn[] = {Cy, By + By, Ay + Ay + Ay}; + int solveExtremY(float res[]) { + float eqn[] = {Cy, By + By, Ay + Ay + Ay}; return solveQuad(eqn, res); } - int addBound(double bound[], int bc, double res[], int rc, double minX, double maxX, boolean changeId, int id) { + int addBound(float bound[], int bc, float res[], int rc, float minX, float maxX, boolean changeId, int id) { for(int i = 0; i < rc; i++) { - double t = res[i]; + float t = res[i]; if (t > -DELTA && t < 1 + DELTA) { - double rx = t * (t * (t * Ax + Bx) + Cx); + float rx = t * (t * (t * Ax + Bx) + Cx); if (minX <= rx && rx <= maxX) { bound[bc++] = t; bound[bc++] = rx; @@ -360,7 +362,7 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross line. */ - public static int crossLine(double x1, double y1, double x2, double y2, double x, double y) { + public static int crossLine(float x1, float y1, float x2, float y2, float x, float y) { // LEFT/RIGHT/UP/EMPTY if ((x < x1 && x < x2) || @@ -398,7 +400,7 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross quard curve */ - public static int crossQuad(double x1, double y1, double cx, double cy, double x2, double y2, double x, double y) { + public static int crossQuad(float x1, float y1, float cx, float cy, float x2, float y2, float x, float y) { // LEFT/RIGHT/UP/EMPTY if ((x < x1 && x < cx && x < x2) || @@ -419,9 +421,9 @@ public class Crossing { // INSIDE QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2); - double px = x - x1; - double py = y - y1; - double res[] = new double[3]; + float px = x - x1; + float py = y - y1; + float res[] = new float[3]; int rc = c.solvePoint(res, px); return c.cross(res, rc, py, py); @@ -430,7 +432,7 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross cubic curve */ - public static int crossCubic(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2, double x, double y) { + public static int crossCubic(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, float x, float y) { // LEFT/RIGHT/UP/EMPTY if ((x < x1 && x < cx1 && x < cx2 && x < x2) || @@ -451,9 +453,9 @@ public class Crossing { // INSIDE CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2); - double px = x - x1; - double py = y - y1; - double res[] = new double[3]; + float px = x - x1; + float py = y - y1; + float res[] = new float[3]; int rc = c.solvePoint(res, px); return c.cross(res, rc, py, py); } @@ -461,11 +463,11 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross path */ - public static int crossPath(PathIterator p, double x, double y) { + public static int crossPath(PathIterator p, float x, float y) { int cross = 0; - double mx, my, cx, cy; - mx = my = cx = cy = 0.0; - double coords[] = new double[6]; + float mx, my, cx, cy; + mx = my = cx = cy = 0.0f; + float coords[] = new float[6]; while (!p.isDone()) { switch (p.currentSegment(coords)) { @@ -509,24 +511,24 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross shape */ - public static int crossShape(Shape s, double x, double y) { + public static int crossShape(Path2D s, float x, float y) { if (!s.getBounds2D().contains(x, y)) { return 0; } - return crossPath(s.getPathIterator(null), x, y); + return crossPath(s.iterator(null), x, y); } /** * Returns true if value enough small */ - public static boolean isZero(double val) { + public static boolean isZero(float val) { return -DELTA < val && val < DELTA; } /** * Sort bound array */ - static void sortBound(double bound[], int bc) { + static void sortBound(float bound[], int bc) { for(int i = 0; i < bc - 4; i += 4) { int k = i; for(int j = i + 4; j < bc; j += 4) { @@ -535,7 +537,7 @@ public class Crossing { } } if (k != i) { - double tmp = bound[i]; + float tmp = bound[i]; bound[i] = bound[k]; bound[k] = tmp; tmp = bound[i + 1]; @@ -554,7 +556,7 @@ public class Crossing { /** * Returns are bounds intersect or not intersect rectangle */ - static int crossBound(double bound[], int bc, double py1, double py2) { + static int crossBound(float bound[], int bc, float py1, float py2) { // LEFT/RIGHT if (bc == 0) { @@ -599,7 +601,7 @@ public class Crossing { /** * Returns how many times rectangle stripe cross line or the are intersect */ - public static int intersectLine(double x1, double y1, double x2, double y2, double rx1, double ry1, double rx2, double ry2) { + public static int intersectLine(float x1, float y1, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { // LEFT/RIGHT/UP if ((rx2 < x1 && rx2 < x2) || @@ -619,7 +621,7 @@ public class Crossing { } // Build bound - double bx1, bx2; + float bx1, bx2; if (x1 < x2) { bx1 = x1 < rx1 ? rx1 : x1; bx2 = x2 < rx2 ? x2 : rx2; @@ -627,9 +629,9 @@ public class Crossing { bx1 = x2 < rx1 ? rx1 : x2; bx2 = x1 < rx2 ? x1 : rx2; } - double k = (y2 - y1) / (x2 - x1); - double by1 = k * (bx1 - x1) + y1; - double by2 = k * (bx2 - x1) + y1; + float k = (y2 - y1) / (x2 - x1); + float by1 = k * (bx1 - x1) + y1; + float by2 = k * (bx2 - x1) + y1; // BOUND-UP if (by1 < ry1 && by2 < ry1) { @@ -668,7 +670,7 @@ public class Crossing { /** * Returns how many times rectangle stripe cross quad curve or the are intersect */ - public static int intersectQuad(double x1, double y1, double cx, double cy, double x2, double y2, double rx1, double ry1, double rx2, double ry2) { + public static int intersectQuad(float x1, float y1, float cx, float cy, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { // LEFT/RIGHT/UP ------------------------------------------------------ if ((rx2 < x1 && rx2 < cx && rx2 < x2) || @@ -688,13 +690,13 @@ public class Crossing { // INSIDE ------------------------------------------------------------- QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2); - double px1 = rx1 - x1; - double py1 = ry1 - y1; - double px2 = rx2 - x1; - double py2 = ry2 - y1; + float px1 = rx1 - x1; + float py1 = ry1 - y1; + float px2 = rx2 - x1; + float py2 = ry2 - y1; - double res1[] = new double[3]; - double res2[] = new double[3]; + float res1[] = new float[3]; + float res2[] = new float[3]; int rc1 = c.solvePoint(res1, px1); int rc2 = c.solvePoint(res2, px2); @@ -704,9 +706,9 @@ public class Crossing { } // Build bound -------------------------------------------------------- - double minX = px1 - DELTA; - double maxX = px2 + DELTA; - double bound[] = new double[28]; + float minX = px1 - DELTA; + float maxX = px2 + DELTA; + float bound[] = new float[28]; int bc = 0; // Add roots bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0); @@ -716,13 +718,13 @@ public class Crossing { bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2); // Add start and end if (rx1 < x1 && x1 < rx2) { - bound[bc++] = 0.0; - bound[bc++] = 0.0; - bound[bc++] = 0.0; + bound[bc++] = 0.0f; + bound[bc++] = 0.0f; + bound[bc++] = 0.0f; bound[bc++] = 4; } if (rx1 < x2 && x2 < rx2) { - bound[bc++] = 1.0; + bound[bc++] = 1.0f; bound[bc++] = c.ax; bound[bc++] = c.ay; bound[bc++] = 5; @@ -739,7 +741,7 @@ public class Crossing { /** * Returns how many times rectangle stripe cross cubic curve or the are intersect */ - public static int intersectCubic(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2, double rx1, double ry1, double rx2, double ry2) { + public static int intersectCubic(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { // LEFT/RIGHT/UP if ((rx2 < x1 && rx2 < cx1 && rx2 < cx2 && rx2 < x2) || @@ -759,13 +761,13 @@ public class Crossing { // INSIDE CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2); - double px1 = rx1 - x1; - double py1 = ry1 - y1; - double px2 = rx2 - x1; - double py2 = ry2 - y1; + float px1 = rx1 - x1; + float py1 = ry1 - y1; + float px2 = rx2 - x1; + float py2 = ry2 - y1; - double res1[] = new double[3]; - double res2[] = new double[3]; + float res1[] = new float[3]; + float res2[] = new float[3]; int rc1 = c.solvePoint(res1, px1); int rc2 = c.solvePoint(res2, px2); @@ -774,11 +776,11 @@ public class Crossing { return 0; } - double minX = px1 - DELTA; - double maxX = px2 + DELTA; + float minX = px1 - DELTA; + float maxX = px2 + DELTA; // Build bound -------------------------------------------------------- - double bound[] = new double[40]; + float bound[] = new float[40]; int bc = 0; // Add roots bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0); @@ -790,13 +792,13 @@ public class Crossing { bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 4); // Add start and end if (rx1 < x1 && x1 < rx2) { - bound[bc++] = 0.0; - bound[bc++] = 0.0; - bound[bc++] = 0.0; + bound[bc++] = 0.0f; + bound[bc++] = 0.0f; + bound[bc++] = 0.0f; bound[bc++] = 6; } if (rx1 < x2 && x2 < rx2) { - bound[bc++] = 1.0; + bound[bc++] = 1.0f; bound[bc++] = c.ax; bound[bc++] = c.ay; bound[bc++] = 7; @@ -813,18 +815,18 @@ public class Crossing { /** * Returns how many times rectangle stripe cross path or the are intersect */ - public static int intersectPath(PathIterator p, double x, double y, double w, double h) { + public static int intersectPath(PathIterator p, float x, float y, float w, float h) { int cross = 0; int count; - double mx, my, cx, cy; - mx = my = cx = cy = 0.0; - double coords[] = new double[6]; + float mx, my, cx, cy; + mx = my = cx = cy = 0.0f; + float coords[] = new float[6]; - double rx1 = x; - double ry1 = y; - double rx2 = x + w; - double ry2 = y + h; + float rx1 = x; + float ry1 = y; + float rx2 = x + w; + float ry2 = y + h; while (!p.isDone()) { count = 0; @@ -872,11 +874,11 @@ public class Crossing { /** * Returns how many times rectangle stripe cross shape or the are intersect */ - public static int intersectShape(Shape s, double x, double y, double w, double h) { + public static int intersectShape(Path2D s, float x, float y, float w, float h) { if (!s.getBounds2D().intersects(x, y, w, h)) { return 0; } - return intersectPath(s.getPathIterator(null), x, y, w, h); + return intersectPath(s.iterator(null), x, y, w, h); } /** @@ -892,4 +894,4 @@ public class Crossing { public static boolean isInsideEvenOdd(int cross) { return (cross & 1) != 0; } -}
\ No newline at end of file +} |