You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2018/06/18 09:44:37 UTC
[sis] 26/31: Move PassThroughTransform.create(…) method to MathTransforms.passThrough(…).
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 7c856886b41d80263472173a1c7af39ed74af696
Author: Martin Desruisseaux <de...@apache.org>
AuthorDate: Fri Jun 8 13:06:22 2018 +0000
Move PassThroughTransform.create(…) method to MathTransforms.passThrough(…).
git-svn-id: https://svn.apache.org/repos/asf/sis/branches/JDK8@1833165 13f79535-47bb-0310-9956-ffa450edef68
---
.../operation/DefaultPassThroughOperation.java | 5 +-
.../operation/transform/ConcatenatedTransform.java | 2 +-
.../transform/DefaultMathTransformFactory.java | 2 +-
.../operation/transform/MathTransforms.java | 45 ++++++++++++++-
.../operation/transform/PassThroughTransform.java | 64 ++++++++++------------
.../transform/ConcatenatedTransformTest.java | 2 +-
.../operation/transform/MathTransformsTest.java | 2 +-
.../transform/PassThroughTransformTest.java | 8 +--
.../transform/TransformSeparatorTest.java | 2 +-
9 files changed, 86 insertions(+), 46 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPassThroughOperation.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPassThroughOperation.java
index cca675d..8593199 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPassThroughOperation.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPassThroughOperation.java
@@ -27,6 +27,7 @@ import org.opengis.referencing.operation.CoordinateOperation;
import org.opengis.referencing.operation.PassThroughOperation;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.crs.CompoundCRS;
+import org.apache.sis.referencing.operation.transform.MathTransforms;
import org.apache.sis.referencing.operation.transform.PassThroughTransform;
import org.apache.sis.internal.referencing.ReferencingUtilities;
import org.apache.sis.internal.metadata.MetadataUtilities;
@@ -109,7 +110,7 @@ public class DefaultPassThroughOperation extends AbstractCoordinateOperation imp
final int firstAffectedOrdinate,
final int numTrailingOrdinates)
{
- super(properties, sourceCRS, targetCRS, null, PassThroughTransform.create(
+ super(properties, sourceCRS, targetCRS, null, MathTransforms.passThrough(
firstAffectedOrdinate, operation.getMathTransform(), numTrailingOrdinates));
ArgumentChecks.ensureNonNull("operation", operation);
this.operation = operation;
@@ -350,7 +351,7 @@ public class DefaultPassThroughOperation extends AbstractCoordinateOperation imp
Errors.Keys.CanNotAssign_2, missing, Arrays.toString(ordinates)));
}
}
- transform = PassThroughTransform.create(ordinates[0] - 1, operation.getMathTransform(),
+ transform = MathTransforms.passThrough(ordinates[0] - 1, operation.getMathTransform(),
ReferencingUtilities.getDimension(sourceCRS) - ordinates[ordinates.length - 1]);
return;
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
index 8df182e..3f32b61 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
@@ -309,7 +309,7 @@ class ConcatenatedTransform extends AbstractMathTransform implements Serializabl
factory.createConcatenatedTransform(factory.createAffineTransform(sub), candidate.subTransform),
candidate.numTrailingOrdinates);
} else {
- return PassThroughTransform.create(
+ return MathTransforms.passThrough(
candidate.firstAffectedOrdinate,
create(MathTransforms.linear(sub), candidate.subTransform, factory),
candidate.numTrailingOrdinates);
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
index ee6ba2e..09868e3 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
@@ -1347,7 +1347,7 @@ public class DefaultMathTransformFactory extends AbstractFactory implements Math
lastMethod.remove();
final MathTransform tr;
try {
- tr = PassThroughTransform.create(firstAffectedOrdinate, subTransform, numTrailingOrdinates);
+ tr = MathTransforms.passThrough(firstAffectedOrdinate, subTransform, numTrailingOrdinates);
} catch (IllegalArgumentException exception) {
throw new InvalidGeodeticParameterException(exception.getLocalizedMessage(), exception);
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
index d6ecdbd..c62765d 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
@@ -220,6 +220,49 @@ public final class MathTransforms extends Static {
}
/**
+ * Creates a transform which passes through a subset of coordinates to another transform.
+ * This method returns a transform having the following dimensions:
+ *
+ * {@preformat java
+ * Source: firstAffectedOrdinate + subTransform.getSourceDimensions() + numTrailingOrdinates
+ * Target: firstAffectedOrdinate + subTransform.getTargetDimensions() + numTrailingOrdinates
+ * }
+ *
+ * Affected ordinates will range from {@code firstAffectedOrdinate} inclusive to
+ * {@code dimTarget - numTrailingOrdinates} exclusive.
+ *
+ * @param firstAffectedOrdinate index of the first affected ordinate.
+ * @param subTransform the sub-transform to apply on modified coordinates.
+ * @param numTrailingOrdinates number of trailing ordinates to pass through.
+ * @return a pass-through transform, potentially as a {@link PassThroughTransform} instance but not necessarily.
+ *
+ * @since 1.0
+ */
+ public static MathTransform passThrough(final int firstAffectedOrdinate,
+ final MathTransform subTransform,
+ final int numTrailingOrdinates)
+ {
+ ArgumentChecks.ensureNonNull ("subTransform", subTransform);
+ ArgumentChecks.ensurePositive("firstAffectedOrdinate", firstAffectedOrdinate);
+ ArgumentChecks.ensurePositive("numTrailingOrdinates", numTrailingOrdinates);
+ if (firstAffectedOrdinate == 0 && numTrailingOrdinates == 0) {
+ return subTransform;
+ }
+ if (subTransform.isIdentity()) {
+ final int dimension = subTransform.getSourceDimensions();
+ if (dimension == subTransform.getTargetDimensions()) {
+ return IdentityTransform.create(firstAffectedOrdinate + dimension + numTrailingOrdinates);
+ }
+ }
+ final Matrix matrix = getMatrix(subTransform);
+ if (matrix != null) {
+ return linear(PassThroughTransform.asMatrix(firstAffectedOrdinate, matrix, numTrailingOrdinates));
+ } else {
+ return PassThroughTransform.newInstance(firstAffectedOrdinate, subTransform, numTrailingOrdinates);
+ }
+ }
+
+ /**
* Puts together a list of independent math transforms, each of them operating on a subset of ordinate values.
* This method is often used for defining 4-dimensional (<var>x</var>,<var>y</var>,<var>z</var>,<var>t</var>)
* transform as an aggregation of 3 simpler transforms operating on (<var>x</var>,<var>y</var>), (<var>z</var>)
@@ -254,7 +297,7 @@ public final class MathTransforms extends Static {
int firstAffectedOrdinate = 0;
for (int i=0; i<transforms.length; i++) {
MathTransform tr = transforms[i];
- tr = PassThroughTransform.create(firstAffectedOrdinate, tr, sum - (firstAffectedOrdinate += dimensions[i]));
+ tr = passThrough(firstAffectedOrdinate, tr, sum - (firstAffectedOrdinate += dimensions[i]));
if (compound == null) {
compound = tr;
} else {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
index bd5f381..4ada705 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
@@ -37,7 +37,7 @@ import static org.apache.sis.util.ArgumentChecks.*;
/**
* Transform which passes through a subset of ordinates to another transform.
- * This allows transforms to operate on a subset of ordinates.
+ * This allows transforms to operate on a subset of coordinate values.
*
* <div class="note"><b>Example:</b> giving (<var>latitude</var>, <var>longitude</var>, <var>height</var>) coordinates,
* {@code PassThroughTransform} can convert the height values from feet to meters without affecting the latitude and
@@ -45,7 +45,7 @@ import static org.apache.sis.util.ArgumentChecks.*;
*
* {@preformat java
* MathTransform feetToMetres = MathTransforms.linear(0.3048, 0); // One-dimensional conversion.
- * MathTransform tr = PassThroughTransform.create(2, feetToMetres, 0); // Three-dimensional conversion.
+ * MathTransform tr = MathTransforms.passThrough(2, feetToMetres, 0); // Three-dimensional conversion.
* }
* </div>
*
@@ -58,8 +58,9 @@ import static org.apache.sis.util.ArgumentChecks.*;
* Serialization should be used only for short term storage or RMI between applications running the same SIS version.
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 0.5
+ * @version 1.0
*
+ * @see MathTransforms#passThrough(int, MathTransform, int)
* @see MathTransforms#compound(MathTransform...)
*
* @since 0.5
@@ -99,7 +100,7 @@ public class PassThroughTransform extends AbstractMathTransform implements Seria
/**
* Constructor for sub-classes.
- * Users should invoke the static {@link #create(int, MathTransform, int)} factory method instead,
+ * Users should invoke the static {@link MathTransforms#passThrough(int, MathTransform, int)} factory method instead,
* since the most optimal pass-through transform for the given {@code subTransform} is not necessarily
* a {@code PassThroughTransform} instance.
*
@@ -107,7 +108,7 @@ public class PassThroughTransform extends AbstractMathTransform implements Seria
* @param subTransform the sub-transform to apply on modified coordinates.
* @param numTrailingOrdinates number of trailing ordinates to pass through.
*
- * @see #create(int, MathTransform, int)
+ * @see MathTransforms#passThrough(int, MathTransform, int)
*/
protected PassThroughTransform(final int firstAffectedOrdinate,
final MathTransform subTransform,
@@ -143,40 +144,35 @@ public class PassThroughTransform extends AbstractMathTransform implements Seria
* @param subTransform the sub-transform to apply on modified coordinates.
* @param numTrailingOrdinates number of trailing ordinates to pass through.
* @return a pass-through transform, not necessarily a {@code PassThroughTransform} instance.
+ *
+ * @deprecated Moved to {@link MathTransforms#passThrough(int, MathTransform, int)}.
*/
+ @Deprecated
public static MathTransform create(final int firstAffectedOrdinate,
final MathTransform subTransform,
final int numTrailingOrdinates)
{
- ensureNonNull ("subTransform", subTransform);
- ensurePositive("firstAffectedOrdinate", firstAffectedOrdinate);
- ensurePositive("numTrailingOrdinates", numTrailingOrdinates);
- if (firstAffectedOrdinate == 0 && numTrailingOrdinates == 0) {
- return subTransform;
- }
- /*
- * Optimizes the "Identity transform" case.
- */
- if (subTransform.isIdentity()) {
- final int dimension = subTransform.getSourceDimensions();
- if (dimension == subTransform.getTargetDimensions()) {
- return IdentityTransform.create(firstAffectedOrdinate + dimension + numTrailingOrdinates);
- }
- }
- /*
- * Special case for transformation backed by a matrix. Is is possible to use a
- * new matrix for such transform, instead of wrapping the sub-transform into a
- * PassThroughTransform object. It is faster and easier to concatenate.
- */
- Matrix matrix = MathTransforms.getMatrix(subTransform);
- if (matrix != null) {
- matrix = expand(MatrixSIS.castOrCopy(matrix), firstAffectedOrdinate, numTrailingOrdinates, 1);
- return MathTransforms.linear(matrix);
- }
- /*
- * Constructs the general PassThroughTransform object. An optimization is done right in
- * the constructor for the case where the sub-transform is already a PassThroughTransform.
- */
+ return MathTransforms.passThrough(firstAffectedOrdinate, subTransform, numTrailingOrdinates);
+ }
+
+ /**
+ * Special case for transformation backed by a matrix. Is is possible to use a new matrix for such transform,
+ * instead of wrapping the sub-transform into a {@code PassThroughTransform} object. It is faster and easier
+ * to concatenate.
+ */
+ static Matrix asMatrix(final int firstAffectedOrdinate, final Matrix subTransform, final int numTrailingOrdinates) {
+ return expand(MatrixSIS.castOrCopy(subTransform), firstAffectedOrdinate, numTrailingOrdinates, 1);
+ }
+
+ /**
+ * Constructs the general {@code PassThroughTransform} object. An optimization is done right in
+ * the constructor for the case where the sub-transform is already a {@code PassThroughTransform}.
+ * It is caller's responsibility to ensure that the argument values are valid.
+ */
+ static PassThroughTransform newInstance(final int firstAffectedOrdinate,
+ final MathTransform subTransform,
+ final int numTrailingOrdinates)
+ {
int dim = subTransform.getSourceDimensions();
if (subTransform.getTargetDimensions() == dim) {
dim += firstAffectedOrdinate + numTrailingOrdinates;
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
index bab34a4..fefe495 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
@@ -118,7 +118,7 @@ public final strictfp class ConcatenatedTransformTest extends MathTransformTestC
@Test
public void testPassthrough() throws FactoryException {
final MathTransform kernel = new PseudoTransform(2, 3); // Any non-linear transform.
- final MathTransform passth = PassThroughTransform.create(0, kernel, 1);
+ final MathTransform passth = MathTransforms.passThrough(0, kernel, 1);
final Matrix4 matrix = new Matrix4();
transform = ConcatenatedTransform.create(MathTransforms.linear(matrix), passth, null);
assertSame("Identity transform should be ignored.", passth, transform);
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
index 625e773..9a3c6cf 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
@@ -70,7 +70,7 @@ public final strictfp class MathTransformsTest extends TestCase {
swap.m00 = 0; swap.m01 = 1;
swap.m10 = 1; swap.m11 = 0;
MathTransform tr = ExponentialTransform1D.create(10, 1);
- tr = PassThroughTransform.create(1, tr, 1);
+ tr = MathTransforms.passThrough(1, tr, 1);
tr = new ConcatenatedTransformDirect(MathTransforms.linear(scale), tr); // See "implementation note" above.
tr = new ConcatenatedTransformDirect(tr, MathTransforms.linear(swap));
return tr;
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
index 7a09bda..1f8acee 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
@@ -56,20 +56,20 @@ public final strictfp class PassThroughTransformTest extends MathTransformTestCa
private Random random;
/**
- * Verifies argument validation performed by {@link PassThroughTransform#create(int, MathTransform, int)}.
+ * Verifies argument validation performed by {@link MathTransforms#passThrough(int, MathTransform, int)}.
*/
@Test
public void testIllegalArgument() {
final MathTransform subTransform = MathTransforms.identity(1);
try {
- PassThroughTransform.create(-1, subTransform, 0);
+ MathTransforms.passThrough(-1, subTransform, 0);
fail("An illegal argument should have been detected");
} catch (IllegalArgumentException e) {
final String message = e.getMessage();
assertTrue(message, message.contains("firstAffectedOrdinate"));
}
try {
- PassThroughTransform.create(0, subTransform, -1);
+ MathTransforms.passThrough(0, subTransform, -1);
fail("An illegal argument should have been detected");
} catch (IllegalArgumentException e) {
final String message = e.getMessage();
@@ -134,7 +134,7 @@ public final strictfp class PassThroughTransformTest extends MathTransformTestCa
for (int firstAffectedOrdinate=0; firstAffectedOrdinate<=3; firstAffectedOrdinate++) {
for (int numTrailingOrdinates=0; numTrailingOrdinates<=3; numTrailingOrdinates++) {
final int numAdditionalOrdinates = firstAffectedOrdinate + numTrailingOrdinates;
- transform = PassThroughTransform.create(firstAffectedOrdinate, subTransform, numTrailingOrdinates);
+ transform = MathTransforms.passThrough(firstAffectedOrdinate, subTransform, numTrailingOrdinates);
if (numAdditionalOrdinates == 0) {
assertSame("Failed to recognize that no passthrough was needed.", subTransform, transform);
continue;
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformSeparatorTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformSeparatorTest.java
index 53866a0..64eb9fa 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformSeparatorTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformSeparatorTest.java
@@ -210,7 +210,7 @@ public final strictfp class TransformSeparatorTest extends TestCase {
public void testPassThroughTransform() throws FactoryException {
final MathTransform nonLinear = new EllipsoidToCentricTransform(6378137, 6356752.314245179,
Units.METRE, false, EllipsoidToCentricTransform.TargetType.CARTESIAN);
- final TransformSeparator s = new TransformSeparator(PassThroughTransform.create(2, nonLinear, 3));
+ final TransformSeparator s = new TransformSeparator(MathTransforms.passThrough(2, nonLinear, 3));
/*
* Trivial case: no dimension specified, we should get the transform unchanged.
*/
--
To stop receiving notification emails like this one, please contact
desruisseaux@apache.org.