sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/04: Remove (at least for now) roundIfAlmostInteger(AffineTransform) since it is not sure that the benefit is worth the risk.
Date Sun, 05 Apr 2020 20:31:58 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 84f904ed48dabd514a629d2f5e860d0402875ad1
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sun Apr 5 17:55:29 2020 +0200

    Remove (at least for now) roundIfAlmostInteger(AffineTransform) since it is not sure that
the benefit is worth the risk.
---
 .../java/org/apache/sis/image/ResamplingGrid.java  | 41 ----------------------
 .../org/apache/sis/image/ResamplingGridTest.java   | 22 ------------
 2 files changed, 63 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ResamplingGrid.java b/core/sis-feature/src/main/java/org/apache/sis/image/ResamplingGrid.java
index 399b5b0..cabe1c5 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ResamplingGrid.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ResamplingGrid.java
@@ -32,7 +32,6 @@ import org.apache.sis.util.resources.Errors;
 import org.apache.sis.io.wkt.Formatter;
 
 import static java.lang.Math.abs;
-import static java.lang.Math.rint;
 
 
 /**
@@ -80,17 +79,6 @@ final class ResamplingGrid extends AbstractMathTransform2D {
     static final double TOLERANCE = 0.125;
 
     /**
-     * A small tolerance factor for comparisons of floating point numbers. We use the smallest
-     * accuracy possible for the {@code float} type for integer numbers different than zero,
-     * as computed by:
-     *
-     * {@preformat java
-     *     Math.nextUp(1f) - 1f;
-     * }
-     */
-    static final double EPS = 1.1920929E-7;
-
-    /**
      * Number of tiles in this grid. A {@link ResamplingGrid} tile is a rectangular region
inside which
      * bilinear interpolations can be used with acceptable errors. {@link ResamplingGrid}
tiles are not
      * necessarily coincident with image tiles.
@@ -303,7 +291,6 @@ affine: if (depth.width == 0 && depth.height == 0) {
                                                            m01 / height, m11 / height,
                                                            p.getX(),     p.getY());
             tr.translate(-xcnt, -ycnt);
-            roundIfAlmostInteger(tr);
             /*
              * Since the affine transform that we built is a kind of average computed from
bounds center,
              * we need to compare with the four corners for making sure that its precision
is sufficient.
@@ -511,34 +498,6 @@ affine: if (depth.width == 0 && depth.height == 0) {
     }
 
     /**
-     * If scale and shear coefficients are close to integers, replaces their current values
by their rounded values.
-     * The scale and shear coefficients are handled in a "all or nothing" way; either all
of them or none are rounded.
-     * The translation terms are handled separately, provided that the scale and shear coefficients
have been rounded.
-     *
-     * @param  tr  the transform to round. Rounding will be applied in place.
-     */
-    static void roundIfAlmostInteger(final AffineTransform tr) {
-        double r;
-        final double m00, m01, m10, m11;
-        if (abs((m00 = rint(r=tr.getScaleX())) - r) <= EPS &&
-            abs((m01 = rint(r=tr.getShearX())) - r) <= EPS &&
-            abs((m11 = rint(r=tr.getScaleY())) - r) <= EPS &&
-            abs((m10 = rint(r=tr.getShearY())) - r) <= EPS)
-        {
-            /*
-             * At this point the scale and shear coefficients can been rounded to integers.
-             * Continue only if this rounding does not make the transform non-invertible.
-             */
-            if ((m00!=0 || m01!=0) && (m10!=0 || m11!=0)) {
-                double m02, m12;
-                if (abs((r = rint(m02=tr.getTranslateX())) - m02) <= EPS) m02=r;
-                if (abs((r = rint(m12=tr.getTranslateY())) - m12) <= EPS) m12=r;
-                tr.setTransform(m00, m10, m01, m11, m02, m12);
-            }
-        }
-    }
-
-    /**
      * Formats a pseudo-WKT representation of this transform for debugging purpose.
      */
     @Override
diff --git a/core/sis-feature/src/test/java/org/apache/sis/image/ResamplingGridTest.java b/core/sis-feature/src/test/java/org/apache/sis/image/ResamplingGridTest.java
index 0570eed..3577168 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/image/ResamplingGridTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/image/ResamplingGridTest.java
@@ -20,7 +20,6 @@ import java.util.Arrays;
 import java.util.Random;
 import java.awt.Dimension;
 import java.awt.Rectangle;
-import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import org.apache.sis.geometry.Shapes2D;
 import org.opengis.referencing.operation.MathTransform;
@@ -49,27 +48,6 @@ import static org.opengis.test.Assert.*;
  */
 public final strictfp class ResamplingGridTest extends TestCase {
     /**
-     * Tests the {@link ResamplingGrid#roundIfAlmostInteger(AffineTransform)} method.
-     */
-    @Test
-    public void testRoundIfAlmostInteger() {
-        final AffineTransform test = new AffineTransform(4, 0, 0, 4, -400, -1186);
-        final AffineTransform copy = new AffineTransform(test);
-        ResamplingGrid.roundIfAlmostInteger(test);
-        assertEquals("Translation terms were already integers, so the " +
-                "transform should not have been modified.", copy, test);
-
-        test.translate(ResamplingGrid.EPS/8, -ResamplingGrid.EPS/8);
-        ResamplingGrid.roundIfAlmostInteger(test);
-        assertEquals("Translation terms should have been rounded.", copy, test);
-
-        test.translate(ResamplingGrid.EPS*2, -ResamplingGrid.EPS*2);
-        ResamplingGrid.roundIfAlmostInteger(test);
-        assertFalse("Treshold was smaller than the translation, so the " +
-                "transform should not have been modified.", copy.equals(test));
-    }
-
-    /**
      * Tests {@link ResamplingGrid#create(MathTransform2D, MathTransform2D, Rectangle)} with
an affine transform.
      * The method should detect the affine case and return an equal transform (not necessarily
the same instance).
      *


Mime
View raw message