sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1650566 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/geometry/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ sis-refe...
Date Fri, 09 Jan 2015 15:32:32 GMT
Author: desruisseaux
Date: Fri Jan  9 15:32:31 2015
New Revision: 1650566

URL: http://svn.apache.org/r1650566
Log:
Added tests.

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java?rev=1650566&r1=1650565&r2=1650566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
[UTF-8] Fri Jan  9 15:32:31 2015
@@ -268,6 +268,9 @@ public final class Envelopes extends Sta
          * ordinate values. This coordinate will be updated in the 'switch' statement inside
          * the 'while' loop.
          */
+        if (sourceDim >= 20) { // Maximal value supported by Formulas.pow3(int) is 19.
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.ExcessiveNumberOfDimensions_1));
+        }
         int             pointIndex            = 0;
         boolean         isDerivativeSupported = true;
         GeneralEnvelope transformed           = null;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java?rev=1650566&r1=1650565&r2=1650566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
[UTF-8] Fri Jan  9 15:32:31 2015
@@ -72,6 +72,7 @@ public final class Formulas extends Stat
 
     /**
      * Returns 3ⁿ for very small (less than 10) positive values of <var>n</var>.
+     * Note that this method overflow for any value equals or greater than 20.
      *
      * @param n The exponent.
      * @return 3ⁿ
@@ -81,6 +82,7 @@ public final class Formulas extends Stat
      * @since 0.5
      */
     public static int pow3(int n) {
+        assert n >= 0 && n <= 19 : n;
         int p = 1;
         while (--n >= 0) {
             p *= 3;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java?rev=1650566&r1=1650565&r2=1650566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java
[UTF-8] Fri Jan  9 15:32:31 2015
@@ -62,6 +62,10 @@ public final class ShapeUtilities extend
      * @param  bx2 <var>x</var> value of the last  point on the second line.
      * @param  by2 <var>y</var> value of the last  point on the second line.
      * @return The intersection point, or {@code null} if none.
+     *
+     * @todo This method is used by Geotk (a sandbox for code that may migrate to SIS), but
not yet by SIS.
+     *       We temporarily keep this code here, but may delete or move it elsewhere in a
future SIS version
+     *       depending whether we port to SIS the sandbox code.
      */
     public static Point2D.Double intersectionPoint(final double ax1, final double ay1, double
ax2, double ay2,
                                                    final double bx1, final double by1, double
bx2, double by2)
@@ -113,6 +117,10 @@ public final class ShapeUtilities extend
      * @return The nearest point on the given line.
      *
      * @see #colinearPoint(double,double , double,double , double,double , double)
+     *
+     * @todo This method is used by Geotk (a sandbox for code that may migrate to SIS), but
not yet by SIS.
+     *       We temporarily keep this code here, but may delete or move it elsewhere in a
future SIS version
+     *       depending whether we port to SIS the sandbox code.
      */
     public static Point2D.Double nearestColinearPoint(final double x1, final double y1,
                                                       final double x2, final double y2,
@@ -170,6 +178,10 @@ public final class ShapeUtilities extend
      * @return A point on the given line located at the given distance from the given point.
      *
      * @see #nearestColinearPoint(double,double , double,double , double,double)
+     *
+     * @todo This method is used by Geotk (a sandbox for code that may migrate to SIS), but
not yet by SIS.
+     *       We temporarily keep this code here, but may delete or move it elsewhere in a
future SIS version
+     *       depending whether we port to SIS the sandbox code.
      */
     public static Point2D.Double colinearPoint(double x1, double y1, double x2, double y2,
                                                double x, double y, double distance)
@@ -245,10 +257,10 @@ public final class ShapeUtilities extend
      *
      * Note that if {@code P0.y == P2.y}, then both {@code horizontal} values produce the
same result.
      *
-     * @param  x0 <var>x</var> value of the starting point.
-     * @param  y0 <var>y</var> value of the starting point.
-     * @param  x1 <var>x</var> value of a passing point.
-     * @param  y1 <var>y</var> value of a passing point.
+     * @param  x1 <var>x</var> value of the starting point.
+     * @param  y1 <var>y</var> value of the starting point.
+     * @param  px <var>x</var> value of a passing point.
+     * @param  py <var>y</var> value of a passing point.
      * @param  x2 <var>x</var> value of the ending point.
      * @param  y2 <var>y</var> value of the ending point.
      * @param  horizontal If {@code true}, the <var>x</var> axis is considered
horizontal while computing the
@@ -256,14 +268,18 @@ public final class ShapeUtilities extend
      *         joining the {@code P0} and {@code P2} points.
      * @return A quadratic curve passing by the given points. The curve starts at {@code
P0} and ends at {@code P2}.
      *         If two points are too close or if the three points are colinear, then this
method returns {@code null}.
+     *
+     * @todo This method is used by Geotk (a sandbox for code that may migrate to SIS), but
not yet by SIS.
+     *       We temporarily keep this code here, but may delete or move it elsewhere in a
future SIS version
+     *       depending whether we port to SIS the sandbox code.
      */
-    public static QuadCurve2D.Double fitParabol(final double x0, final double y0,
-                                                final double x1, final double y1,
+    public static QuadCurve2D.Double fitParabol(final double x1, final double y1,
+                                                final double px, final double py,
                                                 final double x2, final double y2,
                                                 final boolean horizontal)
     {
-        final Point2D.Double p = parabolicControlPoint(x0, y0, x1, y1, x2, y2, horizontal);
-        return (p != null) ? new QuadCurve2D.Double(x0, y0, p.x, p.y, x2, y2) : null;
+        final Point2D.Double p = parabolicControlPoint(x1, y1, px, py, x2, y2, horizontal);
+        return (p != null) ? new QuadCurve2D.Double(x1, y1, p.x, p.y, x2, y2) : null;
     }
 
     /**
@@ -282,10 +298,10 @@ public final class ShapeUtilities extend
      *
      * Note that if {@code P0.y == P2.y}, then both {@code horizontal} values produce the
same result.
      *
-     * @param  x0 <var>x</var> value of the starting point.
-     * @param  y0 <var>y</var> value of the starting point.
-     * @param  x1 <var>x</var> value of a passing point.
-     * @param  y1 <var>y</var> value of a passing point.
+     * @param  x1 <var>x</var> value of the starting point.
+     * @param  y1 <var>y</var> value of the starting point.
+     * @param  px <var>x</var> value of a passing point.
+     * @param  py <var>y</var> value of a passing point.
      * @param  x2 <var>x</var> value of the ending point.
      * @param  y2 <var>y</var> value of the ending point.
      * @param  horizontal If {@code true}, the <var>x</var> axis is considered
horizontal while computing the
@@ -295,26 +311,26 @@ public final class ShapeUtilities extend
      *         and ends at {@code (x2,y2)}. If two points are too close or if the three points
are colinear, then this
      *         method returns {@code null}.
      */
-    public static Point2D.Double parabolicControlPoint(final double x0, final double y0,
-            double x1, double y1, double x2, double y2, final boolean horizontal)
+    public static Point2D.Double parabolicControlPoint(final double x1, final double y1,
+            double px, double py, double x2, double y2, final boolean horizontal)
     {
         /*
          * Apply a translation in such a way that (x0,y0) become the coordinate system origin.
          * After this translation, we shall not use (x0,y0) until we are done.
          */
-        x1 -= x0;
-        y1 -= y0;
-        x2 -= x0;
-        y2 -= y0;
+        px -= x1;
+        py -= y1;
+        x2 -= x1;
+        y2 -= y1;
         if (horizontal) {
-            final double a = (y2 - y1*x2/x1) / (x2-x1); // Actually "a*x2"
+            final double a = (y2 - py*x2/px) / (x2-px); // Actually "a*x2"
             final double check = abs(a);
             if (!(check <= 1/EPS)) return null; // Two points have the same coordinates.
             if (!(check >=   EPS)) return null; // The three points are co-linear.
             final double b = y2/x2 - a;
-            x1 = (1 + b/(2*a))*x2 - y2/(2*a);
-            y1 = y0 + b*x1;
-            x1 += x0;
+            px = (1 + b/(2*a))*x2 - y2/(2*a);
+            py = y1 + b*px;
+            px += x1;
         } else {
             /*
              * Apply a rotation in such a way that (x2,y2)
@@ -323,15 +339,15 @@ public final class ShapeUtilities extend
             final double rx2 = x2;
             final double ry2 = y2;
             x2 = hypot(x2,y2);
-            y2 = (x1*rx2 + y1*ry2) / x2; // use 'y2' as a temporary variable for 'x1'
-            y1 = (y1*rx2 - x1*ry2) / x2;
-            x1 = y2;
+            y2 = (px*rx2 + py*ry2) / x2; // use 'y2' as a temporary variable for 'x1'
+            py = (py*rx2 - px*ry2) / x2;
+            px = y2;
             y2 = 0; // set as a matter of principle (but not used).
             /*
              * Now compute the control point coordinates in our new coordinate system axis.
              */
             final double x = 0.5;                       // Actually "x/x2"
-            final double y = (y1*x*x2) / (x1*(x2-x1));  // Actually "y/y2"
+            final double y = (py*x*x2) / (px*(x2-px));  // Actually "y/y2"
             final double check = abs(y);
             if (!(check <= 1/EPS)) return null; // Two points have the same coordinates.
             if (!(check >=   EPS)) return null; // The three points are co-linear.
@@ -339,10 +355,10 @@ public final class ShapeUtilities extend
              * Applies the inverse rotation then a translation to bring
              * us back to the original coordinate system.
              */
-            x1 = (x*rx2 - y*ry2) + x0;
-            y1 = (y*rx2 + x*ry2) + y0;
+            px = (x*rx2 - y*ry2) + x1;
+            py = (y*rx2 + x*ry2) + y1;
         }
-        return new Point2D.Double(x1,y1);
+        return new Point2D.Double(px,py);
     }
 
     /**
@@ -356,6 +372,10 @@ public final class ShapeUtilities extend
      * @param  x3 <var>x</var> value of the third  point.
      * @param  y3 <var>y</var> value of the third  point.
      * @return A circle passing by the given points.
+     *
+     * @todo This method is used by Geotk (a sandbox for code that may migrate to SIS), but
not yet by SIS.
+     *       We temporarily keep this code here, but may delete or move it elsewhere in a
future SIS version
+     *       depending whether we port to SIS the sandbox code.
      */
     public static Point2D.Double circleCentre(double x1, double y1,
                                               double x2, double y2,

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java?rev=1650566&r1=1650565&r2=1650566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java
[UTF-8] Fri Jan  9 15:32:31 2015
@@ -30,6 +30,7 @@ import static org.opengis.test.Assert.*;
 
 /**
  * Tests the {@link ShapeUtilities} class.
+ * Values in this test were determined empirically by running {@link ShapeUtilitiesViewer}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5 (derived from geotk-3.20)
@@ -40,7 +41,98 @@ public final strictfp class ShapeUtiliti
     /**
      * Tolerance factor for the tests in this class.
      */
-    private static final double EPS = 1E-8;
+    private static final double EPS = 1E-12;
+
+    /**
+     * Asserts that the given point is equals to the given value.
+     */
+    private static void assertPointEquals(final double x, final double y, final Point2D point)
{
+        assertEquals(x, point.getX(), EPS);
+        assertEquals(y, point.getY(), EPS);
+    }
+
+    /**
+     * Tests {@link ShapeUtilities#intersectionPoint(double, double, double, double, double,
double, double, double)}.
+     */
+    @Test
+    public void testIntersectionPoint() {
+        assertPointEquals(373.0459349536288,  153.4272907665677, ShapeUtilities.intersectionPoint(164,
261, 541,  67, 475, 214, 135,  12));
+        assertPointEquals(164.2967949656081,  147.2610859066296, ShapeUtilities.intersectionPoint(
 6, 259, 227, 103, 328, 254,  32,  61));
+        assertPointEquals(206.18415613599478, 276.5596260282143, ShapeUtilities.intersectionPoint(549,
309, 158, 272, 495, 138, 174, 292));
+
+        assertNull("Segments do not intersect.", ShapeUtilities.intersectionPoint( 52, 61,
419, 209, 419, 130, 529, 303));
+        assertNull("Segments do not intersect.", ShapeUtilities.intersectionPoint( 53, 62,
222, 221, 494, 158, 382, 174));
+        assertNull("Segments do not intersect.", ShapeUtilities.intersectionPoint(566, 296,
386, 305, 553, 51, 408, 291));
+    }
+
+    /**
+     * Tests {@link ShapeUtilities#nearestColinearPoint(double, double, double, double, double,
double)}.
+     */
+    @Test
+    public void testNearestColinearPoint() {
+        assertPointEquals(250.3762957286331,   41.53513088371716, ShapeUtilities.nearestColinearPoint(251,
 41,  82, 186, 334, 139));
+        assertPointEquals(339.88188039274024, 107.30764653376968, ShapeUtilities.nearestColinearPoint(318,
189, 363,  21, 167,  61));
+        assertPointEquals(120.45221035554958, 270.19778288495337, ShapeUtilities.nearestColinearPoint(100,
279, 574,  75, 135, 304));
+        assertPointEquals(141.0,              203.0,              ShapeUtilities.nearestColinearPoint(351,
 17, 141, 203,  55, 221));
+        assertPointEquals(333.6115520537628,  160.28938068478067, ShapeUtilities.nearestColinearPoint(289,
 25, 381, 304,  10, 267));
+    }
+
+    /**
+     * Tests {@link ShapeUtilities#colinearPoint(double, double, double, double, double,
double, double)}.
+     */
+    @Test
+    public void testColinearPoint() {
+        assertPointEquals(292.1838668370446,  278.764084678759,   ShapeUtilities.colinearPoint(214,
297, 587, 210, 104, 77, 275.902));
+        assertPointEquals(151.57330058770097, 162.19277228964654, ShapeUtilities.colinearPoint(187,
 93, 123, 218, 204, 16, 155.309));
+        assertPointEquals(568.6671514383643,  274.6199927862288,  ShapeUtilities.colinearPoint(232,
 84, 587, 285, 469, 31, 263.219));
+
+        assertNull("No point at the given distance.", ShapeUtilities.colinearPoint(415, 112,
21,  269, 223, 270, 341.434));
+        assertNull("No point at the given distance.", ShapeUtilities.colinearPoint(353, 235,
233, 104, 423,  81, 558.129));
+    }
+
+    /**
+     * Invokes {@code ShapeUtilities.fitParabol(x1, y1, px, py, x2, y2, horizontal)}, then
verifies that the control
+     * point of the returned curve is equals to {@code (cx, cy)}.
+     */
+    private static void assertParabolEquals(final double cx, final double cy,
+                                            final double x1, final double y1,
+                                            final double px, final double py,
+                                            final double x2, final double y2,
+                                            final boolean horizontal)
+    {
+        final QuadCurve2D p = ShapeUtilities.fitParabol(x1, y1, px, py, x2, y2, horizontal);
+        assertPointEquals(x1, y1, p.getP1());
+        assertPointEquals(x2, y2, p.getP2());
+        assertPointEquals(cx, cy, p.getCtrlPt());
+    }
+
+    /**
+     * Tests {@link ShapeUtilities#fitParabol(double, double, double, double, double, double,
boolean)}
+     * with a {@code false} boolean argument.
+     */
+    @Test
+    public void testFitParabol() {
+        assertParabolEquals(203.09937404322247, 298.52149034018106, 188,  25, 367, 282, 477,
294, false);
+        assertParabolEquals(440.2165208525737,  147.92614458270768, 342, 193, 503, 182, 537,
196, false);
+        assertParabolEquals(688.8232271997849,  117.2311838864974,  488, 241, 578, 134, 455,
 86, false);
+    }
+
+    /**
+     * Tests {@link ShapeUtilities#fitParabol(double, double, double, double, double, double,
boolean)}
+     * with a {@code true} boolean argument.
+     */
+    @Test
+    public void testFitHorizontalParabol() {
+        assertParabolEquals(327.0, 272.41465201465195, 538, 197, 473, 213, 116, 43, true);
+    }
+
+    /**
+     * Tests {@link ShapeUtilities#circleCentre(double, double, double, double, double, double)}.
+     */
+    @Test
+    public void testCircleCentre() {
+        assertPointEquals(117.40902595856156, 151.49785663253124, ShapeUtilities.circleCentre(182,
103, 50, 107, 124, 232));
+    }
 
     /**
      * Tests {@link ShapeUtilities#toPrimitive(Shape)}.

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java?rev=1650566&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
[UTF-8] Fri Jan  9 15:32:31 2015
@@ -0,0 +1,245 @@
+/*
+ * 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.j2d;
+
+import java.util.Locale;
+import java.util.Random;
+import java.io.Console;
+import java.io.PrintWriter;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Path2D;
+import java.awt.geom.Point2D;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import org.apache.sis.util.CharSequences;
+
+
+/**
+ * Visual tests of the {@link ShapeUtilities} class. This "test" is not executed by the Maven
build.
+ * It is rather designed for explicit execution from an IDE or the command line for visual
inspection.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+@SuppressWarnings("serial")
+final strictfp class ShapeUtilitiesViewer extends JPanel {
+    /**
+     * The {@link ShapeUtilities} methods to test.
+     */
+    private static enum Method {
+        INTERSECTION_POINT,
+        NEAREAST_COLINEAR_POINT,
+        COLINEAR_POINT,
+        FIT_PARABOL,
+        FIT_HORIZONTAL_PARABOL,
+        CIRCLE_CENTRE
+    };
+
+    /**
+     * Radius (in pixels) of points to drawn.
+     */
+    private static final int POINT_RADIUS = 4;
+
+    /**
+     * The visual representation of the arguments given to the tested method.
+     */
+    private final Path2D input;
+
+    /**
+     * The visual representation of the value returned by the tested method.
+     */
+    private final Path2D output;
+
+    /**
+     * {@code true} if we should fill the output, or {@code false} for drawing the contour
only.
+     */
+    private boolean fillOutput;
+
+    /**
+     * Random number generator to use in the visual test.
+     */
+    private final Random random;
+
+    /**
+     * Where to write the coordinate points.
+     */
+    private final PrintWriter out;
+
+    /**
+     * Creates a new panel where to paint the input and output values.
+     */
+    private ShapeUtilitiesViewer() {
+        setBackground(Color.BLACK);
+        input  = new Path2D.Float();
+        output = new Path2D.Float();
+        random = new Random();
+        final Console console = System.console();
+        out = (console != null) ? console.writer() : new PrintWriter(System.out);
+    }
+
+    /**
+     * Append the given point to the given path.
+     */
+    private static void addPoint(final Path2D addTo, final double x, final double y) {
+        addTo.append(new Ellipse2D.Double(x - POINT_RADIUS, y - POINT_RADIUS, 2*POINT_RADIUS,
2*POINT_RADIUS), false);
+    }
+
+    /**
+     * Append the given point to the given path.
+     */
+    private static void addPoint(final Path2D addTo, final Point2D point) {
+        if (point != null) {
+            addPoint(addTo, point.getX(), point.getY());
+        }
+    }
+
+    /**
+     * Assigns random values to the points.
+     */
+    @SuppressWarnings("fallthrough")
+    final void assignRandomPoints(final Method method) {
+        input .reset();
+        output.reset();
+        fillOutput = true;
+        boolean horizontal = false;
+        final int x      = getX();
+        final int y      = getY();
+        final int width  = getWidth();
+        final int height = getHeight();
+        final int x1 = x + random.nextInt(width);
+        final int y1 = y + random.nextInt(height);
+        final int x2 = x + random.nextInt(width);
+        final int y2 = y + random.nextInt(height);
+        final int x3 = x + random.nextInt(width);
+        final int y3 = y + random.nextInt(height);
+        final int x4 = x + random.nextInt(width);
+        final int y4 = y + random.nextInt(height);
+        switch (method) {
+            case INTERSECTION_POINT: {
+                input.moveTo(x1, y1);
+                input.lineTo(x2, y2);
+                input.moveTo(x3, y3);
+                input.lineTo(x4, y4);
+                addPoint(output, ShapeUtilities.intersectionPoint(x1, y1, x2, y2, x3, y3,
x4, y4));
+                out.printf(Locale.ENGLISH, "intersectionPoint(%d, %d, %d, %d, %d, %d, %d,
%d)%n", x1, y1, x2, y2, x3, y3, x4, y4);
+                break;
+            }
+            case NEAREAST_COLINEAR_POINT: {
+                input.moveTo(x1, y1);
+                input.lineTo(x2, y2);
+                addPoint(input, x3, y3);
+                addPoint(output, ShapeUtilities.nearestColinearPoint(x1, y1, x2, y2, x3,
y3));
+                out.printf(Locale.ENGLISH, "nearestColinearPoint(%d, %d, %d, %d, %d, %d)%n",
x1, y1, x2, y2, x3, y3);
+                break;
+            }
+            case COLINEAR_POINT: {
+                final double distance = Math.hypot(x4, y4);
+                input.moveTo(x1, y1);
+                input.lineTo(x2, y2);
+                addPoint(input, x3, y3);
+                addPoint(output, ShapeUtilities.colinearPoint(x1, y1, x2, y2, x3, y3, distance));
+                out.printf(Locale.ENGLISH, "colinearPoint(%d, %d, %d, %d, %d, %d, %g)%n",
x1, y1, x2, y2, x3, y3, distance);
+                break;
+            }
+            case FIT_HORIZONTAL_PARABOL: {
+                horizontal = true;
+                // Fall through
+            }
+            case FIT_PARABOL: {
+                addPoint(input, x1, y1);
+                addPoint(input, x2, y2);
+                addPoint(input, x3, y3);
+                output.append(ShapeUtilities.fitParabol(x1, y1, x2, y2, x3, y3, horizontal),
false);
+                out.printf(Locale.ENGLISH, "fitParabol(%d, %d, %d, %d, %d, %d, %b)%n", x1,
y1, x2, y2, x3, y3, horizontal);
+                fillOutput = false;
+                break;
+            }
+            case CIRCLE_CENTRE: {
+                addPoint(input, x1, y1);
+                addPoint(input, x2, y2);
+                addPoint(input, x3, y3);
+                addPoint(output, ShapeUtilities.circleCentre(x1, y1, x2, y2, x3, y3));
+                out.printf(Locale.ENGLISH, "circleCentre(%d, %d, %d, %d, %d, %d)%n", x1,
y1, x2, y2, x3, y3);
+                break;
+            }
+        }
+        out.flush();
+        repaint();
+    }
+
+    /**
+     * Paints the visual test.
+     *
+     * @param graphics Where to paint the test.
+     */
+    @Override
+    protected void paintComponent(final Graphics graphics) {
+        super.paintComponent(graphics);
+        final Graphics2D g = (Graphics2D) graphics;
+        if (fillOutput) {
+            g.setColor(Color.ORANGE);
+            g.fill(output);
+        }
+        g.setColor(Color.RED);
+        g.draw(output);
+        g.setColor(Color.CYAN);
+        g.fill(input);
+        g.setColor(Color.BLUE);
+        g.draw(input);
+    }
+
+    /**
+     * Creates a button for testing with new points.
+     */
+    private JButton createButtonForNextTest(final Method method) {
+        final JButton button = new JButton(CharSequences.camelCaseToSentence(
+                method.name().toLowerCase(Locale.ENGLISH)).toString());
+        button.addActionListener((ActionEvent e) -> {
+            assignRandomPoints(method);
+        });
+        return button;
+    }
+
+    /**
+     * Shows the viewer.
+     *
+     * @param args Ignored.
+     */
+    public static void main(final String[] args) {
+        final ShapeUtilitiesViewer viewer = new ShapeUtilitiesViewer();
+        final JPanel buttons = new JPanel(new GridLayout(2,3));
+        for (final Method method : Method.values()) {
+            buttons.add(viewer.createButtonForNextTest(method));
+        }
+        final JFrame frame = new JFrame("ShapeUtilities");
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setLayout(new BorderLayout());
+        frame.add(viewer, BorderLayout.CENTER);
+        frame.add(buttons, BorderLayout.SOUTH);
+        frame.setSize(600, 400);
+        frame.setVisible(true);
+    }
+}

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

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

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1650566&r1=1650565&r2=1650566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Fri Jan  9 15:32:31 2015
@@ -251,6 +251,11 @@ public final class Errors extends Indexe
         public static final short ExcessiveListSize_2 = 25;
 
         /**
+         * For this algorithm, {0} is an excessive number of dimensions.
+         */
+        public static final short ExcessiveNumberOfDimensions_1 = 177;
+
+        /**
          * The character string is too long.
          */
         public static final short ExcessiveStringSize = 153;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1650566&r1=1650565&r2=1650566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Fri Jan  9 15:32:31 2015
@@ -61,6 +61,7 @@ EmptyEnvelope2D                   = Enve
 EmptyProperty_1                   = Property named \u201c{0}\u201d shall not be empty.
 ExcessiveArgumentSize_3           = Argument \u2018{0}\u2019 shall not contain more than
{1} elements. A number of {2} is excessive.
 ExcessiveListSize_2               = A size of {1} elements is excessive for the \u201c{0}\u201d
list.
+ExcessiveNumberOfDimensions_1     = For this algorithm, {0} is an excessive number of dimensions.
 ExcessiveStringSize               = The character string is too long.
 FileNotFound_1                    = File \u201c{0}\u201d has not been found.
 ForbiddenAttribute_2              = Attribute \u201c{0}\u201d is not allowed for an object
of type \u2018{1}\u2019.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1650566&r1=1650565&r2=1650566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Fri Jan  9 15:32:31 2015
@@ -51,6 +51,7 @@ EmptyEnvelope2D                   = L\u2
 EmptyProperty_1                   = La propri\u00e9t\u00e9 nomm\u00e9e \u00ab\u202f{0}\u202f\u00bb
ne doit pas \u00eatre vide.
 ExcessiveArgumentSize_3           = L\u2019argument \u2018{0}\u2019 ne peut pas contenir
plus de {1} \u00e9l\u00e9ments. Un nombre de {2} est excessif.
 ExcessiveListSize_2               = Une taille de {1} \u00e9l\u00e9ments est excessive pour
la liste \u00ab\u202f{0}\u202f\u00bb.
+ExcessiveNumberOfDimensions_1     = Pour cet algorithme, {0} est un trop grand nombre de
dimensions.
 ExcessiveStringSize               = La cha\u00eene de caract\u00e8res est trop longue.
 FileNotFound_1                    = Le fichier \u00ab\u202f{0}\u202f\u00bb n\u2019a pas \u00e9t\u00e9
trouv\u00e9.
 ForbiddenAttribute_2              = L\u2019attribut \u00ab\u202f{0}\u202f\u00bb n\u2019est
pas autoris\u00e9 pour un objet de type \u2018{1}\u2019.



Mime
View raw message