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 2019/02/13 18:49:11 UTC
[sis] 02/02: Fix an IllegalArgumentException (invalid index: -2)
which occurs in some situations when extracting the transform for a subset
of source dimensions.
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 ababaae863e280674550460c8242489c8b5a5c20
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Feb 13 18:59:07 2019 +0100
Fix an IllegalArgumentException (invalid index: -2) which occurs in some situations when extracting the transform for a subset of source dimensions.
---
.../operation/transform/TransformSeparator.java | 4 +-
.../transform/TransformSeparatorTest.java | 67 ++++++++++++++++++++++
2 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
index b2d07d8..7197f81 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
@@ -572,7 +572,9 @@ public class TransformSeparator {
* not accept arbitrary indices for modified coordinates.
*/
if (containsAll(dimensions, lower, subLower) && containsAll(dimensions, subUpper, upper)) {
- return factory.passThrough(subLower - lower, subTransform, Math.max(0, upper - subUpper));
+ final int offset = subDimensions[0];
+ assert containsAll(subDimensions, offset, offset + subDimensions.length) : offset;
+ return factory.passThrough(offset + subLower - lower, subTransform, Math.max(0, upper - subUpper));
}
}
/*
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 47d5c44..d9c38c7 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
@@ -346,6 +346,73 @@ public final strictfp class TransformSeparatorTest extends TestCase {
}
/**
+ * Tests separation of a concatenated transform containing a pass through transform.
+ *
+ * @throws FactoryException if an error occurred while creating a new transform.
+ * @throws TransformException if an error occurred while transforming coordinates for comparison purpose.
+ */
+ @Test
+ @DependsOnMethod({"testConcatenatedTransform", "testPassThroughTransform"})
+ public void testConcatenatedPassThroughTransform() throws FactoryException, TransformException {
+ final MathTransform linear = MathTransforms.scale(4, 1, 1, 1, 1, 6);
+ final MathTransform nonLinear = new PseudoTransform(3, 2);
+ final MathTransform passthrough = MathTransforms.passThrough(2, nonLinear, 1);
+ final MathTransform concatenated = new ConcatenatedTransform(linear, passthrough); // Bypass 'tryOptimized' method.
+ final TransformSeparator sep = new TransformSeparator(concatenated);
+ sep.addSourceDimensionRange(0, 2);
+ assertMatrixEquals("Leading passthrough dimensions", new Matrix3(4, 0, 0, 0, 1, 0, 0, 0, 1),
+ MathTransforms.getMatrix(sep.separate()), STRICT);
+ sep.clear();
+ sep.addSourceDimensionRange(5, 6);
+ assertMatrixEquals("Trailing passthrough dimensions", new Matrix2(6, 0, 0, 1),
+ MathTransforms.getMatrix(sep.separate()), STRICT);
+ sep.clear();
+ sep.addSourceDimensionRange(2, 5);
+ assertSame("subTransform", nonLinear, sep.separate());
+
+ sep.clear();
+ sep.addSourceDimensionRange(1, 5);
+ MathTransform mt = sep.separate();
+ assertInstanceOf("separate()", PassThroughTransform.class, mt);
+ final PassThroughTransform ps = ((PassThroughTransform) mt);
+ assertEquals("firstAffectedCoordinate", 1, ps.firstAffectedCoordinate);
+ assertEquals("numTrailingCoordinates", 0, ps.numTrailingCoordinates);
+ assertSame ("subTransform", nonLinear, ps.subTransform);
+ }
+
+ /**
+ * Tests separation of a pass through transform containing another pass through transform.
+ *
+ * @throws FactoryException if an error occurred while creating a new transform.
+ * @throws TransformException if an error occurred while transforming coordinates for comparison purpose.
+ */
+ @Test
+ @DependsOnMethod("testConcatenatedPassThroughTransform")
+ public void testNestedPassThroughTransform() throws FactoryException, TransformException {
+ final MathTransform nonLinear = new PseudoTransform(3, 2);
+ final MathTransform passthrough1 = MathTransforms.passThrough(2, nonLinear, 1);
+ final MathTransform concatenated = new ConcatenatedTransform(MathTransforms.scale(4, 3, 2, 1, 1, 6), passthrough1);
+ final MathTransform passthrough2 = new PassThroughTransform(2, concatenated, 3);
+ final TransformSeparator sep = new TransformSeparator(passthrough2);
+ sep.addSourceDimensionRange(3, 7);
+ MathTransform mt = sep.separate();
+ assertInstanceOf("separate()", ConcatenatedTransform.class, mt);
+ assertMatrixEquals("Leading passthrough dimensions", Matrices.create(5, 5, new double[] {
+ 3, 0, 0, 0, 0,
+ 0, 2, 0, 0, 0,
+ 0, 0, 1, 0, 0,
+ 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 1}), MathTransforms.getMatrix(((ConcatenatedTransform) mt).transform1), STRICT);
+
+ mt = ((ConcatenatedTransform) mt).transform2;
+ assertInstanceOf("subTransform", PassThroughTransform.class, mt);
+ final PassThroughTransform ps = ((PassThroughTransform) mt);
+ assertEquals("firstAffectedCoordinate", 1, ps.firstAffectedCoordinate);
+ assertEquals("numTrailingCoordinates", 0, ps.numTrailingCoordinates);
+ assertSame ("subTransform", nonLinear, ps.subTransform);
+ }
+
+ /**
* Tests {@link TransformSeparator#getTrimSourceDimensions()}.
*
* @throws FactoryException if an error occurred while creating a new transform.