Repository: commons-math Updated Branches: refs/heads/MATH_3_X a01916248 -> 759fed8a7
Removed use of awt transforms. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/759fed8a Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/759fed8a Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/759fed8a Branch: refs/heads/MATH_3_X Commit: 759fed8a76744f1d64a63c44b53eaae62c87b853 Parents: a019162 Author: Luc Maisonobe <l...@apache.org> Authored: Fri Jul 10 15:28:53 2015 +0200 Committer: Luc Maisonobe <l...@apache.org> Committed: Fri Jul 10 15:28:53 2015 +0200 ---------------------------------------------------------------------- .../euclidean/threed/PolyhedronsSet.java | 19 +++--- .../math3/geometry/euclidean/twod/Line.java | 61 +++++++++++++++----- .../math3/geometry/euclidean/twod/LineTest.java | 6 +- 3 files changed, 59 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/759fed8a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java index b06113b..7116c11 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java @@ -16,7 +16,6 @@ */ package org.apache.commons.math3.geometry.euclidean.threed; -import java.awt.geom.AffineTransform; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -658,13 +657,15 @@ public class PolyhedronsSet extends AbstractRegion<Euclidean3D, Euclidean2D> { final Vector2D tP00 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p00)); final Vector2D tP10 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p10)); final Vector2D tP01 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p01)); - final AffineTransform at = - new AffineTransform(tP10.getX() - tP00.getX(), tP10.getY() - tP00.getY(), - tP01.getX() - tP00.getX(), tP01.getY() - tP00.getY(), - tP00.getX(), tP00.getY()); cachedOriginal = (Plane) original; - cachedTransform = org.apache.commons.math3.geometry.euclidean.twod.Line.getTransform(at); + cachedTransform = + org.apache.commons.math3.geometry.euclidean.twod.Line.getTransform(tP10.getX() - tP00.getX(), + tP10.getY() - tP00.getY(), + tP01.getX() - tP00.getX(), + tP01.getY() - tP00.getY(), + tP00.getX(), + tP00.getY()); } return ((SubLine) sub).applyTransform(cachedTransform); @@ -720,12 +721,12 @@ public class PolyhedronsSet extends AbstractRegion<Euclidean3D, Euclidean2D> { final Plane oPlane = (Plane) original; final Plane tPlane = (Plane) transformed; final Vector2D shift = tPlane.toSubSpace((Point<Euclidean3D>) apply(oPlane.getOrigin())); - final AffineTransform at = - AffineTransform.getTranslateInstance(shift.getX(), shift.getY()); cachedOriginal = (Plane) original; cachedTransform = - org.apache.commons.math3.geometry.euclidean.twod.Line.getTransform(at); + org.apache.commons.math3.geometry.euclidean.twod.Line.getTransform(1, 0, 0, 1, + shift.getX(), + shift.getY()); } http://git-wip-us.apache.org/repos/asf/commons-math/blob/759fed8a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java index d6fd487..b5587ad 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java @@ -447,10 +447,39 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc * org.apache.commons.math3.geometry.partitioning.SubHyperplane * SubHyperplane} instances * @exception MathIllegalArgumentException if the transform is non invertible + * @deprecated as of 3.6, replaced with {@link #getTransform(double, double, double, double, double, double)} */ + @Deprecated public static Transform<Euclidean2D, Euclidean1D> getTransform(final AffineTransform transform) throws MathIllegalArgumentException { - return new LineTransform(transform); + final double[] m = new double[6]; + transform.getMatrix(m); + return new LineTransform(m[0], m[1], m[2], m[3], m[4], m[5]); + } + + /** Get a {@link org.apache.commons.math3.geometry.partitioning.Transform + * Transform} embedding an affine transform. + * @param cXX transform factor between input abscissa and output abscissa + * @param cYX transform factor between input abscissa and output ordinate + * @param cXY transform factor between input ordinate and output abscissa + * @param cYY transform factor between input ordinate and output ordinate + * @param cX1 transform addendum for output abscissa + * @param cY1 transform addendum for output ordinate + * @return a new transform that can be applied to either {@link + * Vector2D Vector2D}, {@link Line Line} or {@link + * org.apache.commons.math3.geometry.partitioning.SubHyperplane + * SubHyperplane} instances + * @exception MathIllegalArgumentException if the transform is non invertible + * @since 3.6 + */ + public static Transform<Euclidean2D, Euclidean1D> getTransform(final double cXX, + final double cYX, + final double cXY, + final double cYY, + final double cX1, + final double cY1) + throws MathIllegalArgumentException { + return new LineTransform(cXX, cYX, cXY, cYY, cX1, cY1); } /** Class embedding an affine transform. @@ -476,21 +505,25 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc // CHECKSTYLE: resume JavadocVariable check /** Build an affine line transform from a n {@code AffineTransform}. - * @param transform transform to use (must be invertible otherwise - * the {@link LineTransform#apply(Hyperplane)} method would work - * only for some lines, and fail for other ones) + * @param cXX transform factor between input abscissa and output abscissa + * @param cYX transform factor between input abscissa and output ordinate + * @param cXY transform factor between input ordinate and output abscissa + * @param cYY transform factor between input ordinate and output ordinate + * @param cX1 transform addendum for output abscissa + * @param cY1 transform addendum for output ordinate * @exception MathIllegalArgumentException if the transform is non invertible + * @since 3.6 */ - public LineTransform(final AffineTransform transform) throws MathIllegalArgumentException { - - final double[] m = new double[6]; - transform.getMatrix(m); - cXX = m[0]; - cXY = m[2]; - cX1 = m[4]; - cYX = m[1]; - cYY = m[3]; - cY1 = m[5]; + public LineTransform(final double cXX, final double cYX, final double cXY, + final double cYY, final double cX1, final double cY1) + throws MathIllegalArgumentException { + + this.cXX = cXX; + this.cYX = cYX; + this.cXY = cXY; + this.cYY = cYY; + this.cX1 = cX1; + this.cY1 = cY1; c1Y = MathArrays.linearCombination(cXY, cY1, -cYY, cX1); c1X = MathArrays.linearCombination(cXX, cY1, -cYX, cX1); http://git-wip-us.apache.org/repos/asf/commons-math/blob/759fed8a/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/LineTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/LineTest.java b/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/LineTest.java index 8ce43fd..2c5d5f8 100644 --- a/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/LineTest.java +++ b/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/LineTest.java @@ -27,8 +27,6 @@ import org.apache.commons.math3.util.FastMath; import org.junit.Assert; import org.junit.Test; -import java.awt.geom.AffineTransform; - public class LineTest { @Test @@ -111,14 +109,14 @@ public class LineTest { Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0), 1.0e-10); Transform<Euclidean2D, Euclidean1D> t1 = - Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5)); + Line.getTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5); Assert.assertEquals(0.5 * FastMath.PI, ((Line) t1.apply(l1)).getAngle(), 1.0e-10); Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0), 1.0e-10); Transform<Euclidean2D, Euclidean1D> t2 = - Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5)); + Line.getTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5); Assert.assertEquals(FastMath.atan2(1.0, -2.0), ((Line) t2.apply(l2)).getAngle(), 1.0e-10);