sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Move a WKT utility method to WKTUtilities internal class.
Date Sat, 04 Jan 2020 17:53:12 GMT
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 db59cb53d7842be5e94d14a36d456f3254769e67
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sat Jan 4 18:52:45 2020 +0100

    Move a WKT utility method to WKTUtilities internal class.
---
 .../sis/internal/referencing/WKTUtilities.java     | 42 ++++++++++++++++++++--
 .../main/java/org/apache/sis/io/wkt/Formatter.java |  2 +-
 .../sis/internal/referencing/WKTUtilitiesTest.java | 14 +++++++-
 .../org/apache/sis/internal/util/Numerics.java     | 42 ----------------------
 .../org/apache/sis/internal/util/NumericsTest.java | 15 +-------
 5 files changed, 55 insertions(+), 60 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
index 4b149b0..89ac500 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
@@ -58,6 +58,7 @@ import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.math.DecimalFunctions;
+import org.apache.sis.math.Statistics;
 import org.apache.sis.math.Vector;
 
 
@@ -70,7 +71,7 @@ import org.apache.sis.math.Vector;
  * We need to be specific in order to select the right "aspect" of the given object.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.4
  * @module
  */
@@ -349,6 +350,43 @@ public final class WKTUtilities extends Static {
     }
 
     /**
+     * Suggests an amount of fraction digits to use for formatting numbers in each column
of the given matrix.
+     * The number of fraction digits may be negative if we could round the numbers to 10,
100, <i>etc</i>.
+     *
+     * @param  rows  the matrix rows. It is not required that each row has the same length.
+     * @return suggested amount of fraction digits as an array as long as the longest row.
+     *
+     * @see org.apache.sis.referencing.operation.matrix.Matrices#toString(Matrix)
+     */
+    public static int[] suggestFractionDigits(final Vector[] rows) {
+        int length = 0;
+        final int n = rows.length - 1;
+        for (int j=0; j <= n; j++) {
+            final int rl = rows[j].size();
+            if (rl > length) length = rl;
+        }
+        final int[] fractionDigits = new int[length];
+        final Statistics stats = new Statistics(null);
+        for (int i=0; i<length; i++) {
+            boolean isInteger = true;
+            for (final Vector row : rows) {
+                if (row.size() > i) {
+                    final double value = row.doubleValue(i);
+                    stats.accept(value);
+                    if (isInteger && Math.floor(value) != value && !Double.isNaN(value))
{
+                        isInteger = false;
+                    }
+                }
+            }
+            if (!isInteger) {
+                fractionDigits[i] = Numerics.suggestFractionDigits(stats);
+            }
+            stats.reset();
+        }
+        return fractionDigits;
+    }
+
+    /**
      * Suggests an amount of fraction digits to use for formatting numbers in each column
of the given sequence
      * of points. The number of fraction digits may be negative if we could round the numbers
to 10, <i>etc</i>.
      *
@@ -357,7 +395,7 @@ public final class WKTUtilities extends Static {
      * @return suggested amount of fraction digits as an array as long as the longest row.
      */
     public static int[] suggestFractionDigits(final CoordinateReferenceSystem crs, final
Vector[] points) {
-        final int[] fractionDigits = Numerics.suggestFractionDigits(points);
+        final int[] fractionDigits = suggestFractionDigits(points);
         final Ellipsoid ellipsoid = ReferencingUtilities.getEllipsoid(crs);
         if (ellipsoid != null) {
             /*
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
index 92780cd..3657a23 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
@@ -1239,7 +1239,7 @@ public class Formatter implements Localized {
             return;
         }
         if (fractionDigits == null || fractionDigits.length == 0) {
-            fractionDigits = Numerics.suggestFractionDigits(rows);
+            fractionDigits = WKTUtilities.suggestFractionDigits(rows);
         }
         numberFormat.setRoundingMode(RoundingMode.HALF_EVEN);
         /*
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WKTUtilitiesTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WKTUtilitiesTest.java
index 7108002..385e3e4 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WKTUtilitiesTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WKTUtilitiesTest.java
@@ -32,7 +32,7 @@ import static org.apache.sis.internal.referencing.WKTUtilities.*;
  * Tests {@link WKTUtilities}.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.7
  * @module
  */
@@ -59,6 +59,18 @@ public final strictfp class WKTUtilitiesTest extends TestCase {
     }
 
     /**
+     * Tests {@link WKTUtilities#suggestFractionDigits(Vector[])}.
+     */
+    @Test
+    public void testSuggestFractionDigitsFromVectors() {
+        final int[] f = WKTUtilities.suggestFractionDigits(new Vector[] {
+            Vector.create(new double[] {10, 100,   0.1, 1000.1}),
+            Vector.create(new double[] {15, 140.1, 0.4, Double.NaN}),
+            Vector.create(new double[] {20, 400,   0.5, Double.NaN})});
+        assertArrayEquals(new int[] {0, 0, 3, 3}, f);
+    }
+
+    /**
      * Tests {@link WKTUtilities#suggestFractionDigits(CoordinateReferenceSystem, Vector[])}.
      */
     @Test
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java b/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
index 5bd16e0..27edc5e 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
@@ -27,8 +27,6 @@ import org.apache.sis.util.Workaround;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.math.DecimalFunctions;
 import org.apache.sis.math.Statistics;
-import org.apache.sis.math.Vector;
-import org.opengis.referencing.operation.Matrix;    // For javadoc
 
 import static java.lang.Math.min;
 import static java.lang.Math.max;
@@ -602,46 +600,6 @@ public final class Numerics extends Static {
     }
 
     /**
-     * Suggests an amount of fraction digits to use for formatting numbers in each column
of the given matrix.
-     * The number of fraction digits may be negative if we could round the numbers to 10,
100, <i>etc</i>.
-     *
-     * @param  rows  the matrix rows. It is not required that each row has the same length.
-     * @return suggested amount of fraction digits as an array as long as the longest row.
-     *
-     * @see org.apache.sis.referencing.operation.matrix.Matrices#toString(Matrix)
-     *
-     * @todo Move into {@link org.apache.sis.internal.referencing.WKTUtilities}
-     *       if we move WKT parser/formatter to referencing module.
-     */
-    public static int[] suggestFractionDigits(final Vector[] rows) {
-        int length = 0;
-        final int n = rows.length - 1;
-        for (int j=0; j <= n; j++) {
-            final int rl = rows[j].size();
-            if (rl > length) length = rl;
-        }
-        final int[] fractionDigits = new int[length];
-        final Statistics stats = new Statistics(null);
-        for (int i=0; i<length; i++) {
-            boolean isInteger = true;
-            for (final Vector row : rows) {
-                if (row.size() > i) {
-                    final double value = row.doubleValue(i);
-                    stats.accept(value);
-                    if (isInteger && Math.floor(value) != value && !Double.isNaN(value))
{
-                        isInteger = false;
-                    }
-                }
-            }
-            if (!isInteger) {
-                fractionDigits[i] = suggestFractionDigits(stats);
-            }
-            stats.reset();
-        }
-        return fractionDigits;
-    }
-
-    /**
      * Formats the given value with the given format, using scientific notation if needed.
      * This is a workaround for {@link DecimalFormat} not switching automatically to scientific
notation for large numbers.
      *
diff --git a/core/sis-utility/src/test/java/org/apache/sis/internal/util/NumericsTest.java
b/core/sis-utility/src/test/java/org/apache/sis/internal/util/NumericsTest.java
index 22c2053..5c64ba1 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/internal/util/NumericsTest.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/internal/util/NumericsTest.java
@@ -21,7 +21,6 @@ import org.apache.sis.math.MathFunctions;
 import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.util.ComparisonMode;
-import org.apache.sis.math.Vector;
 import org.junit.Test;
 
 import static java.lang.Double.NaN;
@@ -35,7 +34,7 @@ import static org.junit.Assert.*;
  * Tests the {@link Numerics} class.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.3
  * @module
  */
@@ -189,16 +188,4 @@ public final strictfp class NumericsTest extends TestCase {
         final float recomposed = StrictMath.scalb((float) expected, e);
         assertEquals(value, StrictMath.copySign(recomposed, value), 0f);
     }
-
-    /**
-     * Tests {@link Numerics#suggestFractionDigits(Vector[])}.
-     */
-    @Test
-    public void testSuggestFractionDigits() {
-        final int[] f = Numerics.suggestFractionDigits(new Vector[] {
-            Vector.create(new double[] {10, 100,   0.1, 1000.1}),
-            Vector.create(new double[] {15, 140.1, 0.4, Double.NaN}),
-            Vector.create(new double[] {20, 400,   0.5, Double.NaN})});
-        assertArrayEquals(new int[] {0, 0, 3, 3}, f);
-    }
 }


Mime
View raw message