sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Rename "fitCubicCurve" as "bezier" since the returned curve is not necessarily cubic. Also remove the method from public API because its API may change again based on experience.
Date Tue, 14 May 2019 07:58:48 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 776b64f  Rename "fitCubicCurve" as "bezier" since the returned curve is not necessarily
cubic. Also remove the method from public API because its API may change again based on experience.
776b64f is described below

commit 776b64f8147ab3897e9dd588d081fc695edb85c7
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue May 14 00:28:27 2019 +0200

    Rename "fitCubicCurve" as "bezier" since the returned curve is not necessarily cubic.
    Also remove the method from public API because its API may change again based on experience.
---
 .../java/org/apache/sis/geometry/Shapes2D.java     | 28 ----------------------
 .../internal/referencing/j2d/ShapeUtilities.java   | 20 +++++++++-------
 .../referencing/j2d/ShapeUtilitiesTest.java        | 10 ++++----
 .../referencing/j2d/ShapeUtilitiesViewer.java      |  6 ++---
 4 files changed, 20 insertions(+), 44 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/Shapes2D.java b/core/sis-referencing/src/main/java/org/apache/sis/geometry/Shapes2D.java
index 0f799de..d88b9da 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/Shapes2D.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/Shapes2D.java
@@ -17,7 +17,6 @@
 package org.apache.sis.geometry;
 
 import java.util.Set;
-import java.awt.Shape;
 import java.awt.geom.Point2D;
 import java.awt.geom.Line2D;
 import java.awt.geom.Ellipse2D;
@@ -151,33 +150,6 @@ public final class Shapes2D extends Static {
     }
 
     /**
-     * Returns a Bézier curve passing by the given points and with the given derivatives
at end points.
-     * The curve equation is:
-     *
-     * <blockquote>B(t) = (1-t)³⋅P₁ + 3(1-t)²t⋅C₁ + 3(1-t)t²⋅C₂ + t³⋅P₂</blockquote>
-     *
-     * where t ∈ [0…1], P₁ and P₂ are start and end point respectively (given in
argument to this method)
-     * and C₁ and C₂ are control points (computed by this method) generally not on the
curve.
-     * The P₁ argument give the point on the curve at <var>t</var>=0.
-     * The P<sub>m</sub> argument give the point on the curve at <var>t</var>=½.
-     * The P₂ argument give the point on the curve at <var>t</var>=1.
-     *
-     * @param  P1  the starting point (<var>t</var> = 0).
-     * @param  Pm  the mid-point (<var>t</var> = ½).
-     * @param  P2  the end point (<var>t</var> = 1).
-     * @param  α1  the derivative (∂y/∂x) at starting point.
-     * @param  α2  the derivative (∂y/∂x) at ending point.
-     * @param  εx  maximal distance on <var>x</var> axis between the cubic Bézier
curve and quadratic or linear simplifications.
-     * @param  εy  maximal distance on <var>y</var> axis between the cubic Bézier
curve and quadratic or linear simplifications.
-     * @return the Bézier curve passing by the 3 given points and having the given derivatives
at end points.
-     *
-     * @since 1.0
-     */
-    public static Shape fitCubicCurve(Point2D P1, Point2D Pm, Point2D P2, double α1, double
α2, double εx, double εy) {
-        return ShapeUtilities.fitCubicCurve(P1.getX(), P1.getY(), Pm.getX(), Pm.getY(), P2.getX(),
P2.getY(), α1, α2, εx, εy);
-    }
-
-    /**
      * Transforms a rectangular envelope using the given math transform.
      * The transformation is only approximated: the returned envelope may be bigger than
      * necessary, or smaller than required if the bounding box contains a pole.
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java
index 0a8a4d8..e0785fe 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ShapeUtilities.java
@@ -360,14 +360,18 @@ public final class ShapeUtilities extends Static {
 
     /**
      * Returns a Bézier curve passing by the given points and with the given derivatives
at end points.
-     * The curve equation is:
+     * The cubic curve equation is:
      *
      * <blockquote>B(t) = (1-t)³⋅P₁ + 3(1-t)²t⋅C₁ + 3(1-t)t²⋅C₂ + t³⋅P₂</blockquote>
      *
      * where t ∈ [0…1], P₁ and P₂ are end points of the curve and C₁ and C₂ are
control points generally not on the curve.
-     * The (x₁,y₁) arguments give the coordinates of point P₁ at <var>t</var>=0.
+     * If the full equation is required for representing the curve, then this method builds
a {@link CubicCurve2D}.
+     * If the same curve can be represented by a quadratic curve, then this method returns
a {@link QuadCurve2D}.
+     * If the curve is actually a straight line, then this method returns a {@link Line2D}.
+     *
+     * <p>The (x₁,y₁) arguments give the coordinates of point P₁ at <var>t</var>=0.
      * The (x<sub>m</sub>,y<sub>m</sub>) arguments give the coordinates
of the point at <var>t</var>=½.
-     * The (x₂,y₂) arguments give the coordinates of point P₂ at <var>t</var>=1.
+     * The (x₂,y₂) arguments give the coordinates of point P₂ at <var>t</var>=1.</p>
      *
      * @param  x1  <var>x</var> value of the starting point.
      * @param  y1  <var>y</var> value of the starting point.
@@ -385,11 +389,11 @@ public final class ShapeUtilities extends Static {
      *
      * @since 1.0
      */
-    public static Shape fitCubicCurve(final double x1, final double y1,
-                                            double xm,       double ym,
-                                      final double x2, final double y2,
-                                      final double α1, final double α2,
-                                      final double εx, final double εy)
+    public static Shape bezier(final double x1, final double y1,
+                                     double xm,       double ym,
+                               final double x2, final double y2,
+                               final double α1, final double α2,
+                               final double εx, final double εy)
     {
         /*
          * Equations in this method are simplified as if (x1,y1) coordinates are (0,0).
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java
index e949b49..21cf9ff 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesTest.java
@@ -142,7 +142,7 @@ public final strictfp class ShapeUtilitiesTest extends TestCase {
                                                final double x2,  final double y2,
                                                final double α1,  final double α2)
     {
-        final CubicCurve2D p = (CubicCurve2D) ShapeUtilities.fitCubicCurve(x1, y1, xm, ym,
x2, y2, α1, α2, 1, 1);
+        final CubicCurve2D p = (CubicCurve2D) ShapeUtilities.bezier(x1, y1, xm, ym, x2, y2,
α1, α2, 1, 1);
         assertPointEquals( x1,  y1, p.getP1());
         assertPointEquals( x2,  y2, p.getP2());
         assertPointEquals(cx1, cy1, p.getCtrlP1());
@@ -150,16 +150,16 @@ public final strictfp class ShapeUtilitiesTest extends TestCase {
     }
 
     /**
-     * Tests {@link ShapeUtilities#fitCubicCurve(double, double, double, double, double,
double, double, double, double, double)}.
+     * Tests {@link ShapeUtilities#bezier(double, double, double, double, double, double,
double, double, double, double)}.
      * This is an anti-regression test with values computed by {@link ShapeUtilitiesViewer}.
      */
     @Test
-    public void testFitCubicCurve() {
+    public void testBezier() {
         /*
          * Case when the curve can be simplified to a straight line.
          * This test uses a line starting from (100,200) with a slope of 1.3333…
          */
-        final Line2D c1 = (Line2D) ShapeUtilities.fitCubicCurve(
+        final Line2D c1 = (Line2D) ShapeUtilities.bezier(
                 100, 200,                           // Start point:  P1
                 175, 300,                           // Midle point:  Pm = P1 + (75,100)
                 250, 400,                           // End point:    P2 = Pm + (75,100)
@@ -183,7 +183,7 @@ public final strictfp class ShapeUtilitiesTest extends TestCase {
          *     C₁  =  ⅓P₁ + ⅔Q  = (300, 266.666…)
          *     C₂  =  ⅓P₂ + ⅔Q  = (450, 400.0)
          */
-        final QuadCurve2D c2 = (QuadCurve2D) ShapeUtilities.fitCubicCurve(
+        final QuadCurve2D c2 = (QuadCurve2D) ShapeUtilities.bezier(
                 100,   200,                         // Start point
                 362.5, 350,                         // Midway point
                 550,   600,                         // End point
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
index c11fd5d..c765c34 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
@@ -55,7 +55,7 @@ final strictfp class ShapeUtilitiesViewer extends JPanel {
         DISTANCED_COLINEAR_POINT,
         FIT_PARABOL,
         FIT_PARABOL_HORIZONTAL,
-        FIT_CUBIC_CURVE,
+        BEZIER,
         CIRCLE_CENTRE
     };
 
@@ -180,7 +180,7 @@ final strictfp class ShapeUtilitiesViewer extends JPanel {
                 fillOutput = false;
                 break;
             }
-            case FIT_CUBIC_CURVE: {
+            case BEZIER: {
                 addPoint(input, x1, y1);
                 addPoint(input, x2, y2);
                 addPoint(input, x3, y3);
@@ -189,7 +189,7 @@ final strictfp class ShapeUtilitiesViewer extends JPanel {
                 input.moveTo(x1, y1);
                 input.lineTo(x4, y4);
                 input.lineTo(x3, y3);
-                output.append(ShapeUtilities.fitCubicCurve(x1, y1, x2, y2, x3, y3, α1, α2,
1, 1), false);
+                output.append(ShapeUtilities.bezier(x1, y1, x2, y2, x3, y3, α1, α2, 1,
1), false);
                 out.printf(Locale.ENGLISH, "fitCubicCurve(%d, %d, %d, %d, %d, %d, %g, %g)%n",
x1, y1, x2, y2, x3, y3, α1, α2);
                 fillOutput = false;
                 fillInput = false;


Mime
View raw message