You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2015/07/10 15:35:23 UTC
[math] Removed use of awt transforms.
Repository: commons-math
Updated Branches:
refs/heads/master 9036edd6d -> 0f6812858
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/0f681285
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0f681285
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0f681285
Branch: refs/heads/master
Commit: 0f6812858ad6e3b28e4a2843c526ec8cf501b176
Parents: 9036edd
Author: Luc Maisonobe <lu...@apache.org>
Authored: Fri Jul 10 15:19:54 2015 +0200
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Fri Jul 10 15:33:10 2015 +0200
----------------------------------------------------------------------
.../euclidean/threed/PolyhedronsSet.java | 19 +++---
.../math4/geometry/euclidean/twod/Line.java | 68 +++++++++++++-------
.../math4/geometry/euclidean/twod/LineTest.java | 6 +-
3 files changed, 56 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/0f681285/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSet.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSet.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSet.java
index 9de30ce..da6ba93 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSet.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSet.java
@@ -16,7 +16,6 @@
*/
package org.apache.commons.math4.geometry.euclidean.threed;
-import java.awt.geom.AffineTransform;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -595,13 +594,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.math4.geometry.euclidean.twod.Line.getTransform(at);
+ cachedTransform =
+ org.apache.commons.math4.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);
@@ -660,12 +661,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.math4.geometry.euclidean.twod.Line.getTransform(at);
+ org.apache.commons.math4.geometry.euclidean.twod.Line.getTransform(1, 0, 0, 1,
+ shift.getX(),
+ shift.getY());
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/0f681285/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java
index 3bfae8d..9f7d578 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java
@@ -16,8 +16,6 @@
*/
package org.apache.commons.math4.geometry.euclidean.twod;
-import java.awt.geom.AffineTransform;
-
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.geometry.Point;
@@ -422,20 +420,27 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
/** Get a {@link org.apache.commons.math4.geometry.partitioning.Transform
* Transform} embedding an affine transform.
- * @param transform affine transform to embed (must be inversible
- * otherwise the {@link
- * org.apache.commons.math4.geometry.partitioning.Transform#apply(Hyperplane)
- * 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
* @return a new transform that can be applied to either {@link
* Vector2D Vector2D}, {@link Line Line} or {@link
* org.apache.commons.math4.geometry.partitioning.SubHyperplane
* SubHyperplane} instances
* @exception MathIllegalArgumentException if the transform is non invertible
+ * @since 4.0
*/
- public static Transform<Euclidean2D, Euclidean1D> getTransform(final AffineTransform transform)
+ 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(transform);
+ return new LineTransform(cXX, cYX, cXY, cYY, cX1, cY1);
}
/** Class embedding an affine transform.
@@ -448,11 +453,22 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
private static class LineTransform implements Transform<Euclidean2D, Euclidean1D> {
// CHECKSTYLE: stop JavadocVariable check
+ /** Transform factor between input abscissa and output abscissa. */
private final double cXX;
- private final double cXY;
- private final double cX1;
+
+ /** Transform factor between input abscissa and output ordinate. */
private final double cYX;
+
+ /** Transform factor between input ordinate and output abscissa. */
+ private final double cXY;
+
+ /** Transform factor between input ordinate and output ordinate. */
private final double cYY;
+
+ /** Transform addendum for output abscissa. */
+ private final double cX1;
+
+ /** Transform addendum for output ordinate. */
private final double cY1;
private final double c1Y;
@@ -461,21 +477,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 4.0
*/
- 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/0f681285/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/LineTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/LineTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/LineTest.java
index f7e3379..a7810e7 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/LineTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/LineTest.java
@@ -28,8 +28,6 @@ import org.apache.commons.math4.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
-import java.awt.geom.AffineTransform;
-
public class LineTest {
@Test
@@ -112,14 +110,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);