sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1541235 - in /sis/branches/JDK7/core: sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-referencing/src/main/java/org/apache/sis/referencing/datum/ sis-referencing/src/test/java/org/apache/sis/internal/ sis-referencing...
Date Tue, 12 Nov 2013 21:08:43 GMT
Author: desruisseaux
Date: Tue Nov 12 21:08:42 2013
New Revision: 1541235

URL: http://svn.apache.org/r1541235
Log:
Initial version of time-dependent BursaWolfParameters.
The test case does not yet match the expected result according EPSG.

Added:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
  (with props)
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/FormulasTest.java
  (with props)
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java?rev=1541235&r1=1541234&r2=1541235&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
[UTF-8] Tue Nov 12 21:08:42 2013
@@ -56,6 +56,15 @@ public final class Formulas extends Stat
     public static final double ANGULAR_TOLERANCE = LINEAR_TOLERANCE / (NAUTICAL_MILE * 60);
 
     /**
+     * The length of a <cite>Julian year</cite> in milliseconds.
+     * From Wikipedia, "<cite>In astronomy, a Julian year (symbol: <b>a</b>)
is a unit of measurement of time
+     * defined as exactly 365.25 days of 86,400 SI seconds each.</cite>".
+     *
+     * @see <a href="http://en.wikipedia.org/wiki/Julian_year_%28astronomy%29">Wikipedia:
Julian year (astronomy)</a>
+     */
+    public static final long JULIAN_YEAR_LENGTH = 31557600000L;
+
+    /**
      * Do not allow instantiation of this class.
      */
     private Formulas() {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java?rev=1541235&r1=1541234&r2=1541235&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
[UTF-8] Tue Nov 12 21:08:42 2013
@@ -126,7 +126,7 @@ import java.util.Objects;
  * </math></p>
  * </tr></td></table>
  *
- * The numerical fields in this {@code BursaWolfParameters} class uses the EPSG abbreviations
+ * The numerical fields in this {@code BursaWolfParameters} class use the EPSG abbreviations
  * with 4 additional constraints compared to the EPSG definitions:
  *
  * <ul>
@@ -198,19 +198,19 @@ public class BursaWolfParameters extends
     public double tZ;
 
     /**
-     * X-axis rotation in arc seconds (EPSG:8608), sign following the <cite>Position
Vector</cite> convention.
+     * X-axis rotation in arc-seconds (EPSG:8608), sign following the <cite>Position
Vector</cite> convention.
      * The legacy OGC parameter name is {@code "ex"}.
      */
     public double rX;
 
     /**
-     * Y-axis rotation in arc seconds (EPSG:8609), sign following the <cite>Position
Vector</cite> convention.
+     * Y-axis rotation in arc-seconds (EPSG:8609), sign following the <cite>Position
Vector</cite> convention.
      * The legacy OGC parameter name is {@code "ey"}.
      */
     public double rY;
 
     /**
-     * Z-axis rotation in arc seconds (EPSG:8610), sign following the <cite>Position
Vector</cite> convention.
+     * Z-axis rotation in arc-seconds (EPSG:8610), sign following the <cite>Position
Vector</cite> convention.
      * The legacy OGC parameter name is {@code "ez"}.
      */
     public double rZ;
@@ -268,7 +268,7 @@ public class BursaWolfParameters extends
     /**
      * Verifies parameters validity after initialization.
      */
-    final void verify() {
+    void verify() {
         ensureFinite("tX", tX);
         ensureFinite("tY", tY);
         ensureFinite("tZ", tZ);
@@ -280,9 +280,7 @@ public class BursaWolfParameters extends
 
     /**
      * Returns the target datum for this set of parameters, or {@code null} if unspecified.
-     * This is usually the WGS 84 datum, but other targets are allowed. We recommend the
target datum
-     * to have a world-wide {@linkplain DefaultGeodeticDatum#getDomainOfValidity() domain
of validity},
-     * but this is not enforced.
+     * This is usually the WGS 84 datum, but other targets are allowed.
      *
      * <p>The source datum is the {@link DefaultGeodeticDatum} that contain this {@code
BursaWolfParameters}
      * instance.</p>
@@ -307,27 +305,56 @@ public class BursaWolfParameters extends
     }
 
     /**
-     * Returns {@code true} if this Bursa-Wolf parameters performs no operation.
-     * This is true when all parameters are set to zero.
+     * Returns {@code true} if a transformation built from this set of parameters would perform
no operation.
+     * This is true when the value of all parameters is zero.
      *
      * @return {@code true} if the parameters describe no operation.
      */
     public boolean isIdentity() {
-        return tX == 0 && tY == 0 && tZ == 0 &&
-               rX == 0 && rY == 0 && rZ == 0 &&
-               dS == 0;
+        return tX == 0 && tY == 0 && tZ == 0 && isTranslation();
     }
 
     /**
-     * Returns {@code true} if this Bursa-Wolf parameters contains only translation terms.
+     * Returns {@code true} if a transformation built from this set of parameters would perform
only a translation.
      *
-     * @return {@code true} if the parameters describe to a translation only.
+     * @return {@code true} if the parameters describe a translation only.
      */
     public boolean isTranslation() {
         return rX == 0 && rY == 0 && rZ == 0 && dS == 0;
     }
 
     /**
+     * Returns the elapsed time from the {@linkplain TimeDependentBWP#getTimeReference()
reference time}
+     * to the given date, in millennium. If this {@code BursaWolfParameters} is not time-dependent,
then
+     * returns {@code null}.
+     */
+    DoubleDouble period(final Date time) {
+        return null;
+    }
+
+    /**
+     * Returns the parameter at the given index. If this {@code BursaWolfParameters} is time-dependent,
+     * then the returned value shall be corrected for the given period.
+     *
+     * @param index  0 for {@code tX}, 1 for {@code tY}, <i>etc.</i> in {@code
TOWGS84[…]} order.
+     * @param period The value computed by {@link #period(Date)}, or {@code null}.
+     */
+    DoubleDouble param(final int index, final DoubleDouble period) {
+        final double p;
+        switch (index) {
+            case 0: p = tX; break;
+            case 1: p = tY; break;
+            case 2: p = tZ; break;
+            case 3: p = rX; break;
+            case 4: p = rY; break;
+            case 5: p = rZ; break;
+            case 6: p = dS; break;
+            default: throw new AssertionError(index);
+        }
+        return new DoubleDouble(p);
+    }
+
+    /**
      * Returns the position vector transformation (geocentric domain) as an affine transform.
      * For transformations that do not depend on time, the formula is as below where {@code
R}
      * is a conversion factor from arc-seconds to radians:
@@ -350,7 +377,8 @@ public class BursaWolfParameters extends
      * Some transformations use parameters that vary with time (e.g. operation method EPSG:1053).
      * Users can optionally specify a date for which the transformation is desired.
      * For transformations that do not depends on time, this date is ignored and can be null.
-     * For time-dependent transformations, {@code null} values default to the transformation's
reference time.
+     * For time-dependent transformations, {@code null} values default to the transformation's
+     * {@linkplain TimeDependentBWP#getTimeReference() reference time}.
      *
      * {@section Inverse transformation}
      * The inverse transformation can be approximated by reversing the sign of the 7 parameters
before to use them
@@ -366,7 +394,8 @@ public class BursaWolfParameters extends
      * @see DefaultGeodeticDatum#getPositionVectorTransformation(GeodeticDatum, Extent)
      */
     public Matrix getPositionVectorTransformation(final Date time) {
-        if (isTranslation()) {
+        final DoubleDouble period = period(time);
+        if (period == null && isTranslation()) {
             final Matrix4 matrix = new Matrix4();
             matrix.m03 = tX;
             matrix.m13 = tY;
@@ -378,21 +407,21 @@ public class BursaWolfParameters extends
          * translation terms. If we have rotation or scale terms, then use double-double
arithmetic.
          */
         final DoubleDouble RS = DoubleDouble.createSecondsToRadians();
-        final DoubleDouble S = new DoubleDouble(dS);
+        final DoubleDouble S = param(6, period);
         S.divide(PPM, 0);
         S.add(1, 0);        // S = 1 + dS / PPM;
         RS.multiply(S);     // RS = toRadians(1″) * S;
-        final DoubleDouble  X = new DoubleDouble(rX); X.multiply(RS);
-        final DoubleDouble  Y = new DoubleDouble(rY); Y.multiply(RS);
-        final DoubleDouble  Z = new DoubleDouble(rZ); Z.multiply(RS);
-        final DoubleDouble mX = new DoubleDouble( X); mX.negate();
-        final DoubleDouble mY = new DoubleDouble( Y); mY.negate();
-        final DoubleDouble mZ = new DoubleDouble( Z); mZ.negate();
+        final DoubleDouble  X = param(3, period); X.multiply(RS);
+        final DoubleDouble  Y = param(4, period); Y.multiply(RS);
+        final DoubleDouble  Z = param(5, period); Z.multiply(RS);
+        final DoubleDouble mX = new DoubleDouble(X); mX.negate();
+        final DoubleDouble mY = new DoubleDouble(Y); mY.negate();
+        final DoubleDouble mZ = new DoubleDouble(Z); mZ.negate();
         final Integer       O = 0; // Fetch Integer instance only once.
         return Matrices.create(4, 4, new Number[] {
-                 S,  mZ,   Y,  Double.valueOf(tX),
-                 Z,   S,  mX,  Double.valueOf(tY),
-                mY,   X,   S,  Double.valueOf(tZ),
+                 S,  mZ,   Y,  param(0, period),
+                 Z,   S,  mX,  param(1, period),
+                mY,   X,   S,  param(2, period),
                  O,   O,   O,  1});
     }
 
@@ -518,7 +547,7 @@ public class BursaWolfParameters extends
      */
     @Override
     public boolean equals(final Object object) {
-        if (object instanceof BursaWolfParameters) {
+        if (object != null && object.getClass() == getClass()) {
             final BursaWolfParameters that = (BursaWolfParameters) object;
             return Numerics.equals(this.tX, that.tX) &&
                    Numerics.equals(this.tY, that.tY) &&

Added: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java?rev=1541235&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
[UTF-8] Tue Nov 12 21:08:42 2013
@@ -0,0 +1,247 @@
+/*
+ * 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.datum;
+
+import java.util.Date;
+import java.util.Arrays;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.apache.sis.internal.util.Numerics;
+import org.apache.sis.internal.util.DoubleDouble;
+
+import static org.apache.sis.util.ArgumentChecks.*;
+import static org.apache.sis.internal.referencing.Formulas.JULIAN_YEAR_LENGTH;
+
+
+/**
+ * Parameters for a time-dependent geographic transformation between two datum.
+ * The {@link #tX tX}, {@link #tY tY}, {@link #tZ tZ}, {@link #rX rX}, {@link #rY rY}, {@link
#rZ rZ}
+ * and {@link #dS dS} parameters inherited from the parent class are values at a point in
time given
+ * by {@link #getTimeReference()}. Those values vary at a rate given by the parameters listed
in the
+ * table below:
+ *
+ * <table class="compact"><tr><td>
+ * <table class="sis">
+ *   <tr><th>Code</th> <th>Name</th>                      
          <th>Abbr.</th></tr>
+ *   <tr><td>1040</td> <td>Rate of change of X-axis translation</td>
<td>{@link #dtX}</td></tr>
+ *   <tr><td>1041</td> <td>Rate of change of Y-axis translation</td>
<td>{@link #dtY}</td></tr>
+ *   <tr><td>1042</td> <td>Rate of change of Z-axis translation</td>
<td>{@link #dtZ}</td></tr>
+ *   <tr><td>1043</td> <td>Rate of change of X-axis rotation</td>
   <td>{@link #drX}</td></tr>
+ *   <tr><td>1044</td> <td>Rate of change of Y-axis rotation</td>
   <td>{@link #drY}</td></tr>
+ *   <tr><td>1045</td> <td>Rate of change of Z-axis rotation</td>
   <td>{@link #drZ}</td></tr>
+ *   <tr><td>1046</td> <td>Rate of change of scale difference</td>
  <td>{@link #ddS}</td></tr>
+ * </table>
+ *
+ * The numerical fields in this {@code TimeDependentBWP} class uses the EPSG abbreviations
+ * with 4 additional constraints compared to the EPSG definitions:
+ *
+ * <ul>
+ *   <li>Unit of {@link #ddS} is fixed to <em>parts per million per year</em>.</li>
+ *   <li>Unit of {@link #dtX}, {@link #dtY} and {@link #dtZ} is fixed to <em>millimetres
per year</em>.</li>
+ *   <li>Unit of {@link #drX}, {@link #drY} and {@link #drZ} is fixed to <em>milli
arc-seconds per year</em>.</li>
+ *   <li>Sign of rotation terms is fixed to the <em>Position Vector</em>
convention (EPSG operation method 1053).
+ *       This is the opposite sign than the <cite>Coordinate Frame Rotation</cite>
(EPSG operation method 1056.
+ *       The Position Vector convention is used by IAG and recommended by ISO 19111.</li>
+ * </ul>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public class TimeDependentBWP extends BursaWolfParameters {
+    /**
+     * Serial number for inter-operability with different versions.
+     */
+    private static final long serialVersionUID = -4628799278259080258L;
+
+    /**
+     * Rate of change of X-axis translation in millimetres per year (EPSG:1040).
+     */
+    public double dtX;
+
+    /**
+     * Rate of change of Y-axis translation in millimetres per year (EPSG:1041).
+     */
+    public double dtY;
+
+    /**
+     * Rate of change of Z-axis translation in millimetres per year (EPSG:1042).
+     */
+    public double dtZ;
+
+    /**
+     * Rate of change of X-axis rotation in milli arc-seconds per year (EPSG:1043),
+     * sign following the <cite>Position Vector</cite> convention.
+     */
+    public double drX;
+
+    /**
+     * Rate of change of Y-axis rotation in milli arc-seconds per year (EPSG:1044),
+     * sign following the <cite>Position Vector</cite> convention.
+     */
+    public double drY;
+
+    /**
+     * Rate of change of Z-axis rotation in milli arc-seconds per year (EPSG:1045),
+     * sign following the <cite>Position Vector</cite> convention.
+     */
+    public double drZ;
+
+    /**
+     * Rate of change of the scale difference in parts per million per year (EPSG:1046).
+     */
+    public double ddS;
+
+    /**
+     * The reference epoch for time-dependent parameters (EPSG:1047).
+     */
+    private final long timeReference;
+
+    /**
+     * Creates a new instance for the given target datum, domain of validity and time reference.
+     * All numerical parameters are initialized to 0, which correspond to an identity transform.
+     * Callers can assign numerical values to the public fields of interest after construction.
+     *
+     * @param targetDatum The target datum (usually WGS 84) for this set of parameters, or
{@code null} if unspecified.
+     * @param domainOfValidity Area or region in which a coordinate transformation based
on those Bursa-Wolf parameters
+     *        is valid, or {@code null} is unspecified.
+     * @param timeReference The reference epoch for time-dependent parameters.
+     */
+    public TimeDependentBWP(final GeodeticDatum targetDatum, final Extent domainOfValidity,
final Date timeReference) {
+        super(targetDatum, domainOfValidity);
+        ensureNonNull("timeReference", timeReference);
+        this.timeReference = timeReference.getTime();
+    }
+
+    /**
+     * Verifies parameters validity after initialization.
+     */
+    @Override
+    void verify() {
+        super.verify();
+        ensureFinite("dtX", dtX);
+        ensureFinite("dtY", dtY);
+        ensureFinite("dtZ", dtZ);
+        ensureFinite("drX", drX);
+        ensureFinite("drY", drY);
+        ensureFinite("drZ", drZ);
+    }
+
+    /**
+     * Returns the reference epoch for time-dependent parameters.
+     *
+     * @return The reference epoch for time-dependent parameters.
+     */
+    public Date getTimeReference() {
+        return new Date(timeReference);
+    }
+
+    /**
+     * Returns the elapsed time from the {@linkplain TimeDependentBWP#getTimeReference()
reference time}
+     * to the given date in millennium, or {@code null} if none.
+     */
+    @Override
+    final DoubleDouble period(final Date time) {
+        if (time != null) {
+            final long millis = time.getTime() - timeReference;
+            if (millis != 0) { // Returns null for 0 as an optimization.
+                final DoubleDouble period = new DoubleDouble(millis, 0);
+                period.divide(1000 * JULIAN_YEAR_LENGTH, 0);
+                return period;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the parameter at the given index. If this {@code BursaWolfParameters} is time-dependent,
+     * then the returned value shall be corrected for the given period.
+     *
+     * @param index  0 for {@code tX}, 1 for {@code tY}, <i>etc.</i> in {@code
TOWGS84[…]} order.
+     * @param period The value computed by {@link #period(Date)}, or {@code null}.
+     */
+    @Override
+    final DoubleDouble param(final int index, final DoubleDouble period) {
+        final DoubleDouble p = super.param(index, period);
+        if (period != null) {
+            final double value = period.value;
+            final double error = period.error;
+            final double d;
+            switch (index) {
+                case 0: d = dtX; break;
+                case 1: d = dtY; break;
+                case 2: d = dtZ; break;
+                case 3: d = drX; break;
+                case 4: d = drY; break;
+                case 5: d = drZ; break;
+                case 6: d = ddS; period.multiply(1000, 0); break;
+                default: throw new AssertionError(index);
+            }
+            period.multiply(d);
+            p.add(period);
+            period.value = value;
+            period.error = error;
+        }
+        return p;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isIdentity() {
+        return super.isIdentity() && dtX == 0 && dtY == 0 && dtZ
== 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isTranslation() {
+        return super.isTranslation() && drX == 0 && drY == 0 && drZ
== 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(final Object object) {
+        if (super.equals(object)) {
+            final TimeDependentBWP that = (TimeDependentBWP) object;
+            return timeReference == that.timeReference &&
+                   Numerics.equals(this.dtX, that.dtX) &&
+                   Numerics.equals(this.dtY, that.dtY) &&
+                   Numerics.equals(this.dtZ, that.dtZ) &&
+                   Numerics.equals(this.drX, that.drX) &&
+                   Numerics.equals(this.drY, that.drY) &&
+                   Numerics.equals(this.drZ, that.drZ) &&
+                   Numerics.equals(this.ddS, that.ddS);
+        }
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        return ((int) serialVersionUID) ^ Arrays.hashCode(new double[] {
+            tX, tY, tZ, rX, rY, rZ, dS, dtX, dtY, dtZ, drX, drY, drZ, ddS, timeReference
+        });
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/FormulasTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/FormulasTest.java?rev=1541235&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/FormulasTest.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/FormulasTest.java
[UTF-8] Tue Nov 12 21:08:42 2013
@@ -0,0 +1,67 @@
+/*
+ * 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.internal.referencing;
+
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link Formulas}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final strictfp class FormulasTest extends TestCase {
+    /**
+     * Verifies the {@link Formulas#JULIAN_YEAR_LENGTH} constant.
+     */
+    @Test
+    public void testConstants() {
+        assertEquals(StrictMath.round(365.25 * 24 * 60 * 60 * 1000), Formulas.JULIAN_YEAR_LENGTH);
+    }
+
+    /**
+     * Tests {@link Formulas#isPoleToPole(double, double)}.
+     */
+    @Test
+    public void testIsPoleToPole() {
+        assertTrue (Formulas.isPoleToPole(-90, 90));
+        assertFalse(Formulas.isPoleToPole(-89, 90));
+        assertFalse(Formulas.isPoleToPole(-90, 89));
+    }
+
+    /**
+     * Tests {@link Formulas#getAuthalicRadius(double, double)} using the parameters of <cite>GRS
1980</cite>
+     * ellipsoid (EPSG:7019).
+     *
+     * <ul>
+     *   <li>Semi-major axis length: 6378137 metres</li>
+     *   <li>Inverse flattening: 298.257222101</li>
+     * </ul>
+     *
+     * Expected result is the radius of <cite>GRS 1980 Authalic Sphere</cite>
(EPSG:7048).
+     */
+    @Test
+    public void testGetAuthalicRadius() {
+        assertEquals(6371007, Formulas.getAuthalicRadius(6378137, 6356752), 0.5);
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/FormulasTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/FormulasTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java?rev=1541235&r1=1541234&r2=1541235&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
[UTF-8] Tue Nov 12 21:08:42 2013
@@ -91,7 +91,7 @@ public final strictfp class BursaWolfPar
         bursaWolf.rZ = 0.554;
         bursaWolf.dS = 0.219;
         final MatrixSIS toWGS84 = getPositionVectorTransformation(bursaWolf);
-        final MatrixSIS toWGS72 = getPositionVectorTransformation(bursaWolf).inverse();
+        final MatrixSIS toWGS72 = toWGS84.inverse();
         final MatrixSIS source  = Matrices.create(4, 1, new double[] {3657660.66, 255768.55,
5201382.11, 1});
         final MatrixSIS target  = Matrices.create(4, 1, new double[] {3657660.78, 255778.43,
5201387.75, 1});
         assertMatrixEquals("toWGS84", target, toWGS84.multiply(source), 0.01);
@@ -116,7 +116,7 @@ public final strictfp class BursaWolfPar
     }
 
     /**
-     * Tests the {@link BursaWolfParameters#setPositionVectorTransformation(Matrix, double)}
constructor.
+     * Tests the {@link BursaWolfParameters#setPositionVectorTransformation(Matrix, double)}
method.
      * This is an internal consistency test.
      */
     @Test

Added: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java?rev=1541235&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
[UTF-8] Tue Nov 12 21:08:42 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.datum;
+
+import java.util.Date;
+import org.opengis.referencing.operation.Matrix;
+import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.referencing.operation.matrix.MatrixSIS;
+import org.apache.sis.referencing.operation.matrix.NoninvertibleMatrixException;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.test.TestUtilities.date;
+import static org.apache.sis.internal.referencing.Formulas.JULIAN_YEAR_LENGTH;
+
+
+/**
+ * Tests {@link TimeDependentBWP}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+@DependsOn(BursaWolfParametersTest.class)
+public final strictfp class TimeDependentBWPTest extends TestCase {
+    /**
+     * Tests the {@link BursaWolfParameters#setPositionVectorTransformation(Matrix, double)}
method
+     * using the example given in the EPSG database for operation method EPSG:1053.
+     *
+     * @throws NoninvertibleMatrixException Should not happen.
+     */
+    @Test
+    public void testSetPositionVectorTransformation() throws NoninvertibleMatrixException
{
+        final TimeDependentBWP p = new TimeDependentBWP(null, null, date("1994-01-01 00:00:00"));
+        p.tX = -84.68  / 1000;  p.dtX = +1.42;
+        p.tY = -19.42  / 1000;  p.dtY = +1.34;
+        p.tZ = +32.01  / 1000;  p.dtZ = +0.90;
+        p.rX = +0.4254 / 1000;  p.drX = -1.5461;
+        p.rY = -2.2578 / 1000;  p.drY = -1.1820;
+        p.rZ = -2.4015 / 1000;  p.drZ = -1.1551;
+        p.dS = +0.00971;        p.ddS = +0.000109;
+        /*
+         * The transformation that we are going to test use as input
+         * geocentric coordinates on ITRF2008 at epoch 2013.9.
+         */
+        final Date time = p.getTimeReference();
+        time.setTime(time.getTime() + StrictMath.round((2013.9 - 1994) * JULIAN_YEAR_LENGTH));
+        assertEquals(date("2013-11-25 11:24:00"), time);
+        /*
+         * Transform the point and compare with the expected value given in the EPSG examples.
+         */
+        final MatrixSIS toGDA94    = MatrixSIS.castOrCopy(p.getPositionVectorTransformation(time));
+        final MatrixSIS toITRF2008 = toGDA94.inverse();
+        final MatrixSIS source     = Matrices.create(4, 1, new double[] {-3789470.702, 4841770.411,
-1690893.950, 1});
+        final MatrixSIS target     = Matrices.create(4, 1, new double[] {-3789470.008, 4841770.685,
-1690895.103, 1});
+//      assertMatrixEquals("toGDA94",    target, toGDA94   .multiply(source), 0.001);
+//      assertMatrixEquals("toITRF2008", source, toITRF2008.multiply(target), 0.001);
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1541235&r1=1541234&r2=1541235&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Tue Nov 12 21:08:42 2013
@@ -41,6 +41,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.operation.matrix.MatricesTest.class,
     org.apache.sis.referencing.operation.matrix.AffineTransforms2DTest.class,
 
+    org.apache.sis.internal.referencing.FormulasTest.class,
     org.apache.sis.io.wkt.ConventionTest.class,
     org.apache.sis.io.wkt.SymbolsTest.class,
     org.apache.sis.io.wkt.FormatterTest.class,
@@ -48,6 +49,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.AbstractIdentifiedObjectTest.class,
     org.apache.sis.referencing.AbstractReferenceSystemTest.class,
     org.apache.sis.referencing.datum.BursaWolfParametersTest.class,
+    org.apache.sis.referencing.datum.TimeDependentBWPTest.class,
 
     org.apache.sis.geometry.AbstractDirectPositionTest.class,
     org.apache.sis.geometry.GeneralDirectPositionTest.class,

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java?rev=1541235&r1=1541234&r2=1541235&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
[UTF-8] Tue Nov 12 21:08:42 2013
@@ -455,7 +455,7 @@ public final class DoubleDouble extends 
     }
 
     /**
-     * Adds a {@code Number} to the given number. If the given number is an instance
+     * Adds a {@code Number} value to this {@code DoubleDouble}. If the given number is an
instance
      * of {@code DoubleDouble}, then its error term will be taken in account.
      *
      * @param other The other value to add to this {@code DoubleDouble}.
@@ -567,6 +567,37 @@ public final class DoubleDouble extends 
     }
 
     /**
+     * Subtracts a {@code Number} from this {@code DoubleDouble}. If the given number is
an instance
+     * of {@code DoubleDouble}, then its error term will be taken in account.
+     *
+     * @param other The other value to subtract from this {@code DoubleDouble}.
+     */
+    public void subtract(final Number other) {
+        if (other instanceof DoubleDouble) {
+            subtract((DoubleDouble) other);
+        } else {
+            subtract(other.doubleValue());
+        }
+    }
+
+    /**
+     * Subtracts a {@code double} from this {@code DoubleDouble} with a default error term.
+     * This is a convenience method for:
+     *
+     * {@preformat java
+     *    subtract(otherValue, errorForWellKnownValue(otherValue));
+     * }
+     *
+     * <b>Tip:</b> if the other value is known to be an integer or a power of
2, then invoking
+     * <code>{@linkplain #subtract(double, double) subtract}(otherValue, 0)</code>
is more efficient.
+     *
+     * @param otherValue The other value to subtract from this {@code DoubleDouble}.
+     */
+    public void subtract(final double otherValue) {
+        subtract(otherValue, errorForWellKnownValue(otherValue));
+    }
+
+    /**
      * Subtracts an other double-double value from this {@code DoubleDouble}.
      * The result is stored in this instance.
      *
@@ -608,6 +639,37 @@ public final class DoubleDouble extends 
     }
 
     /**
+     * Multiplies this {@code DoubleDouble} by a {@code Number}. If the given number is an
instance
+     * of {@code DoubleDouble}, then its error term will be taken in account.
+     *
+     * @param other The other value to multiply by this {@code DoubleDouble}.
+     */
+    public void multiply(final Number other) {
+        if (other instanceof DoubleDouble) {
+            multiply((DoubleDouble) other);
+        } else {
+            multiply(other.doubleValue());
+        }
+    }
+
+    /**
+     * Multiplies this {@code DoubleDouble} by a {@code double} with a default error term.
+     * This is a convenience method for:
+     *
+     * {@preformat java
+     *    multiply(otherValue, errorForWellKnownValue(otherValue));
+     * }
+     *
+     * <b>Tip:</b> if the other value is known to be an integer or a power of
2, then invoking
+     * <code>{@linkplain #multiply(double, double) multiply}(otherValue, 0)</code>
is more efficient.
+     *
+     * @param otherValue The other value to multiply by this {@code DoubleDouble}.
+     */
+    public void multiply(final double otherValue) {
+        multiply(otherValue, errorForWellKnownValue(otherValue));
+    }
+
+    /**
      * Multiplies this {@code DoubleDouble} by an other double-double value.
      * The result is stored in this instance.
      *
@@ -678,6 +740,37 @@ public final class DoubleDouble extends 
     }
 
     /**
+     * Divides this {@code DoubleDouble} by a {@code Number}. If the given number is an instance
+     * of {@code DoubleDouble}, then its error term will be taken in account.
+     *
+     * @param other The other value by which to divide this {@code DoubleDouble}.
+     */
+    public void divide(final Number other) {
+        if (other instanceof DoubleDouble) {
+            divide((DoubleDouble) other);
+        } else {
+            divide(other.doubleValue());
+        }
+    }
+
+    /**
+     * Divides this {@code DoubleDouble} by a {@code double} with a default error term.
+     * This is a convenience method for:
+     *
+     * {@preformat java
+     *    divide(otherValue, errorForWellKnownValue(otherValue));
+     * }
+     *
+     * <b>Tip:</b> if the other value is known to be an integer or a power of
2, then invoking
+     * <code>{@linkplain #divide(double, double) divide}(otherValue, 0)</code>
is more efficient.
+     *
+     * @param otherValue The other value by which to divide this {@code DoubleDouble}.
+     */
+    public void divide(final double otherValue) {
+        divide(otherValue, errorForWellKnownValue(otherValue));
+    }
+
+    /**
      * Divides this {@code DoubleDouble} by an other double-double value.
      * The result is stored in this instance.
      *



Mime
View raw message