sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1826273 - in /sis/branches/JDK8/core: sis-metadata/src/test/java/org/apache/sis/metadata/ sis-referencing/src/main/java/org/apache/sis/geometry/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/
Date Thu, 08 Mar 2018 20:31:24 GMT
Author: desruisseaux
Date: Thu Mar  8 20:31:23 2018
New Revision: 1826273

URL: http://svn.apache.org/viewvc?rev=1826273&view=rev
Log:
Avoid nested SpecializableTransform.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java?rev=1826273&r1=1826272&r2=1826273&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/NameMapTest.java
[UTF-8] Thu Mar  8 20:31:23 2018
@@ -117,7 +117,7 @@ public final strictfp class NameMapTest
         assertEquals("getAverageAirTemperature", name);
         assertSame  ("getAverageAirTemperature", name);
         /*
-         * Tests an other intern.
+         * Tests another intern.
          */
         map = MetadataStandard.ISO_19115.asNameMap(EnvironmentalRecord.class, SENTENCE, UML_IDENTIFIER);
         name = map.get("Average air temperature");

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=1826273&r1=1826272&r2=1826273&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 Mar  8 20:31:23 2018
@@ -701,7 +701,7 @@ public class GeneralEnvelope extends Arr
     }
 
     /**
-     * Sets this envelope to the intersection if this envelope with the specified one.
+     * Sets this envelope to the intersection of this envelope with the specified one.
      *
      * <div class="section">Pre-conditions</div>
      * This method assumes that the specified envelope uses the same CRS than this envelope.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java?rev=1826273&r1=1826272&r2=1826273&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java
[UTF-8] Thu Mar  8 20:31:23 2018
@@ -17,6 +17,8 @@
 package org.apache.sis.referencing.operation.transform;
 
 import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Objects;
 import java.io.Serializable;
@@ -36,7 +38,6 @@ import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Utilities;
-import org.apache.sis.util.ArraysExt;
 
 
 /**
@@ -261,31 +262,33 @@ class SpecializableTransform extends Abs
         this.global = global;
         final int sourceDim = global.getSourceDimensions();
         final int targetDim = global.getTargetDimensions();
-        int n = 0;
-        final SubArea[] areas = new SubArea[specializations.size()];
-next:   for (final Map.Entry<Envelope,MathTransform> e : specializations.entrySet())
{
-            final MathTransform tr = e.getValue();
+        final List<SubArea> areas = new ArrayList<>(specializations.size());
+        for (final Map.Entry<Envelope,MathTransform> entry : specializations.entrySet())
{
+            MathTransform tr = entry.getValue();
             ensureDimensionMatches(0, sourceDim, tr.getSourceDimensions());
             ensureDimensionMatches(1, targetDim, tr.getTargetDimensions());
-            final SubArea area = new SubArea(e.getKey(), tr);
-            if (area.getDimension() != sourceDim) {
-                throw new MismatchedDimensionException(Errors.format(Errors.Keys.MismatchedDimension_3,
-                            "envelope", sourceDim, area.getDimension()));
-            }
-            for (int i=0; i<n; i++) {
-                if (areas[i].addSpecialization(area)) {
-                    continue next;
-                }
-            }
-            for (int i=0; i<n; i++) {
-                if (area.intersects(areas[i])) {
-                    // Pending implementation of R-Tree in Apache SIS.
-                    throw new IllegalArgumentException("Current implementation does not accept
overlapping envelopes.");
+            SubArea[] inherited = null;
+            if (tr instanceof SpecializableTransform) {
+                inherited = ((SpecializableTransform) tr).domains;
+                tr = ((SpecializableTransform) tr).global;
+            }
+            final SubArea area = new SubArea(entry.getKey(), tr);
+            addSpecialization(area, areas, sourceDim);
+            /*
+             * At this point we are usually done for the current SubArea. But if the given
MathTransform
+             * is another SpecializableTransform, then instead of storing nested SpecializableTransforms
+             * we will store directly the specializations that it contains.  This will reduce
the amount
+             * of steps when transforming coordinates.
+             */
+            if (inherited != null) {
+                for (final SubArea other : inherited) {
+                    final SubArea e = new SubArea(other, other.transform);
+                    e.intersect(area);
+                    addSpecialization(e, areas, sourceDim);
                 }
             }
-            areas[n++] = area;
         }
-        domains = ArraysExt.resize(areas, n);
+        domains = areas.toArray(new SubArea[areas.size()]);
         SubArea.uniformize(domains);
     }
 
@@ -301,6 +304,35 @@ next:   for (final Map.Entry<Envelope,Ma
         }
     }
 
+    /**
+     * Verifies if the given {@code area} has the expected number of dimensions,
+     * then adds it to {@code domains} list (eventually as a child of an existing node).
+     *
+     * @param  area     the new sub-area to add.
+     * @param  domains  where to add the sub-area (not necessarily directly; maybe as a child
of an existing node).
+     * @param  dim      expected number of dimensions, for verification purpose.
+     */
+    private static void addSpecialization(final SubArea area, final List<SubArea> domains,
final int dim) {
+        if (!area.isEmpty()) {
+            if (area.getDimension() != dim) {
+                throw new MismatchedDimensionException(Errors.format(Errors.Keys.MismatchedDimension_3,
+                            "envelope", dim, area.getDimension()));
+            }
+            for (final SubArea previous : domains) {
+                if (previous.addSpecialization(area)) {
+                    return;
+                }
+            }
+            for (final SubArea previous : domains) {
+                if (area.intersects(previous)) {
+                    // Pending implementation of R-Tree in Apache SIS.
+                    throw new IllegalArgumentException("Current implementation does not accept
overlapping envelopes.");
+                }
+            }
+            domains.add(area);
+        }
+    }
+
     /**
      * Gets the dimension of input points.
      */



Mime
View raw message