sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1604210 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/test/suite/
Date Fri, 20 Jun 2014 16:52:51 GMT
Author: desruisseaux
Date: Fri Jun 20 16:52:51 2014
New Revision: 1604210

URL: http://svn.apache.org/r1604210
Log:
Consolidation of Exponential / Logarithmic Transform1D.

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomainTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConstantTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConstantTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConstantTransform1D.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConstantTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConstantTransform1D.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -37,6 +37,16 @@ final class ConstantTransform1D extends 
     private static final long serialVersionUID = -1583675681650985947L;
 
     /**
+     * A transform for the positive zero constant.
+     */
+    static final ConstantTransform1D ZERO = new ConstantTransform1D(0);
+
+    /**
+     * A transform for the one constant.
+     */
+    static final ConstantTransform1D ONE = new ConstantTransform1D(1);
+
+    /**
      * Constructs a new constant transform.
      *
      * @param offset The {@code offset} term in the linear equation.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -27,20 +27,18 @@ import org.apache.sis.util.ComparisonMod
  * A one dimensional exponential transform.
  * Input values <var>x</var> are converted into output values <var>y</var>
using the following equation:
  *
- * <blockquote><var>y</var>  =  {@linkplain #scale} ⋅ {@linkplain #base}<sup><var>x</var></sup></blockquote>
+ * <blockquote><var>y</var> = {@linkplain #scale}⋅{@linkplain #base}<sup><var>x</var></sup></blockquote>
  *
- * <div class="note"><b>Tip:</b> if a linear transform is applied before
this exponential transform,
- * then the equation can be rewritten as:
- *
- * <blockquote><code>scale</code> ⋅ <code>base</code><sup><var>a</var>
+ <var>b</var>⋅<var>x</var></sup>
- *  =  <code>scale</code> ⋅ <code>base</code><sup><var>a</var></sup>
⋅
- * (<code>base</code><sup><var>b</var></sup>)<sup><var>x</var></sup></blockquote>
+ * <div class="note"><b>Tip:</b>
+ * if a linear transform is applied before this exponential transform, then the equation
can be rewritten as:
+ * <var>scale</var>⋅<var>base</var><sup><var>a</var>
+ <var>b</var>⋅<var>x</var></sup> =
+ * <var>scale</var>⋅<var>base</var><sup><var>a</var></sup>⋅(<var>base</var><sup><var>b</var></sup>)<sup><var>x</var></sup>
  *
  * It is possible to find back the coefficients of the original linear transform by
  * pre-concatenating a logarithmic transform before the exponential one, as below:
  *
  * {@preformat java
- *   LinearTransform1D linear = (LinearTransform1D) ConcatenatedTransform.create(exponentialTransform,
+ *   LinearTransform1D linear = MathTransforms.create(exponentialTransform,
  *           LogarithmicTransform1D.create(base, -Math.log(scale) / Math.log(base)));
  * }
  * </div>
@@ -67,7 +65,7 @@ final class ExponentialTransform1D exten
     protected final double base;
 
     /**
-     * Natural logarithm of {@link #base}.
+     * Natural logarithm of {@link #base}, used for {@link #derivative(double)} computation.
      */
     final double lnBase;
 
@@ -75,7 +73,7 @@ final class ExponentialTransform1D exten
      * The scale value to be multiplied.
      *
      * <div class="note">The scale could be handled by a concatenation with {@link
LinearTransform1D} instead than
-     * an explicit field in this class. However the <var>scale</var> ⋅ <var>base</var><sup><var>x</var></sup>
formula
+     * an explicit field in this class. However the <var>scale</var>⋅<var>base</var><sup><var>x</var></sup>
formula
      * is extensively used as a <cite>transfer function</cite> in grid coverages.
Consequently we keep this explicit
      * field for performance reasons.</div>
      */
@@ -88,14 +86,13 @@ final class ExponentialTransform1D exten
     private MathTransform1D inverse;
 
     /**
-     * Constructs a new exponential transform which is the
-     * inverse of the supplied logarithmic transform.
+     * Constructs a new exponential transform which is the inverse of the supplied logarithmic
transform.
      */
     ExponentialTransform1D(final LogarithmicTransform1D inverse) {
-        this.base     = inverse.base;
-        this.lnBase   = inverse.lnBase;
-        this.scale    = Math.pow(base, -inverse.offset);
-        this.inverse  = inverse;
+        this.base    = inverse.base;
+        this.lnBase  = inverse.lnBase;
+        this.scale   = Math.pow(base, -inverse.offset);
+        this.inverse = inverse;
     }
 
     /**
@@ -113,8 +110,7 @@ final class ExponentialTransform1D exten
     }
 
     /**
-     * Constructs a new exponential transform which include the given scale factor applied
-     * after the exponentiation.
+     * Constructs a new exponential transform which include the given scale factor applied
after the exponentiation.
      *
      * @param  base   The base to be raised to a power.
      * @param  scale  The scale value to be multiplied.
@@ -122,7 +118,7 @@ final class ExponentialTransform1D exten
      */
     public static MathTransform1D create(final double base, final double scale) {
         if (base == 0 || scale == 0) {
-            return LinearTransform1D.create(0, 0);
+            return ConstantTransform1D.ZERO;
         }
         if (base == 1) {
             return LinearTransform1D.create(scale, 0);
@@ -131,7 +127,7 @@ final class ExponentialTransform1D exten
     }
 
     /**
-     * Creates the inverse transform of this object.
+     * Returns the inverse of this transform.
      */
     @Override
     public synchronized MathTransform1D inverse() {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -103,6 +103,8 @@ class LinearTransform1D extends Abstract
             return IdentityTransform1D.INSTANCE;
         }
         if (scale == 0) {
+            if (offset == 0) return ConstantTransform1D.ZERO;
+            if (offset == 1) return ConstantTransform1D.ONE;
             return new ConstantTransform1D(offset);
         }
         return new LinearTransform1D(scale, offset);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -55,7 +55,7 @@ class LogarithmicTransform1D extends Abs
     protected final double base;
 
     /**
-     * Natural logarithm of {@link #base}.
+     * Natural logarithm of {@link #base}, used for {@link #derivative(double)} computation.
      */
     final double lnBase;
 
@@ -114,13 +114,12 @@ class LogarithmicTransform1D extends Abs
         if (base == 10) {
             return new Base10(offset);
         }
-        if (base == 0) {
-            // offset + ln(x) / ln(0)   =   offset + ln(x) / -∞   =   offset + -0  for
0 < x < ∞
-            return LinearTransform1D.create(-0.0, offset);
-        }
-        if (base == Double.POSITIVE_INFINITY) {
-            // offset + ln(x) / ln(∞)   =   offset + ln(x) / +∞   =   offset + 0   for
0 < x < ∞
-            return LinearTransform1D.create(+0.0, offset);
+        if (base == 0 || base == Double.POSITIVE_INFINITY) {
+            /*
+             * offset + ln(x) / ln(0)   =   offset + ln(x) / -∞   =   offset + -0   for
0 < x < ∞
+             * offset + ln(x) / ln(∞)   =   offset + ln(x) / +∞   =   offset +  0   for
0 < x < ∞
+             */
+            return LinearTransform1D.create(0, offset);
         }
         return new LogarithmicTransform1D(base, offset);
     }
@@ -136,7 +135,7 @@ class LogarithmicTransform1D extends Abs
     }
 
     /**
-     * Creates the inverse transform of this object.
+     * Returns the inverse of this transform.
      */
     @Override
     public synchronized MathTransform1D inverse() {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PowerTransform1D.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -78,7 +78,7 @@ final class PowerTransform1D extends Abs
      */
     public static MathTransform1D create(final double power) {
         if (power == 1) return IdentityTransform1D.INSTANCE;
-        if (power == 0) return new ConstantTransform1D(1);
+        if (power == 0) return ConstantTransform1D.ONE;
         return new PowerTransform1D(power);
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomain.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -143,7 +143,7 @@ public strictfp enum CoordinateDomain {
      * Geographic input coordinates with angles in radians and only half of the longitude
range.
      * Ordinates are in (<var>lambda</var>, <var>phi</var>, <var>height</var>)
order.
      */
-    GEOGRAPHIC_RADIANS_HALF {
+    GEOGRAPHIC_RADIANS_HALF_λ {
         @Override
         double generate(final Random random, final int dimension) {
             final double range;
@@ -248,7 +248,17 @@ public strictfp enum CoordinateDomain {
     },
 
     /**
-     * Gaussian numbers: can be positives or negatives, mostly close to zero but some
+     * Values in the -10 to 10 range.
+     */
+    RANGE_10 {
+        @Override
+        double generate(final Random random, final int dimension) {
+            return random.nextDouble() * 20 - 10;
+        }
+    },
+
+    /**
+     * Gaussian distribution. Numbers can be positives or negatives, mostly close to zero
but some
      * numbers can be arbitrarily large.
      */
     GAUSSIAN;

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomainTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomainTest.java?rev=1604210&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomainTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomainTest.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.operation.transform;
+
+import java.util.Random;
+
+// Test imports
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link CoordinateDomain}.
+ * The main intend of this class is to allow visual inspection (by looking in source code)
of sampled data.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public class CoordinateDomainTest extends TestCase {
+    /**
+     * The tolerance threshold used in this test suite.
+     */
+    private static final double TOLERANCE = 0.05;
+
+    /**
+     * Tests {@link CoordinateDomain#GEOCENTRIC}.
+     */
+    @Test
+    public void testGeocentric() {
+        assertArrayEquals(new double[] {
+            // ………………X   ………………………Y    ……………………Z
+            -1277391.5,  -6002208.9,   1732520.1,
+               74602.9,   -589190.3,   6337303.4,
+            -4761978.5,  -1597877.1,  -3914795.3,
+            -4580863.2,   4167915.7,  -1530203.8,
+            -5088029.0,   1419280.2,   3574467.8
+        }, CoordinateDomain.GEOCENTRIC.generateRandomInput(new Random(6711701980687388701L),
3, 5), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC}.
+     * Latitude values shall be in the [-90 … +90]° range.
+     */
+    @Test
+    public void testGeographic() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+              83.5,   82.2,  -7586.1,
+             -87.6,  -88.4,    231.1,
+            -123.5,   18.3,   5601.5,
+              87.7,  -14.1,   8710.9,
+              52.4,  -68.4,  -4706.3
+        }, CoordinateDomain.GEOGRAPHIC.generateRandomInput(new Random(9157324015136982593L),
3, 5), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC_SAFE}.
+     * Latitude values shall be in the [-70 … +70]° range.
+     */
+    @Test
+    public void testGeographicSafe() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+             -18.4,  -35.6,  -3804.6,
+             152.4,    3.5,   3166.6,
+             -28.7,   14.7,   2820.3,
+             -38.9,  -36.0,  -1568.6,
+             161.0,   46.2,   2492.8
+        }, CoordinateDomain.GEOGRAPHIC_SAFE.generateRandomInput(new Random(8378805665450590968L),
3, 5), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC_POLES}.
+     * Latitude values shall be in the [-90 … -70]° or [70 … 90]° range.
+     */
+    @Test
+    public void testGeographicPole() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+            -136.4,   87.3,  -1490.4,
+             -97.8,   71.1,  -4503.6,
+             -45.3,   75.7,  -3179.1,
+             -45.1,  -79.6,  -3440.5,
+              11.1,  -83.6,   2017.0
+        }, CoordinateDomain.GEOGRAPHIC_POLES.generateRandomInput(new Random(6784869539382621962L),
3, 5), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC_RADIANS}.
+     */
+    @Test
+    public void testGeographicRadians() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+            -144.2,   66.4,  -3970.0,
+              -3.1,   -8.0,   6627.9,
+             -20.4,   37.0,  -9071.7,
+             151.2,  -43.0,  -8346.5,
+            -121.7,   33.8,  -5843.4
+        }, toDegrees(CoordinateDomain.GEOGRAPHIC_RADIANS.generateRandomInput(new Random(8149671419063258264L),
3, 5)), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC_RADIANS_HALF_λ}.
+     * Longitude values shall be in the [-90 … +90]° range.
+     */
+    @Test
+    public void testGeographicRadiansHalfλ() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+             -38.4,  -42.3,  -6357.0,
+              36.7,   18.2,  -2924.6,
+             -41.9,    2.4,  -9840.4,
+              69.7,   31.2,   1866.3,
+              15.4,  -89.1,   3977.3
+        }, toDegrees(CoordinateDomain.GEOGRAPHIC_RADIANS_HALF_λ.generateRandomInput(new
Random(544370108347649978L), 3, 5)), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC_RADIANS_NORTH}.
+     */
+    @Test
+    public void testGeographicRadiansNorth() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+              70.2,    0.3,  -2152.7,
+            -142.0,   21.1,  -6983.9,
+             -30.1,   20.5,   6443.0,
+              48.8,   35.1,   4712.3,
+               7.4,   16.6,  -7030.0
+        }, toDegrees(CoordinateDomain.GEOGRAPHIC_RADIANS_NORTH.generateRandomInput(new Random(2332709146110987009L),
3, 5)), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC_RADIANS_SOUTH}.
+     */
+    @Test
+    public void testGeographicRadiansSouth() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+              11.8,  -29.7,  -3783.7,
+            -140.4,  -62.1,  -8471.8,
+              64.2,   -2.5,  -1100.3,
+             -41.0,  -86.7,   4986.0,
+            -174.4,  -84.5,   5615.6
+        }, toDegrees(CoordinateDomain.GEOGRAPHIC_RADIANS_SOUTH.generateRandomInput(new Random(3024333515949168349L),
3, 5)), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC_RADIANS_EAST}.
+     */
+    @Test
+    public void testGeographicRadiansEast() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+              53.0,    22.9, -1166.6,
+              86.1,    12.1,  -255.3,
+             142.9,     8.1, -3782.4,
+             138.1,     3.4,  1172.8,
+             146.4,   -33.8, -4487.7
+        }, toDegrees(CoordinateDomain.GEOGRAPHIC_RADIANS_EAST.generateRandomInput(new Random(3351157046773088704L),
3, 5)), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GEOGRAPHIC_RADIANS_WEST}.
+     */
+    @Test
+    public void testGeographicRadiansWest() {
+        assertArrayEquals(new double[] {
+            // ……λ   …………φ   ………………H
+            -175.6,    74.1,  8059.1,
+            -173.9,    81.9, -6712.6,
+             -11.3,    74.8,  4056.4,
+             -81.4,    -1.4, -9255.1,
+            -133.4,   -50.5, -2251.5
+        }, toDegrees(CoordinateDomain.GEOGRAPHIC_RADIANS_WEST.generateRandomInput(new Random(7320025557405586859L),
3, 5)), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#PROJECTED}.
+     */
+    @Test
+    public void testProjected() {
+        assertArrayEquals(new double[] {
+            // ………………x   ……………………………y   ………………h
+            11376932.6,  -212881715.5,  -5712.7,
+             7918069.3,  -142014756.3,  -2917.9,
+            -1243860.7,  -209994389.7,   -893.4,
+            16373202.6,   414305247.8,  -6783.9,
+            -7715982.4,   -20958213.4,  -1625.9
+        }, toDegrees(CoordinateDomain.PROJECTED.generateRandomInput(new Random(4961499932406116863L),
3, 5)), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#RANGE_10}.
+     */
+    @Test
+    public void testRange10() {
+        assertArrayEquals(new double[] {
+            -7.3,
+             6.0,
+             7.8,
+            -2.3,
+            -9.5
+        }, CoordinateDomain.RANGE_10.generateRandomInput(new Random(2954568576395177702L),
1, 5), TOLERANCE);
+    }
+
+    /**
+     * Tests {@link CoordinateDomain#GAUSSIAN}.
+     */
+    @Test
+    public void testGaussian() {
+        assertArrayEquals(new double[] {
+            -0.916,
+             1.777,
+            -0.896,
+             0.093,
+             0.428
+        }, CoordinateDomain.GAUSSIAN.generateRandomInput(new Random(7679314270394487033L),
1, 5), 0.0005);
+    }
+
+    /**
+     * Converts longitude and latitude values from radians to degrees, for easier reading
of test methods.
+     */
+    private static double[] toDegrees(final double[] coordinates) {
+        for (int i=0; i<coordinates.length; i++) {
+            coordinates[i] = StrictMath.toDegrees(coordinates[i]); i++;
+            coordinates[i] = StrictMath.toDegrees(coordinates[i]); i++;
+            // Skip the third dimension (height).
+        }
+        return coordinates;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomainTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CoordinateDomainTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -32,7 +32,10 @@ import org.apache.sis.test.DependsOn;
  * @version 0.5
  * @module
  */
-@DependsOn(ProjectiveTransformTest.class)
+@DependsOn({
+    CoordinateDomainTest.class,
+    ProjectiveTransformTest.class
+})
 public final strictfp class CopyTransformTest extends MathTransformTestCase {
     /**
      * Generates random ordinates with approximatively 5% of NaN values in the array.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -16,13 +16,21 @@
  */
 package org.apache.sis.referencing.operation.transform;
 
+import java.util.EnumSet;
 import org.opengis.referencing.operation.MathTransform1D;
 import org.opengis.referencing.operation.TransformException;
-import org.apache.sis.test.DependsOn;
+import static java.lang.StrictMath.*;
+
+// Test imports
 import org.junit.Test;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.DependsOnMethod;
+import static org.opengis.test.Assert.*;
 
-import static org.junit.Assert.*;
-import static java.lang.StrictMath.*;
+// Branch-dependent imports
+import org.opengis.test.CalculationType;
+import org.opengis.test.ToleranceModifier;
+import org.opengis.test.ToleranceModifiers;
 
 
 /**
@@ -35,36 +43,65 @@ import static java.lang.StrictMath.*;
  * @version 0.5
  * @module
  */
-@DependsOn(LinearTransformTest.class)
+@DependsOn({
+    CoordinateDomainTest.class,
+    LinearTransformTest.class
+})
 public final strictfp class ExponentialTransform1DTest extends MathTransformTestCase {
     /**
-     * Arbitrary coefficients used for this test.
+     * Arbitrary parameters of the exponential transform to be tested.
+     */
+    private static final double BASE = 10, SCALE = 2;
+
+    /**
+     * Arbitrary coefficients of a linear transform to be concatenated to the exponential
transform.
+     */
+    private static final double C0 = -3, C1 = 0.25;
+
+    /**
+     * The random values to use as input, and the expected transformed values.
+     */
+    private double[] values, expected;
+
+    /**
+     * Generates random values for input coordinates, and allocates (but do not compute values)
+     * array for the expected transformed coordinates.
+     *
+     * @param mt The math transform which will be tested.
+     */
+    private void initialize(final MathTransform1D mt) {
+        transform         = mt; // Must be set before generateRandomCoordinates(…).
+        tolerance         = 1E-14;
+        toleranceModifier = ToleranceModifier.RELATIVE;
+        derivativeDeltas  = new double[] {0.001};
+        values            = generateRandomCoordinates(CoordinateDomain.RANGE_10, 0);
+        expected          = new double[values.length];
+    }
+
+    /**
+     * Tests the current transform using the {@link #values} as input points, and comparing
with
+     * the {@link #expected} values.
      */
-    private static final double BASE = 10, SCALE = 2, C0 = -3, C1 = 0.25;
+    private void run(final Class<? extends MathTransform1D> expectedType) throws TransformException
{
+        assertInstanceOf("Expected the use of mathematical identities.", expectedType, transform);
+        assertFalse(transform.isIdentity());
+        validate();
+        verifyTransform(values, expected);
+        verifyDerivative(2.5); // Test at a hard-coded point.
+    }
 
     /**
-     * A simple (non-concatenated) test case.
+     * A single (non-concatenated) test case.
      *
      * @throws TransformException should never happen.
      */
     @Test
-    public void testSimple() throws TransformException {
-        transform = ExponentialTransform1D.create(BASE, SCALE);
-        validate();
-        assertFalse(transform.isIdentity());
-        final double[] source = generateRandomCoordinates(CoordinateDomain.GAUSSIAN, 0);
-        final double[] target = new double[source.length];
-        for (int i=0; i<source.length; i++) {
-            target[i] = SCALE * pow(BASE, source[i]);
+    public void testSingle() throws TransformException {
+        initialize(ExponentialTransform1D.create(BASE, SCALE));
+        for (int i=0; i<values.length; i++) {
+            expected[i] = SCALE * pow(BASE, values[i]);
         }
-        tolerance = 1E-12;
-        verifyTransform(source, target);
-        /*
-         * Tests the derivative at a single point.
-         */
-        tolerance = 0.002;
-        derivativeDeltas = new double[] {0.001};
-        verifyDerivative(2.5);
+        run(ExponentialTransform1D.class);
     }
 
     /**
@@ -73,42 +110,28 @@ public final strictfp class ExponentialT
      * @throws TransformException should never happen.
      */
     @Test
+    @DependsOnMethod("testSingle")
     public void testAffinePreConcatenation() throws TransformException {
-        transform = MathTransforms.concatenate(
-                LinearTransform1D.create(C1, C0),
-                ExponentialTransform1D.create(BASE, SCALE));
-        validate();
-        assertFalse(transform.isIdentity());
-        assertTrue("Expected mathematical identities.", transform instanceof ExponentialTransform1D);
-        final double[] source = generateRandomCoordinates(CoordinateDomain.GAUSSIAN, 0);
-        final double[] target = new double[source.length];
-        for (int i=0; i<source.length; i++) {
-            target[i] = SCALE * pow(BASE, C0 + C1 * source[i]);
+        initialize(MathTransforms.concatenate(
+                   LinearTransform1D.create(C1, C0),
+                   ExponentialTransform1D.create(BASE, SCALE)));
+        for (int i=0; i<values.length; i++) {
+            expected[i] = SCALE * pow(BASE, C0 + C1 * values[i]);
         }
-        tolerance = 1E-14;
-        verifyTransform(source, target);
+        run(ExponentialTransform1D.class);
         /*
-         * Tests the derivative at a single point.
-         */
-        tolerance = 1E-9;
-        derivativeDeltas = new double[] {0.001};
-        verifyDerivative(2.5);
-        /*
-         * Find back the original linear coefficients as documented in the ExpentionalTransform1D
-         * class javadoc. Then check that the transform results are the expected ones.
+         * Find back the original linear coefficients as documented in the ExponentialTransform1D
class javadoc.
          */
         final double lnBase =  log(BASE);
         final double offset = -log(SCALE) / lnBase;
         final MathTransform1D log = LogarithmicTransform1D.create(BASE, offset);
+        for (int i=0; i<values.length; i++) {
+            expected[i] = log(expected[i]) / lnBase + offset;
+        }
         transform = (LinearTransform1D) MathTransforms.concatenate(transform, log);
-        assertTrue("Expected mathematical identities.", transform instanceof LinearTransform1D);
+        run(LinearTransform1D.class);
         assertEquals(C1, ((LinearTransform1D) transform).scale,  1E-12);
         assertEquals(C0, ((LinearTransform1D) transform).offset, 1E-12);
-        for (int i=0; i<source.length; i++) {
-            target[i] = log(target[i]) / lnBase + offset;
-        }
-        tolerance = 1E-14;
-        verifyTransform(source, target);
     }
 
     /**
@@ -117,25 +140,22 @@ public final strictfp class ExponentialT
      * @throws TransformException should never happen.
      */
     @Test
+    @DependsOnMethod("testSingle")
     public void testAffinePostConcatenation() throws TransformException {
-        transform = MathTransforms.concatenate(
-                ExponentialTransform1D.create(BASE, SCALE),
-                LinearTransform1D.create(C1, C0));
-        validate();
-        assertFalse(transform.isIdentity());
-        final double[] source = generateRandomCoordinates(CoordinateDomain.GAUSSIAN, 0);
-        final double[] target = new double[source.length];
-        for (int i=0; i<source.length; i++) {
-            target[i] = C0 + C1 * (SCALE * pow(BASE, source[i]));
+        initialize(MathTransforms.concatenate(
+                   ExponentialTransform1D.create(BASE, SCALE),
+                   LinearTransform1D.create(C1, C0)));
+        for (int i=0; i<values.length; i++) {
+            expected[i] = C0 + C1 * (SCALE * pow(BASE, values[i]));
         }
-        tolerance = 1E-12;
-        verifyTransform(source, target);
         /*
-         * Tests the derivative at a single point.
+         * The inverse transforms in this test case have high rounding errors.
+         * Those errors are low for values close to zero, and increase fast for higher values.
+         * We scale the default tolerance (1E-14) by 1E+8, which give us a tolerance of 1E-6.
          */
-        tolerance = 0.01;
-        derivativeDeltas = new double[] {0.001};
-        verifyDerivative(2.5);
+        toleranceModifier = ToleranceModifiers.concatenate(toleranceModifier,
+                ToleranceModifiers.scale(EnumSet.of(CalculationType.INVERSE_TRANSFORM), 1E+8));
+        run(ConcatenatedTransformDirect1D.class);
     }
 
     /**
@@ -144,28 +164,17 @@ public final strictfp class ExponentialT
      * @throws TransformException should never happen.
      */
     @Test
+    @DependsOnMethod("testSingle")
     public void testLogarithmicConcatenation() throws TransformException {
-        final double offset = -3;
-        final double base   = 8;
+        final double base   = 8; // Must be different than BASE.
         final double lnBase = log(base);
-        transform = MathTransforms.concatenate(
-                LogarithmicTransform1D.create(base, offset),
-                ExponentialTransform1D.create(BASE, SCALE));
-        validate();
-        assertFalse(transform.isIdentity());
-        final double[] source = generateRandomCoordinates(CoordinateDomain.GAUSSIAN, 0);
-        final double[] target = new double[source.length];
-        for (int i=0; i<source.length; i++) {
-            source[i] = abs(source[i]) + 0.001;
-            target[i] = SCALE * pow(BASE, log(source[i]) / lnBase + offset);
+        initialize(MathTransforms.concatenate(
+                   LogarithmicTransform1D.create(base, C0),
+                   ExponentialTransform1D.create(BASE, SCALE)));
+        for (int i=0; i<values.length; i++) {
+            values[i] = abs(values[i]) + 0.001;
+            expected[i] = SCALE * pow(BASE, log(values[i]) / lnBase + C0);
         }
-        tolerance = 1E-14;
-        verifyTransform(source, target);
-        /*
-         * Tests the derivative at a single point.
-         */
-        tolerance = 1E-10;
-        derivativeDeltas = new double[] {0.001};
-        verifyDerivative(2.5);
+        run(ConcatenatedTransformDirect1D.class);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -18,7 +18,6 @@ package org.apache.sis.referencing.opera
 
 import java.util.Random;
 import java.io.IOException;
-import java.io.PrintStream;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransform1D;
@@ -31,8 +30,6 @@ import org.opengis.metadata.Identifier;
 import org.apache.sis.parameter.Parameterized;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
-import org.apache.sis.math.Statistics;
-import org.apache.sis.math.StatisticsFormat;
 import org.apache.sis.io.TableAppender;
 import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.io.wkt.FormattableObject;
@@ -42,13 +39,11 @@ import static java.lang.StrictMath.*;
 // Test imports
 import org.opengis.test.Validators;
 import org.opengis.test.referencing.TransformTestCase;
-import org.apache.sis.test.TestCase;
 import org.apache.sis.test.TestUtilities;
 import static org.apache.sis.test.ReferencingAssert.*;
 
 // Branch-dependent imports
 import org.opengis.test.CalculationType;
-import org.opengis.test.ToleranceModifier;
 
 
 /**
@@ -108,14 +103,11 @@ public abstract strictfp class MathTrans
         /*
          * Use 'zTolerance' threshold instead of 'tolerance' when comparing vertical coordinate
values.
          */
-        toleranceModifier = new ToleranceModifier() {
-            @Override
-            public void adjust(final double[] tolerance, final DirectPosition coordinate,
final CalculationType mode) {
-                if (mode != CalculationType.IDENTITY) {
-                    final int i = forComparison(zDimension, mode);
-                    if (i >= 0 && i < tolerance.length) {
-                        tolerance[i] = zTolerance;
-                    }
+        toleranceModifier = (final double[] tolerance, final DirectPosition coordinate, final
CalculationType mode) -> {
+            if (mode != CalculationType.IDENTITY) {
+                final int i = forComparison(zDimension, mode);
+                if (i >= 0 && i < tolerance.length) {
+                    tolerance[i] = zTolerance;
                 }
             }
         };
@@ -319,27 +311,6 @@ public abstract strictfp class MathTrans
         for (int i = round(coordinates.length * propNaN); --i >= 0;) {
             coordinates[random.nextInt(coordinates.length)] = Double.NaN;
         }
-        if (TestCase.verbose) {
-            final PrintStream out = out();
-            out.print("Random input coordinates for ");
-            out.print(domain); out.println(" domain:");
-            final Statistics[] stats = new Statistics[dimension];
-            for (int i=0; i<stats.length; i++) {
-                stats[i] = new Statistics(null);
-            }
-            for (int i=0; i<coordinates.length; i++) {
-                stats[i % dimension].accept(coordinates[i]);
-            }
-            final StatisticsFormat format = StatisticsFormat.getInstance();
-            format.setBorderWidth(1);
-            try {
-                format.format(stats, out);
-            } catch (IOException e) {
-                throw new AssertionError(e);
-            }
-            out.println();
-            out.flush();
-        }
         return coordinates;
     }
 
@@ -364,7 +335,7 @@ public abstract strictfp class MathTrans
      */
     @Debug
     protected final void printInternalWKT() {
-        final TableAppender table = new TableAppender(out());
+        final TableAppender table = new TableAppender(System.out);
         table.setMultiLinesCells(true);
         table.appendHorizontalSeparator();
         table.append("WKT of “").append(getName()).append('”').nextColumn();
@@ -388,12 +359,4 @@ public abstract strictfp class MathTrans
             throw new AssertionError(e);
         }
     }
-
-    /**
-     * Where to write debugging information.
-     */
-    @Debug
-    private static PrintStream out() {
-        return System.out;
-    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java?rev=1604210&r1=1604209&r2=1604210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/PassThroughTransformTest.java
[UTF-8] Fri Jun 20 16:52:51 2014
@@ -45,6 +45,7 @@ import org.opengis.test.ToleranceModifie
  * @module
  */
 @DependsOn({
+    CoordinateDomainTest.class,
     LinearTransformTest.class,
     ExponentialTransform1DTest.class
 })

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=1604210&r1=1604209&r2=1604210&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] Fri Jun 20 16:52:51 2014
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.5
  * @module
  */
 @Suite.SuiteClasses({
@@ -40,6 +40,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.operation.matrix.NonSquareMatrixTest.class, // Expected to
be last MatrixTestCase - see javadoc.
     org.apache.sis.referencing.operation.matrix.MatricesTest.class,
     org.apache.sis.referencing.operation.matrix.AffineTransforms2DTest.class,
+    org.apache.sis.referencing.operation.transform.CoordinateDomainTest.class,
     org.apache.sis.referencing.operation.transform.IterationStrategyTest.class,
     org.apache.sis.referencing.operation.transform.AbstractMathTransformTest.class,
     org.apache.sis.referencing.operation.transform.ProjectiveTransformTest.class,



Mime
View raw message