Removed use of awt transforms.
This commit is contained in:
parent
9036edd6d6
commit
0f6812858a
|
@ -16,7 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.math4.geometry.euclidean.threed;
|
package org.apache.commons.math4.geometry.euclidean.threed;
|
||||||
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
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 tP00 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p00));
|
||||||
final Vector2D tP10 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p10));
|
final Vector2D tP10 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p10));
|
||||||
final Vector2D tP01 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p01));
|
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;
|
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);
|
return ((SubLine) sub).applyTransform(cachedTransform);
|
||||||
|
@ -660,12 +661,12 @@ public class PolyhedronsSet extends AbstractRegion<Euclidean3D, Euclidean2D> {
|
||||||
final Plane oPlane = (Plane) original;
|
final Plane oPlane = (Plane) original;
|
||||||
final Plane tPlane = (Plane) transformed;
|
final Plane tPlane = (Plane) transformed;
|
||||||
final Vector2D shift = tPlane.toSubSpace((Point<Euclidean3D>) apply(oPlane.getOrigin()));
|
final Vector2D shift = tPlane.toSubSpace((Point<Euclidean3D>) apply(oPlane.getOrigin()));
|
||||||
final AffineTransform at =
|
|
||||||
AffineTransform.getTranslateInstance(shift.getX(), shift.getY());
|
|
||||||
|
|
||||||
cachedOriginal = (Plane) original;
|
cachedOriginal = (Plane) original;
|
||||||
cachedTransform =
|
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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.math4.geometry.euclidean.twod;
|
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.MathIllegalArgumentException;
|
||||||
import org.apache.commons.math4.exception.util.LocalizedFormats;
|
import org.apache.commons.math4.exception.util.LocalizedFormats;
|
||||||
import org.apache.commons.math4.geometry.Point;
|
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
|
/** Get a {@link org.apache.commons.math4.geometry.partitioning.Transform
|
||||||
* Transform} embedding an affine transform.
|
* Transform} embedding an affine transform.
|
||||||
* @param transform affine transform to embed (must be inversible
|
* @param cXX transform factor between input abscissa and output abscissa
|
||||||
* otherwise the {@link
|
* @param cYX transform factor between input abscissa and output ordinate
|
||||||
* org.apache.commons.math4.geometry.partitioning.Transform#apply(Hyperplane)
|
* @param cXY transform factor between input ordinate and output abscissa
|
||||||
* apply(Hyperplane)} method would work only for some lines, and
|
* @param cYY transform factor between input ordinate and output ordinate
|
||||||
* fail for other ones)
|
* @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
|
* @return a new transform that can be applied to either {@link
|
||||||
* Vector2D Vector2D}, {@link Line Line} or {@link
|
* Vector2D Vector2D}, {@link Line Line} or {@link
|
||||||
* org.apache.commons.math4.geometry.partitioning.SubHyperplane
|
* org.apache.commons.math4.geometry.partitioning.SubHyperplane
|
||||||
* SubHyperplane} instances
|
* SubHyperplane} instances
|
||||||
* @exception MathIllegalArgumentException if the transform is non invertible
|
* @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 {
|
throws MathIllegalArgumentException {
|
||||||
return new LineTransform(transform);
|
return new LineTransform(cXX, cYX, cXY, cYY, cX1, cY1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Class embedding an affine transform.
|
/** 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> {
|
private static class LineTransform implements Transform<Euclidean2D, Euclidean1D> {
|
||||||
|
|
||||||
// CHECKSTYLE: stop JavadocVariable check
|
// CHECKSTYLE: stop JavadocVariable check
|
||||||
|
/** Transform factor between input abscissa and output abscissa. */
|
||||||
private final double cXX;
|
private final double cXX;
|
||||||
private final double cXY;
|
|
||||||
private final double cX1;
|
/** Transform factor between input abscissa and output ordinate. */
|
||||||
private final double cYX;
|
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;
|
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 cY1;
|
||||||
|
|
||||||
private final double c1Y;
|
private final double c1Y;
|
||||||
|
@ -461,21 +477,25 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
|
||||||
// CHECKSTYLE: resume JavadocVariable check
|
// CHECKSTYLE: resume JavadocVariable check
|
||||||
|
|
||||||
/** Build an affine line transform from a n {@code AffineTransform}.
|
/** Build an affine line transform from a n {@code AffineTransform}.
|
||||||
* @param transform transform to use (must be invertible otherwise
|
* @param cXX transform factor between input abscissa and output abscissa
|
||||||
* the {@link LineTransform#apply(Hyperplane)} method would work
|
* @param cYX transform factor between input abscissa and output ordinate
|
||||||
* only for some lines, and fail for other ones)
|
* @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
|
* @exception MathIllegalArgumentException if the transform is non invertible
|
||||||
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public LineTransform(final AffineTransform transform) throws MathIllegalArgumentException {
|
public LineTransform(final double cXX, final double cYX, final double cXY,
|
||||||
|
final double cYY, final double cX1, final double cY1)
|
||||||
|
throws MathIllegalArgumentException {
|
||||||
|
|
||||||
final double[] m = new double[6];
|
this.cXX = cXX;
|
||||||
transform.getMatrix(m);
|
this.cYX = cYX;
|
||||||
cXX = m[0];
|
this.cXY = cXY;
|
||||||
cXY = m[2];
|
this.cYY = cYY;
|
||||||
cX1 = m[4];
|
this.cX1 = cX1;
|
||||||
cYX = m[1];
|
this.cY1 = cY1;
|
||||||
cYY = m[3];
|
|
||||||
cY1 = m[5];
|
|
||||||
|
|
||||||
c1Y = MathArrays.linearCombination(cXY, cY1, -cYY, cX1);
|
c1Y = MathArrays.linearCombination(cXY, cY1, -cYY, cX1);
|
||||||
c1X = MathArrays.linearCombination(cXX, cY1, -cYX, cX1);
|
c1X = MathArrays.linearCombination(cXX, cY1, -cYX, cX1);
|
||||||
|
|
|
@ -28,8 +28,6 @@ import org.apache.commons.math4.util.FastMath;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
|
|
||||||
public class LineTest {
|
public class LineTest {
|
||||||
|
|
||||||
@Test
|
@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);
|
Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0), 1.0e-10);
|
||||||
Transform<Euclidean2D, Euclidean1D> t1 =
|
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,
|
Assert.assertEquals(0.5 * FastMath.PI,
|
||||||
((Line) t1.apply(l1)).getAngle(),
|
((Line) t1.apply(l1)).getAngle(),
|
||||||
1.0e-10);
|
1.0e-10);
|
||||||
|
|
||||||
Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0), 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 =
|
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),
|
Assert.assertEquals(FastMath.atan2(1.0, -2.0),
|
||||||
((Line) t2.apply(l2)).getAngle(),
|
((Line) t2.apply(l2)).getAngle(),
|
||||||
1.0e-10);
|
1.0e-10);
|
||||||
|
|
Loading…
Reference in New Issue