sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1653351 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/internal/referencing/ test/java/org/apache/sis/refe...
Date Tue, 20 Jan 2015 19:54:45 GMT
Author: desruisseaux
Date: Tue Jan 20 19:54:45 2015
New Revision: 1653351

URL: http://svn.apache.org/r1653351
Log:
Removed MathTransforms.getCore(...) from public API, because its contract is not clear enough.
Its functionality moved to the internal OperationMethods.checkDimensions(...) method, since
the
only purpose of 'getCore' was to help checking the source/target dimensions compatibility.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
      - copied, changed from r1653288, sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
      - copied, changed from r1653288, sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Copied: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
(from r1653288, sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java?p2=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java&p1=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java&r1=1653288&r2=1653351&rev=1653351&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/OperationMethods.java
[UTF-8] Tue Jan 20 19:54:45 2015
@@ -14,320 +14,109 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.referencing.operation.transform;
+package org.apache.sis.internal.referencing;
 
-import java.util.List;
-import java.util.Collections;
-import java.awt.geom.AffineTransform;
-import org.opengis.geometry.MismatchedDimensionException;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.operation.MathTransform1D;
-import org.opengis.referencing.operation.MathTransform2D;
-import org.opengis.referencing.operation.TransformException;
-import org.opengis.referencing.operation.MathTransformFactory;
-import org.apache.sis.internal.referencing.DirectPositionView;
-import org.apache.sis.internal.referencing.ExtendedPrecisionMatrix;
-import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
-import org.apache.sis.referencing.operation.matrix.AffineTransforms2D;
-import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.opengis.referencing.operation.OperationMethod;
+import org.apache.sis.referencing.operation.transform.MathTransforms;
+import org.apache.sis.referencing.operation.transform.PassThroughTransform;
+import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.Static;
 
-import static org.apache.sis.util.ArgumentChecks.*;
-
 
 /**
- * Utility methods creating or working on {@link MathTransform} instances.
- * This class centralizes in one place some of the most commonly used functions this package.
- * The {@code MathTransforms} class provides the following services:
- *
- * <ul>
- *   <li>Create various SIS implementations of {@link MathTransform}.</li>
- *   <li>Perform non-standard operations on arbitrary instances.</li>
- * </ul>
- *
- * The factory static methods are provided as convenient alternatives to the GeoAPI {@link
MathTransformFactory}
- * interface. However users seeking for more implementation neutrality are encouraged to
limit themselves to the
- * GeoAPI factory interfaces instead.
+ * Utility methods related to {@link OperationMethod} and {@link MathTransform} instances.
+ * Not in public API because the contract of those methods is not clear or is disputable.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5 (derived from geotk-3.20)
  * @version 0.5
  * @module
- *
- * @see MathTransformFactory
  */
-public final class MathTransforms extends Static {
+public final class OperationMethods extends Static {
     /**
      * Do not allow instantiation of this class.
      */
-    private MathTransforms() {
+    private OperationMethods() {
     }
 
     /**
-     * Returns an identity transform of the specified dimension.
+     * Checks if an operation method and a math transform have a compatible number of source
and target dimensions.
+     * In the particular case of a {@linkplain PassThroughTransform pass through transform}
with more dimensions
+     * than what we would expect from the given method, the check will rather be performed
against the
+     * {@linkplain PassThroughTransform#getSubTransform() sub transform}.
      *
-     * <p>Special cases:</p>
-     * <ul>
-     *   <li>If {@code dimension == 1}, then the returned transform implements {@link
MathTransform1D}.</li>
-     *   <li>If {@code dimension == 2}, then the returned transform implements {@link
MathTransform2D}.</li>
-     * </ul>
+     * <p>The intend is to allow creation of a three-dimensional {@code ProjectedCRS}
with a two-dimensional
+     * {@code OperationMethod}, where the third-dimension just pass through. This is not
a recommended approach
+     * and we do not document that as a supported feature, but we do not prevent it neither.</p>
      *
-     * @param dimension The dimension of the transform to be returned.
-     * @return An identity transform of the specified dimension.
-     */
-    public static LinearTransform identity(final int dimension) {
-        ensureStrictlyPositive("dimension", dimension);
-        return IdentityTransform.create(dimension);
-    }
-
-    /**
-     * Creates a one-dimensional affine transform for the given coefficients.
-     * Input values <var>x</var> will be converted into output values <var>y</var>
using the following equation:
+     * <p>This method tries to locates what seems to be the "core" of the given math
transform. The definition
+     * of "core" is imprecise and may be adjusted in future SIS versions. The current algorithm
is as below:</p>
      *
-     * <blockquote><var>y</var>  =  <var>x</var> ⋅ {@code
scale} + {@code offset}</blockquote>
-     *
-     * @param  scale  The {@code scale}  term in the linear equation.
-     * @param  offset The {@code offset} term in the linear equation.
-     * @return The linear transform for the given scale and offset.
-     */
-    public static LinearTransform linear(final double scale, final double offset) {
-        return LinearTransform1D.create(scale, offset);
-    }
-
-    /**
-     * Creates an arbitrary linear transform from the specified matrix. Usually the matrix
-     * {@linkplain org.apache.sis.referencing.operation.matrix.MatrixSIS#isAffine() is affine},
-     * but this is not mandatory. Non-affine matrix will define a projective transform.
-     *
-     * <p>If the transform input dimension is {@code M}, and output dimension is {@code
N},
-     * then the given matrix shall have size {@code [N+1][M+1]}.
-     * The +1 in the matrix dimensions allows the matrix to do a shift, as well as a rotation.
-     * The {@code [M][j]} element of the matrix will be the <var>j</var>'th ordinate
of the moved origin.</p>
-     *
-     * @param  matrix The matrix used to define the linear transform.
-     * @return The linear (usually affine) transform.
+     * <ul>
+     *   <li>If the given transform can be decomposed in {@linkplain MathTransforms#getSteps(MathTransform)
steps},
+     *       then the steps for {@linkplain org.apache.sis.referencing.cs.CoordinateSystems#swapAndScaleAxes
axis
+     *       swapping and scaling} are ignored.</li>
+     *   <li>If the given transform or its non-ignorable step is a {@link PassThroughTransform},
then its sub-transform
+     *       is taken. Only one non-ignorable step may exist, otherwise we do not try to
select any of them.</li>
+     * </ul>
      *
-     * @see org.opengis.referencing.operation.MathTransformFactory#createAffineTransform(Matrix)
-     */
-    public static LinearTransform linear(final Matrix matrix) {
-        ensureNonNull("matrix", matrix);
-        final int sourceDimension = matrix.getNumCol() - 1;
-        final int targetDimension = matrix.getNumRow() - 1;
-        if (sourceDimension == targetDimension) {
-            if (matrix.isIdentity()) {
-                return identity(sourceDimension);
-            }
-            if (Matrices.isAffine(matrix)) {
-                switch (sourceDimension) {
-                    case 1: {
-                        return linear(matrix.getElement(0,0), matrix.getElement(0,1));
-                    }
-                    case 2: {
-                        if (matrix instanceof ExtendedPrecisionMatrix) {
-                            return new AffineTransform2D(((ExtendedPrecisionMatrix) matrix).getExtendedElements());
-                        } else {
-                            return new AffineTransform2D(
-                                    matrix.getElement(0,0), matrix.getElement(1,0),
-                                    matrix.getElement(0,1), matrix.getElement(1,1),
-                                    matrix.getElement(0,2), matrix.getElement(1,2));
-                        }
+     * @param  method    The operation method to compare to the math transform.
+     * @param  transform The math transform to compare to the operation method.
+     * @throws IllegalArgumentException if the number of dimensions are incompatible.
+     */
+    public static void checkDimensions(final OperationMethod method, MathTransform transform)
+            throws IllegalArgumentException
+    {
+        int actual = transform.getSourceDimensions();
+        Integer expected = method.getSourceDimensions();
+        if (expected != null && actual > expected) {
+            /*
+             * The given MathTransform use more dimensions than the OperationMethod.
+             * Try to locate one and only one sub-transform, ignoring axis swapping and scaling.
+             */
+            MathTransform subTransform = null;
+            for (final MathTransform step : MathTransforms.getSteps(transform)) {
+                if (!isIgnorable(step)) {
+                    if (subTransform == null && step instanceof PassThroughTransform)
{
+                        subTransform = ((PassThroughTransform) step).getSubTransform();
+                    } else {
+                        subTransform = null;
+                        break;
                     }
                 }
-            } else if (sourceDimension == 2) {
-                return new ProjectiveTransform2D(matrix);
             }
-        }
-        final LinearTransform candidate = CopyTransform.create(matrix);
-        if (candidate != null) {
-            return candidate;
-        }
-        return new ProjectiveTransform(matrix);
-    }
-
-    /**
-     * Concatenates the two given transforms. The returned transform will implement
-     * {@link MathTransform1D} or {@link MathTransform2D} if the dimensions of the
-     * concatenated transform are equal to 1 or 2 respectively.
-     *
-     * @param tr1 The first math transform.
-     * @param tr2 The second math transform.
-     * @return    The concatenated transform.
-     * @throws MismatchedDimensionException if the output dimension of the first transform
-     *         does not match the input dimension of the second transform.
-     *
-     * @see MathTransformFactory#createConcatenatedTransform(MathTransform, MathTransform)
-     */
-    public static MathTransform concatenate(final MathTransform tr1, final MathTransform
tr2)
-            throws MismatchedDimensionException
-    {
-        ensureNonNull("tr1", tr1);
-        ensureNonNull("tr2", tr2);
-        return ConcatenatedTransform.create(tr1, tr2);
-    }
-
-    /**
-     * Concatenates the given one-dimensional transforms. This is a convenience methods
-     * delegating to {@link #concatenate(MathTransform, MathTransform)} and casting the
-     * result to a {@link MathTransform1D} instance.
-     *
-     * @param tr1 The first math transform.
-     * @param tr2 The second math transform.
-     * @return    The concatenated transform.
-     * @throws MismatchedDimensionException if the output dimension of the first transform
-     *         does not match the input dimension of the second transform.
-     */
-    public static MathTransform1D concatenate(MathTransform1D tr1, MathTransform1D tr2)
-            throws MismatchedDimensionException
-    {
-        return (MathTransform1D) concatenate((MathTransform) tr1, (MathTransform) tr2);
-    }
-
-    /**
-     * Concatenates the given two-dimensional transforms. This is a convenience methods
-     * delegating to {@link #concatenate(MathTransform, MathTransform)} and casting the
-     * result to a {@link MathTransform2D} instance.
-     *
-     * @param tr1 The first math transform.
-     * @param tr2 The second math transform.
-     * @return    The concatenated transform.
-     * @throws MismatchedDimensionException if the output dimension of the first transform
-     *         does not match the input dimension of the second transform.
-     */
-    public static MathTransform2D concatenate(MathTransform2D tr1, MathTransform2D tr2)
-            throws MismatchedDimensionException
-    {
-        return (MathTransform2D) concatenate((MathTransform) tr1, (MathTransform) tr2);
-    }
-
-    /**
-     * Concatenates the three given transforms. This is a convenience methods doing its job
-     * as two consecutive concatenations.
-     *
-     * @param tr1 The first math transform.
-     * @param tr2 The second math transform.
-     * @param tr3 The third math transform.
-     * @return    The concatenated transform.
-     * @throws MismatchedDimensionException if the output dimension of a transform
-     *         does not match the input dimension of next transform.
-     */
-    public static MathTransform concatenate(MathTransform tr1, MathTransform tr2, MathTransform
tr3)
-            throws MismatchedDimensionException
-    {
-        ensureNonNull("tr1", tr1);
-        ensureNonNull("tr2", tr2);
-        ensureNonNull("tr3", tr3);
-        return concatenate(concatenate(tr1, tr2), tr3);
-    }
-
-    /**
-     * Concatenates the three given one-dimensional transforms. This is a convenience methods
-     * delegating to {@link #concatenate(MathTransform, MathTransform, MathTransform)} and
-     * casting the result to a {@link MathTransform1D} instance.
-     *
-     * @param tr1 The first math transform.
-     * @param tr2 The second math transform.
-     * @param tr3 The third math transform.
-     * @return    The concatenated transform.
-     * @throws MismatchedDimensionException if the output dimension of a transform
-     *         does not match the input dimension of next transform.
-     */
-    public static MathTransform1D concatenate(MathTransform1D tr1, MathTransform1D tr2, MathTransform1D
tr3)
-            throws MismatchedDimensionException
-    {
-        return (MathTransform1D) concatenate((MathTransform) tr1, (MathTransform) tr2, (MathTransform)
tr3);
-    }
-
-    /**
-     * Concatenates the three given two-dimensional transforms. This is a convenience methods
-     * delegating to {@link #concatenate(MathTransform, MathTransform, MathTransform)} and
-     * casting the result to a {@link MathTransform2D} instance.
-     *
-     * @param tr1 The first math transform.
-     * @param tr2 The second math transform.
-     * @param tr3 The third math transform.
-     * @return    The concatenated transform.
-     * @throws MismatchedDimensionException if the output dimension of a transform
-     *         does not match the input dimension of next transform.
-     */
-    public static MathTransform2D concatenate(MathTransform2D tr1, MathTransform2D tr2, MathTransform2D
tr3)
-            throws MismatchedDimensionException
-    {
-        return (MathTransform2D) concatenate((MathTransform) tr1, (MathTransform) tr2, (MathTransform)
tr3);
-    }
-
-    /**
-     * Returns all single components of the given (potentially concatenated) transform.
-     * This method makes the following choice:
-     *
-     * <ul>
-     *   <li>If {@code transform} is {@code null}, returns an empty list.</li>
-     *   <li>Otherwise if {@code transform} is the result of a call to a {@code concatenate(…)}
method,
-     *       returns all components. All nested concatenated transforms (if any) will be
expanded.</li>
-     *   <li>Otherwise returns the given transform in a list of size 1.</li>
-     * </ul>
-     *
-     * @param  transform The transform for which to get the components, or {@code null}.
-     * @return All single math transforms performed by this concatenated transform.
-     */
-    public static List<MathTransform> getSteps(final MathTransform transform) {
-        if (transform != null) {
-            if (transform instanceof ConcatenatedTransform) {
-                return ((ConcatenatedTransform) transform).getSteps();
-            } else {
-                return Collections.singletonList(transform);
+            if (subTransform != null) {
+                transform = subTransform;
+                actual = transform.getSourceDimensions();
             }
-        } else {
-            return Collections.emptyList();
         }
-    }
-
-    /**
-     * Returns what seems to be the "core" of the given math transform. This method should
be used only
-     * for information purpose, since the definition of "core" is imprecise and may be adjusted
in future
-     * SIS versions. The current algorithm is as below:
-     *
-     * <ul>
-     *   <li>If the given transform can be decomposed in {@linkplain #getSteps(MathTransform)
steps}, then the steps for
-     *       {@linkplain org.apache.sis.referencing.cs.CoordinateSystems#swapAndScaleAxes
axis swapping and scaling} are
-     *       ignored.</li>
-     *   <li>If the given transform or one of its steps is a {@link PassThroughTransform},
then its sub-transform
-     *       it taken.</li>
-     * </ul>
-     *
-     * @param  transform The math transform from which to get the "core" transform, or {@code
null}.
-     * @return The "core" (may be the whole math transform), or {@code null} if the given
argument was null.
-     */
-    public static MathTransform getCore(final MathTransform transform) {
-        MathTransform step = transform;
-        while (!isIgnorable(step)) {
-            if (step instanceof ConcatenatedTransform) {
-                // Ignore axis switch and scaling (usually unit conversions).
-                final ConcatenatedTransform c = (ConcatenatedTransform) step;
-                if (isIgnorable(c.transform1)) {
-                    step = c.transform2;
-                } else if (isIgnorable(c.transform2)) {
-                    step = c.transform1;
-                } else {
-                    return c; // Both components are non-ignorable: return the ConcatenatedTransform
as a whole.
-                }
-            } else if (step instanceof PassThroughTransform) {
-                step = ((PassThroughTransform) step).subTransform;
-            } else {
-                return step;
+        /*
+         * Now verify if the MathTransform dimensions are equal to the OperationMethod ones,
+         * ignoring null java.lang.Integer instances.
+         */
+        final String name;
+        if (expected == null || actual == expected) {
+            actual = transform.getTargetDimensions();
+            expected = method.getTargetDimensions();
+            if (expected == null || actual == expected) {
+                return;
             }
+            name = "transform.target";
+        } else {
+            name = "transform.source";
         }
-        return transform; // The full MathTransform is ignorable. Do not try to decompose
it.
+        throw new IllegalArgumentException(Errors.format(Errors.Keys.MismatchedDimension_3,
name, expected, actual));
     }
 
     /**
      * Returns {@code true} if the specified transform is likely to exists only for axis
swapping
      * and/or unit conversions. The heuristic rule checks if the transform is backed by a
square
-     * matrix with exactly one non-null value in each row and each column. This method is
used for
-     * implementation of the {@link #getCore(MathTransform)} method only.
+     * matrix with exactly one non-null value in each row and each column.
      */
     private static boolean isIgnorable(final MathTransform transform) {
-        final Matrix matrix = getMatrix(transform);
+        final Matrix matrix = MathTransforms.getMatrix(transform);
         if (matrix != null) {
             final int size = matrix.getNumRow();
             if (matrix.getNumCol() == size) {
@@ -346,67 +135,4 @@ public final class MathTransforms extend
         }
         return false;
     }
-
-    /**
-     * If the given transform is linear, returns its coefficients as a matrix.
-     * More specifically:
-     *
-     * <ul>
-     *   <li>If the given transform is an instance of {@link LinearTransform},
-     *       returns {@link LinearTransform#getMatrix()}.</li>
-     *   <li>Otherwise if the given transform is an instance of {@link AffineTransform},
-     *       returns its coefficients in a {@link org.apache.sis.referencing.operation.matrix.Matrix3}
instance.</li>
-     *   <li>Otherwise returns {@code null}.</li>
-     * </ul>
-     *
-     * @param  transform The transform for which to get the matrix, or {@code null}.
-     * @return The matrix of the given transform, or {@code null} if none.
-     */
-    public static Matrix getMatrix(final MathTransform transform) {
-        if (transform instanceof LinearTransform) {
-            return ((LinearTransform) transform).getMatrix();
-        }
-        if (transform instanceof AffineTransform) {
-            return AffineTransforms2D.toMatrix((AffineTransform) transform);
-        }
-        return null;
-    }
-
-    /**
-     * A buckle method for calculating derivative and coordinate transformation in a single
step.
-     * The transform result is stored in the given destination array, and the derivative
matrix
-     * is returned. Invoking this method is equivalent to the following code, except that
it may
-     * execute faster with some {@code MathTransform} implementations:
-     *
-     * {@preformat java
-     *     DirectPosition ptSrc = ...;
-     *     DirectPosition ptDst = ...;
-     *     Matrix matrixDst = derivative(ptSrc);
-     *     ptDst = transform(ptSrc, ptDst);
-     * }
-     *
-     * @param transform The transform to use.
-     * @param srcPts The array containing the source coordinate.
-     * @param srcOff The offset to the point to be transformed in the source array.
-     * @param dstPts the array into which the transformed coordinate is returned.
-     * @param dstOff The offset to the location of the transformed point that is stored in
the destination array.
-     * @return The matrix of the transform derivative at the given source position.
-     * @throws TransformException If the point can't be transformed or if a problem occurred
-     *         while calculating the derivative.
-     */
-    public static Matrix derivativeAndTransform(final MathTransform transform,
-                                                final double[] srcPts, final int srcOff,
-                                                final double[] dstPts, final int dstOff)
-            throws TransformException
-    {
-        if (transform instanceof AbstractMathTransform) {
-            return ((AbstractMathTransform) transform).transform(srcPts, srcOff, dstPts,
dstOff, true);
-        }
-        // Must be calculated before to transform the coordinate.
-        final Matrix derivative = transform.derivative(new DirectPositionView(srcPts, srcOff,
transform.getSourceDimensions()));
-        if (dstPts != null) {
-            transform.transform(srcPts, srcOff, dstPts, dstOff, 1);
-        }
-        return derivative;
-    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java?rev=1653351&r1=1653350&r2=1653351&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] Tue Jan 20 19:54:45 2015
@@ -283,71 +283,6 @@ public final class MathTransforms extend
     }
 
     /**
-     * Returns what seems to be the "core" of the given math transform. This method should
be used only
-     * for information purpose, since the definition of "core" is imprecise and may be adjusted
in future
-     * SIS versions. The current algorithm is as below:
-     *
-     * <ul>
-     *   <li>If the given transform can be decomposed in {@linkplain #getSteps(MathTransform)
steps}, then the steps for
-     *       {@linkplain org.apache.sis.referencing.cs.CoordinateSystems#swapAndScaleAxes
axis swapping and scaling} are
-     *       ignored.</li>
-     *   <li>If the given transform or one of its steps is a {@link PassThroughTransform},
then its sub-transform
-     *       it taken.</li>
-     * </ul>
-     *
-     * @param  transform The math transform from which to get the "core" transform, or {@code
null}.
-     * @return The "core" (may be the whole math transform), or {@code null} if the given
argument was null.
-     */
-    public static MathTransform getCore(final MathTransform transform) {
-        MathTransform step = transform;
-        while (!isIgnorable(step)) {
-            if (step instanceof ConcatenatedTransform) {
-                // Ignore axis switch and scaling (usually unit conversions).
-                final ConcatenatedTransform c = (ConcatenatedTransform) step;
-                if (isIgnorable(c.transform1)) {
-                    step = c.transform2;
-                } else if (isIgnorable(c.transform2)) {
-                    step = c.transform1;
-                } else {
-                    return c; // Both components are non-ignorable: return the ConcatenatedTransform
as a whole.
-                }
-            } else if (step instanceof PassThroughTransform) {
-                step = ((PassThroughTransform) step).subTransform;
-            } else {
-                return step;
-            }
-        }
-        return transform; // The full MathTransform is ignorable. Do not try to decompose
it.
-    }
-
-    /**
-     * Returns {@code true} if the specified transform is likely to exists only for axis
swapping
-     * and/or unit conversions. The heuristic rule checks if the transform is backed by a
square
-     * matrix with exactly one non-null value in each row and each column. This method is
used for
-     * implementation of the {@link #getCore(MathTransform)} method only.
-     */
-    private static boolean isIgnorable(final MathTransform transform) {
-        final Matrix matrix = getMatrix(transform);
-        if (matrix != null) {
-            final int size = matrix.getNumRow();
-            if (matrix.getNumCol() == size) {
-                for (int j=0; j<size; j++) {
-                    int n1=0, n2=0;
-                    for (int i=0; i<size; i++) {
-                        if (matrix.getElement(j,i) != 0) n1++;
-                        if (matrix.getElement(i,j) != 0) n2++;
-                    }
-                    if (n1 != 1 || n2 != 1) {
-                        return false;
-                    }
-                }
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
      * If the given transform is linear, returns its coefficients as a matrix.
      * More specifically:
      *

Copied: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
(from r1653288, sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java?p2=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java&p1=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java&r1=1653288&r2=1653351&rev=1653351&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/OperationMethodsTest.java
[UTF-8] Tue Jan 20 19:54:45 2015
@@ -14,12 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.referencing.operation.transform;
+package org.apache.sis.internal.referencing;
 
-import java.util.List;
+import java.util.Collections;
+import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.referencing.operation.MathTransform;
-import org.apache.sis.referencing.operation.matrix.Matrix4;
-import org.apache.sis.test.DependsOnMethod;
+import org.opengis.referencing.operation.OperationMethod;
+import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
+import org.apache.sis.referencing.operation.DefaultOperationMethod;
+import org.apache.sis.referencing.operation.transform.MathTransformsTest;
+import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -27,63 +31,43 @@ import static org.opengis.test.Assert.*;
 
 
 /**
- * Tests {@link MathTransforms}.
+ * Tests {@link OperationMethods}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
  * @version 0.5
  * @module
  */
-public final strictfp class MathTransformsTest extends TestCase {
+@DependsOn({
+    MathTransformsTest.class,
+    org.apache.sis.referencing.operation.DefaultOperationMethodTest.class
+})
+public final strictfp class OperationMethodsTest extends TestCase {
     /**
-     * For floating point comparisons.
+     * Creates a dummy operation method of the given dimensions.
      */
-    private static final double STRICT = 0;
-
-    /**
-     * Creates a dummy transform for testing purpose.
-     * The {@code scale} and {@code scap} arguments are initially identity matrices,
-     * and will be written by this method with dummy coefficient values for testing purpose.
-     *
-     * <p><b>Implementation note:</b> we do not use {@code MathTransforms.concatenate(…)}
for
-     * preventing the optimization performed for the {@link PassThroughTransform} special
case.</p>
-     *
-     * @param scale The matrix applying a scale along at least one axis.
-     * @param swap  The matrix swapping two matrices.
-     */
-    private static MathTransform createConcatenateAndPassThrough(final Matrix4 scale, final
Matrix4 swap) {
-        scale.m11 = 3;
-        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 = new ConcatenatedTransformDirect(MathTransforms.linear(scale), tr); // See "implementation
note" above.
-        tr = new ConcatenatedTransformDirect(tr, MathTransforms.linear(swap));
-        return tr;
-    }
-
-    /**
-     * Tests {@link MathTransforms#getSteps(MathTransform)}.
-     */
-    @Test
-    public void testGetSteps() {
-        final Matrix4 scale = new Matrix4(); // Scales a value.
-        final Matrix4 swap  = new Matrix4(); // Swaps two dimensions.
-        final List<MathTransform> steps = MathTransforms.getSteps(createConcatenateAndPassThrough(scale,
swap));
-        assertEquals(3, steps.size());
-        assertMatrixEquals("Step 1", scale, MathTransforms.getMatrix(steps.get(0)), STRICT);
-        assertMatrixEquals("Step 3", swap,  MathTransforms.getMatrix(steps.get(2)), STRICT);
-        assertInstanceOf  ("Step 2", PassThroughTransform.class, steps.get(1));
+    private static OperationMethod createOperationMethod(final int sourceDimension, final
int targetDimension) {
+        final ParameterDescriptorGroup parameters = new DefaultParameterDescriptorGroup(
+                Collections.singletonMap(ParameterDescriptorGroup.NAME_KEY, "Dummy"), 1,
1);
+        return new DefaultOperationMethod(Collections.singletonMap(OperationMethod.NAME_KEY,
parameters.getName()),
+                sourceDimension, targetDimension, parameters);
     }
 
     /**
-     * Tests {@link MathTransforms#getCore(MathTransform)}.
+     * Tests {@link OperationMethods#checkDimensions(OperationMethod, MathTransform)}.
      */
     @Test
-    @DependsOnMethod("testGetSteps")
-    public void testGetCore() {
-        MathTransform tr = createConcatenateAndPassThrough(new Matrix4(), new Matrix4());
-        tr = MathTransforms.getCore(tr);
-        assertInstanceOf("The only non-ignorable part should be the exponential one.", ExponentialTransform1D.class,
tr);
+    public void testCheckDimensions() {
+        final MathTransform tr = MathTransformsTest.createConcatenateAndPassThrough();
+        OperationMethods.checkDimensions(createOperationMethod(3, 3), tr);
+        OperationMethods.checkDimensions(createOperationMethod(1, 1), tr);
+        try {
+            OperationMethods.checkDimensions(createOperationMethod(2, 2), tr);
+            fail("OperationMethod of dimension 2 shall be considered incompatible.");
+        } catch (IllegalArgumentException e) {
+            // This is the expected exception.
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("transform.source"));
+        }
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java?rev=1653351&r1=1653350&r2=1653351&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
[UTF-8] Tue Jan 20 19:54:45 2015
@@ -19,7 +19,6 @@ package org.apache.sis.referencing.opera
 import java.util.List;
 import org.opengis.referencing.operation.MathTransform;
 import org.apache.sis.referencing.operation.matrix.Matrix4;
-import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -42,6 +41,23 @@ public final strictfp class MathTransfor
 
     /**
      * Creates a dummy transform for testing purpose.
+     * The transform has the folowing properties:
+     *
+     * <ul>
+     *   <li>The source and target dimensions are 3.</li>
+     *   <li>The transform contains 3 step.</li>
+     *   <li>The second step is a {@link PassThroughTransform}.</li>
+     *   <li>The transform in the middle (at dimension 1) is non-linear.</li>
+     * </ul>
+     *
+     * @return The dummy math transform.
+     */
+    public static MathTransform createConcatenateAndPassThrough() {
+        return createConcatenateAndPassThrough(new Matrix4(), new Matrix4());
+    }
+
+    /**
+     * Creates a dummy transform for testing purpose.
      * The {@code scale} and {@code scap} arguments are initially identity matrices,
      * and will be written by this method with dummy coefficient values for testing purpose.
      *
@@ -75,15 +91,4 @@ public final strictfp class MathTransfor
         assertMatrixEquals("Step 3", swap,  MathTransforms.getMatrix(steps.get(2)), STRICT);
         assertInstanceOf  ("Step 2", PassThroughTransform.class, steps.get(1));
     }
-
-    /**
-     * Tests {@link MathTransforms#getCore(MathTransform)}.
-     */
-    @Test
-    @DependsOnMethod("testGetSteps")
-    public void testGetCore() {
-        MathTransform tr = createConcatenateAndPassThrough(new Matrix4(), new Matrix4());
-        tr = MathTransforms.getCore(tr);
-        assertInstanceOf("The only non-ignorable part should be the exponential one.", ExponentialTransform1D.class,
tr);
-    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1653351&r1=1653350&r2=1653351&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Tue Jan 20 19:54:45 2015
@@ -77,6 +77,10 @@ import org.junit.BeforeClass;
     org.apache.sis.parameter.TensorParametersTest.class,
     org.apache.sis.parameter.TensorValuesTest.class,
 
+    org.apache.sis.referencing.operation.DefaultFormulaTest.class,
+    org.apache.sis.referencing.operation.DefaultOperationMethodTest.class,
+    org.apache.sis.internal.referencing.OperationMethodsTest.class,
+
     org.apache.sis.referencing.datum.BursaWolfParametersTest.class,
     org.apache.sis.referencing.datum.TimeDependentBWPTest.class,
     org.apache.sis.referencing.datum.DefaultEllipsoidTest.class,
@@ -107,9 +111,6 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.CommonCRSTest.class,
     org.apache.sis.referencing.CRSTest.class,
 
-    org.apache.sis.referencing.operation.DefaultFormulaTest.class,
-    org.apache.sis.referencing.operation.DefaultOperationMethodTest.class,
-
     org.apache.sis.geometry.AbstractDirectPositionTest.class,
     org.apache.sis.geometry.GeneralDirectPositionTest.class,
     org.apache.sis.geometry.DirectPosition1DTest.class,



Mime
View raw message