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

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 53cbe72ac4e926537ffd751e03c0b8e79e074749
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Fri Aug 30 17:13:27 2019 +0200

    Fix the SIS-377 fix: standard foot (0.3048 meter) shall not be confused 
with US survey foot.
    See https://issues.apache.org/jira/browse/SIS-377
---
 .../org/apache/sis/io/wkt/MathTransformParser.java | 23 ++++++++++++----------
 .../apache/sis/io/wkt/MathTransformParserTest.java | 21 +++++++++++++++++++-
 .../sis/test/integration/ConsistencyTest.java      |  2 +-
 .../java/org/apache/sis/math/DecimalFunctions.java |  4 ++--
 4 files changed, 36 insertions(+), 14 deletions(-)

diff --git 
a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
 
b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
index a1a3517..fd0711f 100644
--- 
a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
+++ 
b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
@@ -81,8 +81,8 @@ class MathTransformParser extends AbstractParser {
     };
 
     /**
-     * The base unit associated to the {@link #UNIT_KEYWORDS}, ignoring {@link 
WKTKeywords#Unit}.
-     * For each {@code UNIT_KEYWORDS[i]} element, the associated base unit is 
{@code BASE_UNIT[i]}.
+     * The base units associated to the {@link #UNIT_KEYWORDS}, ignoring 
{@link WKTKeywords#Unit}.
+     * For each {@code UNIT_KEYWORDS[i]} element, the associated base unit is 
{@code BASE_UNIT[i-1]}.
      */
     private static final Unit<?>[] BASE_UNITS = {
         Units.METRE, Units.RADIAN, Units.UNITY, Units.SECOND
@@ -93,14 +93,17 @@ class MathTransformParser extends AbstractParser {
      * Some Well Known Texts define factors with low accuracy, as in {@code 
ANGLEUNIT["degree", 0.01745329252]}.
      * This causes the parser to fail to recognize that the unit is degree and 
to convert angles with that factor.
      * This may result in surprising behavior like <a 
href="https://issues.apache.org/jira/browse/SIS-377";>SIS-377</a>.
-     * This array is a workaround for that problem, adding the missing 
accuracy to factors. Only factors having many
-     * digits need to appear here. For example there is no need to declare the 
conversion factor for foot (0.3048)
-     * because that factor requires only 4 fraction digits, which are usually 
present in WKT.
+     * This array is a workaround for that problem, adding the missing 
accuracy to factors.
+     * This workaround should be removed in a future version if we fix
+     * <a href="https://issues.apache.org/jira/browse/SIS-433";>SIS-433</a>.
      *
      * <p>Values in each array <strong>must</strong> be sorted in ascending 
order.</p>
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-377";>SIS-377</a>
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-433";>SIS-433</a>
      */
     private static final double[][] CONVERSION_FACTORS = {
-        {0.3047972654,              // Clarke's foot
+        {0.3048,                    // foot, declared for avoiding that unit 
to be confused with US survey foot.
          0.30480060960121924,       // US survey foot
          1609.3472186944375},       // US survey mile
         {Math.PI/(180*60*60),       // Arc-second:  4.84813681109536E-6
@@ -291,8 +294,8 @@ class MathTransformParser extends AbstractParser {
 
     /**
      * If the unit conversion factor specified in the Well Known Text is 
missing some fraction digits,
-     * try to complete them. The main use case is to replace 0.01745329252 by 
0.017453292519943295 in
-     * degree units.
+     * tries to complete them. The main use case is to replace 0.01745329252 
by 0.017453292519943295
+     * in degree units.
      *
      * @param  predefined  some known conversion factors, in ascending order.
      * @param  factor      the conversion factor specified in the Well Known 
Text element.
@@ -318,8 +321,8 @@ class MathTransformParser extends AbstractParser {
 
     /**
      * If the unit conversion factor specified in the Well Known Text is 
missing some fraction digits,
-     * try to complete them. The main use case is to replace 0.01745329252 by 
0.017453292519943295 in
-     * degree units.
+     * tries to complete them. The main use case is to replace 0.01745329252 
by 0.017453292519943295
+     * in degree units.
      *
      * @param  baseUnit  the base unit for which to complete the conversion 
factor.
      * @param  factor    the conversion factor specified in the Well Known 
Text element.
diff --git 
a/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java
 
b/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java
index d13ebd7..7728b78 100644
--- 
a/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java
+++ 
b/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java
@@ -25,6 +25,7 @@ import org.apache.sis.referencing.operation.matrix.Matrix2;
 import org.apache.sis.referencing.operation.matrix.Matrix3;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 import 
org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory;
+import org.apache.sis.measure.Units;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -37,7 +38,7 @@ import static org.opengis.test.Assert.*;
  * Tests {@link MathTransformParser}.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.6
+ * @version 1.0
  * @since   0.6
  * @module
  */
@@ -49,6 +50,24 @@ public final strictfp class MathTransformParserTest extends 
TestCase {
     private MathTransformParser parser;
 
     /**
+     * Tests {@link MathTransformParser#completeUnitFactor(Unit, double)}.
+     * This is not used directly by {@link MathTransformParser}, but is needed 
by subclass.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-377";>SIS-377</a>
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-433";>SIS-433</a>
+     */
+    @Test
+    public void testCompleteUnitFactor() {
+        assertEquals(0.017453292519943295, 
MathTransformParser.completeUnitFactor(Units.RADIAN, 0.01745329252), STRICT);   
 // SIS-377
+        assertEquals(0.01745329252,        
MathTransformParser.completeUnitFactor(Units.METRE,  0.01745329252), STRICT);   
 // Not the right kind of units.
+        assertEquals(0.3048,               
MathTransformParser.completeUnitFactor(Units.METRE,  0.3048),        STRICT);   
 // Check there is no confusion with US survey foot.
+        assertEquals(0.30480060960121924,  
MathTransformParser.completeUnitFactor(Units.METRE,  0.3048006096),  STRICT);   
 // US survey foot.
+        assertEquals(0.3048007491,         
MathTransformParser.completeUnitFactor(Units.METRE,  0.3048007491),  STRICT);   
 // British foot (1936).
+        assertEquals(0.30479841,           
MathTransformParser.completeUnitFactor(Units.METRE,  0.30479841),    STRICT);   
 // Indian foot (1937).
+        assertEquals(0.3047,               
MathTransformParser.completeUnitFactor(Units.METRE,  0.3047),        STRICT);
+    }
+
+    /**
      * Parses the given text.
      *
      * @throws ParseException if an error occurred during the parsing.
diff --git 
a/core/sis-referencing/src/test/java/org/apache/sis/test/integration/ConsistencyTest.java
 
b/core/sis-referencing/src/test/java/org/apache/sis/test/integration/ConsistencyTest.java
index c364c7f..614da83 100644
--- 
a/core/sis-referencing/src/test/java/org/apache/sis/test/integration/ConsistencyTest.java
+++ 
b/core/sis-referencing/src/test/java/org/apache/sis/test/integration/ConsistencyTest.java
@@ -164,7 +164,7 @@ public final strictfp class ConsistencyTest extends 
TestCase {
     }
 
     /**
-     * Formats the given CRS using the given formatter, parses it and reformat 
again.
+     * Formats the given CRS using the given formatter, parses it and 
reformats again.
      * Then the two WKT are compared.
      *
      * @param  f     the formatter to use.
diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java 
b/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
index 15a3b3c..a7bc118 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
@@ -509,8 +509,8 @@ public final class DecimalFunctions extends Static {
      * <table class="sis">
      *   <caption>Examples</caption>
      *   <tr><th>Accurate</th> <th>Approximate</th> <th>Result</th> 
<th>Comment</th></tr>
-     *   <tr><td>0.123456</td> <td>0.123</td>       <td>true</td>   <td>Differ 
on in digits not specified by {@code approximate}.</td></tr>
-     *   <tr><td>0.123456</td> <td>0.123000</td>    <td>true</td>   <td>This 
method can no distinguish missing digits from trailing zeros.</td></tr>
+     *   <tr><td>0.123456</td> <td>0.123</td>       <td>true</td>   <td>Differ 
in digits not specified by {@code approximate}.</td></tr>
+     *   <tr><td>0.123456</td> <td>0.123000</td>    <td>true</td>   <td>This 
method can not distinguish missing digits from trailing zeros.</td></tr>
      *   <tr><td>0.123456</td> <td>0.123001</td>    <td>false</td>  <td>No 
missing digits, and some of them differ.</td></tr>
      *   <tr><td>0.123</td>    <td>0.123456</td>    <td>false</td>  <td>{@code 
approximate} and {@code accurate} can not be interchanged.</td></tr>
      * </table>

Reply via email to