sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1813381 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/geometry/ test/java/org/apache/sis/geometry/
Date Thu, 26 Oct 2017 10:20:08 GMT
Author: desruisseaux
Date: Thu Oct 26 10:20:07 2017
New Revision: 1813381

URL: http://svn.apache.org/viewvc?rev=1813381&view=rev
Log:
Bug fix when computing intersection between an ordinary envelope and an envelope having [0
… -0]° longitude range.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java?rev=1813381&r1=1813380&r2=1813381&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] Thu Oct 26 10:20:07 2017
@@ -47,8 +47,9 @@ import static org.apache.sis.util.Argume
 import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
 import static org.apache.sis.util.StringBuilders.trimFractionalPart;
 import static org.apache.sis.math.MathFunctions.epsilonEqual;
-import static org.apache.sis.math.MathFunctions.isNegative;
 import static org.apache.sis.math.MathFunctions.isPositive;
+import static org.apache.sis.math.MathFunctions.isNegative;
+import static org.apache.sis.math.MathFunctions.isNegativeZero;
 
 
 /**
@@ -821,10 +822,12 @@ public abstract class AbstractEnvelope i
                     // Not the excluded case, go to next dimension.
                     continue;
                 }
-                // If this envelope does not span the anti-meridian but the given envelope
-                // does, we don't contain the given envelope except in the special case
-                // where the envelope spanning is equals or greater than the axis spanning
-                // (including the case where this envelope expands to infinities).
+                /*
+                 * If this envelope does not span the anti-meridian but the given envelope
does,
+                 * then this envelope does not contain the given envelope except in the special
+                 * case where the envelope spanning is equals or greater than the axis spanning
+                 * (including the case where this envelope expands to infinities).
+                 */
                 if ((lower0 == Double.NEGATIVE_INFINITY && upper0 == Double.POSITIVE_INFINITY)
||
                     (upper0 - lower0 >= getSpan(getAxis(getCoordinateReferenceSystem(),
i))))
                 {
@@ -848,6 +851,14 @@ public abstract class AbstractEnvelope i
                         continue;
                     }
                 }
+            } else if (isNegativeZero(upper0 - lower0)) {
+                /*      !upperCnd
+                 *  ────────┬────────
+                 *        ┌─┼────┐
+                 *        └─┼────┘
+                 *  ────────┴────────
+                 *      !lowerCnd */
+                continue;
             }
             return false;
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java?rev=1813381&r1=1813380&r2=1813381&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
[UTF-8] Thu Oct 26 10:20:07 2017
@@ -33,9 +33,10 @@ import org.apache.sis.util.Emptiable;
 import static java.lang.Double.NaN;
 import static java.lang.Double.isNaN;
 import static java.lang.Double.doubleToLongBits;
+import static org.apache.sis.math.MathFunctions.isSameSign;
 import static org.apache.sis.math.MathFunctions.isPositive;
 import static org.apache.sis.math.MathFunctions.isNegative;
-import static org.apache.sis.math.MathFunctions.isSameSign;
+import static org.apache.sis.math.MathFunctions.isNegativeZero;
 import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
 import static org.apache.sis.internal.referencing.Formulas.isPoleToPole;
 
@@ -769,13 +770,15 @@ public class Envelope2D extends Rectangl
                 if (!isNegativeUnsafe(span1) || isNegativeUnsafe(span0)) {
                     continue;
                 }
-                if (span0 >= AbstractEnvelope.getSpan(getAxis(getCoordinateReferenceSystem(),
i))) {
+                if (span0 >= AbstractEnvelope.getSpan(getAxis(crs, i))) {
                     continue;
                 }
             } else if (minCondition != maxCondition) {
                 if (isNegative(span0) && isPositive(span1)) {
                     continue;
                 }
+            } else if (isNegativeZero(span0)) {
+                continue;
             }
             return false;
         }
@@ -880,8 +883,13 @@ public class Envelope2D extends Rectangl
                 min1  = rect.getY();
                 span1 = (env != null) ? env.height : rect.getHeight();
             }
-            final double max0 = min0 + span0;
-            final double max1 = min1 + span1;
+            /*
+             * The purpose for (min != 0) test before addition is to preserve the sign of
zero.
+             * In the [0 … -0] range, the span is -0. But computing max = 0 + -0 result
in +0,
+             * while we need max = -0 in this case.
+             */
+            final double max0 = (min0 != 0) ? min0 + span0 : span0;
+            final double max1 = (min1 != 0) ? min1 + span1 : span1;
             double min = Math.max(min0, min1);
             double max = Math.min(max0, max1);
             /*
@@ -904,10 +912,10 @@ public class Envelope2D extends Rectangl
                 }
                 if (intersect == 0 || intersect == 3) {
                     final double csSpan = AbstractEnvelope.getSpan(getAxis(crs, i));
-                    if (span1 >= csSpan) {
+                    if (span1 >= csSpan || isNegativeZero(span1)) {
                         min = min0;
                         max = max0;
-                    } else if (span0 >= csSpan) {
+                    } else if (span0 >= csSpan || isNegativeZero(span0)) {
                         min = min1;
                         max = max1;
                     } else {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java?rev=1813381&r1=1813380&r2=1813381&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] Thu Oct 26 10:20:07 2017
@@ -37,8 +37,9 @@ import org.opengis.metadata.extent.Geogr
 import org.apache.sis.util.resources.Errors;
 
 import static org.apache.sis.util.ArgumentChecks.*;
-import static org.apache.sis.math.MathFunctions.isNegative;
 import static org.apache.sis.math.MathFunctions.isSameSign;
+import static org.apache.sis.math.MathFunctions.isNegative;
+import static org.apache.sis.math.MathFunctions.isNegativeZero;
 
 
 /**
@@ -112,7 +113,7 @@ import static org.apache.sis.math.MathFu
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Johann Sorel (Geomatys)
- * @version 0.5
+ * @version 0.8
  *
  * @see Envelope2D
  * @see org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox
@@ -808,10 +809,10 @@ public class GeneralEnvelope extends Arr
                          */
                         final double min, max;
                         final double csSpan = getSpan(getAxis(crs, i));
-                        if (span1 >= csSpan) {
+                        if (span1 >= csSpan || isNegativeZero(span1)) {
                             min = min0;
                             max = max0;
-                        } else if (span0 >= csSpan) {
+                        } else if (span0 >= csSpan || isNegativeZero(span0)) {
                             min = min1;
                             max = max1;
                         } else {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java?rev=1813381&r1=1813380&r2=1813381&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
[UTF-8] Thu Oct 26 10:20:07 2017
@@ -19,8 +19,8 @@ package org.apache.sis.geometry;
 import java.awt.geom.Rectangle2D;
 import org.opengis.geometry.Envelope;
 import org.opengis.geometry.DirectPosition;
-import org.opengis.referencing.crs.GeographicCRS;
-import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.referencing.crs.DefaultGeographicCRS;
+import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -36,7 +36,7 @@ import static org.apache.sis.test.Refere
  * Various implementations are used for each test.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.4
+ * @version 0.8
  * @since   0.3
  * @module
  */
@@ -51,7 +51,7 @@ public final strictfp class AbstractEnve
     /**
      * The coordinate reference system used for the tests.
      */
-    static final GeographicCRS WGS84 = CommonCRS.WGS84.normalizedGeographic();
+    static final DefaultGeographicCRS WGS84 = HardCodedCRS.WGS84;
 
     /**
      * Creates an envelope of the given type. The type shall be one of the

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java?rev=1813381&r1=1813380&r2=1813381&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
[UTF-8] Thu Oct 26 10:20:07 2017
@@ -39,7 +39,7 @@ import static org.apache.sis.geometry.Ab
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Johann Sorel (Geomatys)
- * @version 0.5
+ * @version 0.8
  * @since   0.3
  * @module
  */
@@ -97,7 +97,7 @@ public strictfp class GeneralEnvelopeTes
             final double xLower, final double ymin, final double xUpper, final double ymax)
     {
         final double xmin, xmax;
-        if (MathFunctions.isNegative(xUpper - xLower)) { // Check for anti-meridian spanning.
+        if (MathFunctions.isNegative(xUpper - xLower)) {                // Check for anti-meridian
spanning.
             xmin = -180;
             xmax = +180;
         } else {
@@ -131,25 +131,24 @@ public strictfp class GeneralEnvelopeTes
     private static void assertIntersectEquals(final GeneralEnvelope e1, final GeneralEnvelope
e2,
             final double xmin, final double ymin, final double xmax, final double ymax)
     {
-        final boolean isEmpty = !(((xmax - xmin) * (ymax - ymin)) != 0);        // Use !
for catching NaN.
         final Envelope2D r1 = new Envelope2D(e1);
         final Envelope2D r2 = new Envelope2D(e2);
         final Envelope2D ri = r1.createIntersection(r2);
-        assertEquals("isEmpty", isEmpty, r1.isEmpty());
+        assertFalse("isEmpty", r1.isEmpty());
         assertEnvelopeEquals(ri, xmin, ymin, xmax, ymax);
         assertEquals("Interchanged arguments.", ri, r2.createIntersection(r1));
 
         // Compares with GeneralEnvelope.
         final GeneralEnvelope ei = new GeneralEnvelope(e1);
         ei.intersect(e2);
-        assertEquals("isEmpty", isEmpty, e1.isEmpty());
+        assertFalse("isEmpty", e1.isEmpty());
         assertEnvelopeEquals(ei, xmin, ymin, xmax, ymax);
         assertTrue("Using GeneralEnvelope.", ei.equals(ri, STRICT, false));
 
         // Interchanges arguments.
         ei.setEnvelope(e2);
         ei.intersect(e1);
-        assertEquals("isEmpty", isEmpty, e1.isEmpty());
+        assertFalse("isEmpty", e1.isEmpty());
         assertEnvelopeEquals(ei, xmin, ymin, xmax, ymax);
         assertTrue("Using GeneralEnvelope.", ei.equals(ri, STRICT, false));
     }
@@ -233,7 +232,7 @@ public strictfp class GeneralEnvelopeTes
         //  └──────────┘
         e1.setEnvelope(20, -20,  80, 12);
         e2.setEnvelope(40, -10, 100, 30);
-        final double ymin=-10, ymax=12; // Will not change anymore
+        final double ymin=-10, ymax=12;                         // Will not change anymore
         assertIntersectEquals(e1, e2, 40, ymin, 80, ymax);
         //  ────┐  ┌────
         //  ──┐ │  │ ┌──
@@ -272,6 +271,20 @@ public strictfp class GeneralEnvelopeTes
         //  ─────┘     └─────
         e2.setRange(0, 10, 90);
         assertIntersectEquals(e1, e2, NaN, ymin, NaN, ymax);
+        //  ────────┬────────
+        //        ┌─┼────┐
+        //        └─┼────┘
+        //  ────────┴────────
+        e1.setRange(0, 0.0, -0.0);
+        e2.setRange(0, -10,   30);
+        assertIntersectEquals(e1, e2, -10, ymin, 30, ymax);
+        //  ┌───────────────┐
+        //  │               │
+        //  │               │
+        //  └───────────────┘
+        e1.setRange(0, 0.0, -0.0);
+        e2.setRange(0, 0.0, -0.0);
+        assertIntersectEquals(e1, e2, 0.0, ymin, -0.0, ymax);
 
         // Post-test verification, mostly for SubEnvelope.
         verifyInvariants(e1);



Mime
View raw message