sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1538427 - in /sis/branches/JDK7/core: sis-referencing/src/main/java/org/apache/sis/referencing/datum/ sis-referencing/src/test/java/org/apache/sis/referencing/datum/ sis-utility/src/main/java/org/apache/sis/math/ sis-utility/src/test/java/...
Date Sun, 03 Nov 2013 19:40:31 GMT
Author: desruisseaux
Date: Sun Nov  3 19:40:31 2013
New Revision: 1538427

URL: http://svn.apache.org/r1538427
Log:
Renamed DecimalFunctions.convert(float) as floatToDouble(float), and minor change in the algorithm
for improving the accuracy.

Modified:
    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-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java

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=1538427&r1=1538426&r2=1538427&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] Sun Nov  3 19:40:31 2013
@@ -27,6 +27,7 @@ import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.util.Numerics;
+import org.apache.sis.internal.util.DoubleDouble;
 import org.apache.sis.referencing.IdentifiedObjects;
 
 import static java.lang.Math.PI;
@@ -159,7 +160,7 @@ public class BursaWolfParameters extends
     /**
      * The conversion factor from <cite>parts per million</cite> to scale minus
one.
      */
-    private static final double PPM = 1E+6;
+    static final double PPM = 1E+6;
 
     /**
      * The conversion factor from arc-seconds to radians.
@@ -373,6 +374,12 @@ public class BursaWolfParameters extends
      * @see DefaultGeodeticDatum#getPositionVectorTransformation(GeodeticDatum)
      */
     public Matrix getPositionVectorTransformation(final boolean inverse) {
+        if (!isTranslation()) {
+            final double sgn = inverse ? -1 : +1;
+            final DoubleDouble S = new DoubleDouble(PPM, 0);
+            S.inverseDivide(sgn*dS, 0);
+            
+        }
         final double sgn = inverse ? -1 : +1;
         final double   S = 1 + sgn*dS / PPM;
         final double  RS = sgn*TO_RADIANS * S;

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=1538427&r1=1538426&r2=1538427&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] Sun Nov  3 19:40:31 2013
@@ -18,6 +18,7 @@ package org.apache.sis.referencing.datum
 
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.referencing.operation.matrix.Matrix4;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -35,6 +36,25 @@ import static org.apache.sis.test.Assert
  */
 public final strictfp class BursaWolfParametersTest extends TestCase {
     /**
+     * The conversion factor from arc-seconds to radians.
+     */
+    private static final double TO_RADIANS = Math.PI / (180 * 60 * 60);
+
+    /**
+     * Same implementation than {@link BursaWolfParameters#getPositionVectorTransformation(boolean)}
+     * using only {@code double} arithmetic, for verification purpose.
+     */
+    private static Matrix4 getPositionVectorTransformation(final BursaWolfParameters p, final
boolean inverse) {
+        final double sgn = inverse ? -1 : +1;
+        final double   S = 1 + sgn*p.dS / BursaWolfParameters.PPM;
+        final double  RS = sgn*TO_RADIANS * S;
+        return new Matrix4(
+                   S,  -p.rZ*RS,  +p.rY*RS,  sgn*p.tX,
+            +p.rZ*RS,         S,  -p.rX*RS,  sgn*p.tY,
+            -p.rY*RS,  +p.rX*RS,         S,  sgn*p.tZ,
+                   0,         0,         0,      1);
+    }
+    /**
      * Tests {@link BursaWolfParameters#getPositionVectorTransformation(boolean)}.
      * This test transform a point from WGS72 to WGS84, and conversely,
      * as documented in the example section of EPSG operation method 9606.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java?rev=1538427&r1=1538426&r2=1538427&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
[UTF-8] Sun Nov  3 19:40:31 2013
@@ -68,12 +68,12 @@ public final class DecimalFunctions exte
      * Converts the given {@code float} value to a {@code double} with the extra <em>decimal</em>
fraction digits
      * set to zero. This is different than the standard cast in the Java language, which
set the extra <em>binary</em>
      * fraction digits to zero.
-     * For example {@code (double) 0.1f} gives 0.10000000149011612 while {@code convert(0.1f)}
returns 0.1.
+     * For example {@code (double) 0.1f} gives 0.10000000149011612 while {@code floatToDouble(0.1f)}
returns 0.1.
      *
      * {@note This method is <strong>not</strong> more accurate than the standard
Java cast —
      *        it is only more intuitive for human used to base 10.
      *        If the value come directly from an ASCII file or a user input, then this method
may be useful
-     *        because the value was probably expressed in base 10 before conversion to a
{@code float}.
+     *        because the value was probably expressed in base 10 before conversion to a
<code>float</code>.
      *        But if the value come from an instrument measurement or a calculation, then
there is probably
      *        no reason to use this method because base 10 is not more "real" than base 2
or any other base
      *        for natural phenomenon.}
@@ -88,7 +88,7 @@ public final class DecimalFunctions exte
      * @param  value The {@code float} value to convert as a {@code double}.
      * @return The given value as a {@code double} with the extra decimal fraction digits
set to zero.
      */
-    public static double convert(final float value) {
+    public static double floatToDouble(final float value) {
         if (Float.isNaN(value) || Float.isInfinite(value) || value == 0f) {
             return value;
         }
@@ -120,17 +120,11 @@ public final class DecimalFunctions exte
          * to the tens instead of unities. If the difference appears to not be smaller than
half a ULP,
          * then the last digit was not extranous - we need to keep it.
          */
-        double delta = Math.rint(mc/10)*10 - mc;
-        if (Math.abs(delta) >= c/2) {
-            delta = Math.rint(mc) - mc;
+        double r = Math.rint(mc / 10) * 10;
+        if (Math.abs(r - mc) >= c/2) {
+            r = Math.rint(mc);
         }
-        /*
-         * Now compute the final adjustment that we need to apply to the value.
-         * This adjustment shall always be lower then half a ULP.
-         */
-        delta = Math.scalb(delta / c, e);
-        assert Math.abs(delta) < Math.ulp(value) / 2 : value;
-        return value + delta;
+        return Math.scalb(r / c, e);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java?rev=1538427&r1=1538426&r2=1538427&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java
[UTF-8] Sun Nov  3 19:40:31 2013
@@ -16,9 +16,11 @@
  */
 package org.apache.sis.math;
 
+import java.util.Random;
 import org.junit.Test;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestUtilities;
 
 import static org.junit.Assert.*;
 import static java.lang.Double.*;
@@ -56,17 +58,22 @@ public final strictfp class DecimalFunct
     }
 
     /**
-     * Tests {@link DecimalFunctions#convert(float)}.
+     * Tests {@link DecimalFunctions#floatToDouble(float)}.
      */
     @Test
-    public void testConvertAsDecimal() {
-        assertEquals(10,     convert(10f),     0);
-        assertEquals(0.1,    convert(0.1f),    0);
-        assertEquals(0.01,   convert(0.01f),   0);
-        assertEquals(0.001,  convert(0.001f),  0);
-        assertEquals(0.0001, convert(0.0001f), 0);
-        assertEquals(3.7E-8, convert(3.7E-8f), 0);
-//      assertEquals(3.7E-9, convert(3.7E-9f), 0);
+    public void testFloatToDouble() {
+        assertEquals(10,     floatToDouble(10f),     0);
+        assertEquals(0.1,    floatToDouble(0.1f),    0);
+        assertEquals(0.01,   floatToDouble(0.01f),   0);
+        assertEquals(0.001,  floatToDouble(0.001f),  0);
+        assertEquals(0.0001, floatToDouble(0.0001f), 0);
+        assertEquals(3.7E-8, floatToDouble(3.7E-8f), 0);
+        assertEquals(3.7E-9, floatToDouble(3.7E-9f), 0);
+        final Random random = TestUtilities.createRandomNumberGenerator();
+        for (int i=0; i<100; i++) {
+            final float value = Math.scalb(random.nextFloat(), random.nextInt(20) - 10);
+            assertEquals(String.valueOf(value), String.valueOf(floatToDouble(value)));
+        }
     }
 
     /**



Mime
View raw message