This is an automated email from the ASF dual-hosted git repository.

amanin pushed a commit to branch fix/zero-based-transform
in repository https://gitbox.apache.org/repos/asf/sis.git

commit d972b4e44f86269611a3e44e37cace4b9ad780b7
Author: Alexis Manin <alexis.ma...@geomatys.com>
AuthorDate: Thu Jul 28 10:05:06 2022 +0200

    chore(Referencing): add a unit test to reproduce a corner-case problem in a 
sequence of coordinate transformation
---
 .../transform/ZeroBasedTransformTest.java          | 53 ++++++++++++++++++++++
 .../sis/test/suite/ReferencingTestSuite.java       |  1 +
 2 files changed, 54 insertions(+)

diff --git 
a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ZeroBasedTransformTest.java
 
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ZeroBasedTransformTest.java
new file mode 100644
index 0000000000..910fa9ebbe
--- /dev/null
+++ 
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ZeroBasedTransformTest.java
@@ -0,0 +1,53 @@
+package org.apache.sis.referencing.operation.transform;
+
+import org.apache.sis.geometry.Envelope2D;
+import org.apache.sis.geometry.Envelopes;
+import org.apache.sis.geometry.GeneralEnvelope;
+import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
+import org.apache.sis.referencing.CRS;
+import org.apache.sis.referencing.crs.HardCodedCRS;
+import org.apache.sis.test.TestCase;
+import org.junit.Assert;
+import org.junit.AssumptionViolatedException;
+import org.junit.Test;
+import org.opengis.geometry.Envelope;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.CoordinateOperation;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.TransformException;
+import org.opengis.util.FactoryException;
+
+public class ZeroBasedTransformTest extends TestCase {
+
+    /**
+     * Checks that no significant shift is produced by the combination of the 
following factors:
+     * <ol>
+     *     <li>A source envelope whose origin is zero</li>
+     *     <li>An intermediate geographic transform involving a 
wrap-around</li>
+     *     <li>A Pseudo-Mercator CRS destination</li>
+     * </ol>
+     *
+     * Requires an EPSG database (skipped otherwise)
+     */
+    @Test
+    public void theZeroTheWrapAroundAndThePseudoMercator() throws 
FactoryException, TransformException {
+        final CoordinateReferenceSystem sourceCrs = HardCodedCRS.IMAGE;
+        final CoordinateReferenceSystem intermediateCrs = HardCodedCRS.WGS84;
+        final CoordinateReferenceSystem targetCrs;
+        try {
+            targetCrs = CRS.forCode("EPSG:3857");
+        } catch (FactoryException e) {
+            throw new AssumptionViolatedException("This test requires an EPSG 
database", e);
+        }
+
+        final Envelope sourceEnvelope = new Envelope2D(sourceCrs, 0, 0, 1024, 
512);
+        final AffineTransform2D sourceToCrs84 = new 
AffineTransform2D(0.3515625, 0, 0, -0.3515625, -180.00001, 90);
+
+        CoordinateOperation op = CRS.findOperation(intermediateCrs, targetCrs, 
new DefaultGeographicBoundingBox(-180, 180, -90, 90));
+        final MathTransform sourceToTarget = 
MathTransforms.concatenate(sourceToCrs84, op.getMathTransform());
+
+        final GeneralEnvelope targetEnvelope = 
Envelopes.transform(sourceToTarget, sourceEnvelope);
+        Assert.assertEquals("min X", 
CRS.getDomainOfValidity(targetCrs).getMinimum(0), targetEnvelope.getMinimum(0), 
1E4);
+    }
+}
diff --git 
a/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
 
b/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
index 2e5bbe50ee..fe1e4f54a1 100644
--- 
a/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
+++ 
b/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
@@ -176,6 +176,7 @@ import org.junit.BeforeClass;
     
org.apache.sis.referencing.operation.transform.InterpolatedGeocentricTransformTest.class,
     
org.apache.sis.referencing.operation.transform.InterpolatedMolodenskyTransformTest.class,
     
org.apache.sis.referencing.operation.transform.DefaultMathTransformFactoryTest.class,
+    
org.apache.sis.referencing.operation.transform.ZeroBasedTransformTest.class,
 
     // Test map projections. Those tests need the providers tested above.
     org.apache.sis.referencing.operation.projection.InitializerTest.class,

Reply via email to