sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1804862 - in /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation: projection/ transform/
Date Sat, 12 Aug 2017 09:54:04 GMT
Author: desruisseaux
Date: Sat Aug 12 09:54:04 2017
New Revision: 1804862

URL: http://svn.apache.org/viewvc?rev=1804862&view=rev
Log:
Remove some optimization in map projections for which benchmarking has show that it made no
measurable difference.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConicConformal.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java?rev=1804862&r1=1804861&r2=1804862&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java
[UTF-8] Sat Aug 12 09:54:04 2017
@@ -228,23 +228,23 @@ public class CylindricalEqualArea extend
     }
 
     /**
-     * Converts a list of coordinate point ordinal values.
-     *
-     * <div class="note"><b>Note:</b>
-     * We override the super-class method only as an optimization in the special case where
the target coordinates
-     * are written at the same locations than the source coordinates. In such case, we can
take advantage of the
-     * fact that the λ values are not modified by the normalized Cylindrical Equal Area
projection.</div>
+     * Converts a list of coordinate points. This method performs the same calculation than
above
+     * {@link #transform(double[], int, double[], int, boolean)} method, but is overridden
for efficiency.
      *
      * @throws TransformException if a point can not be converted.
      */
     @Override
     public void transform(final double[] srcPts, int srcOff,
-                          final double[] dstPts, int dstOff, int numPts)
-            throws TransformException
+                          final double[] dstPts, int dstOff, int numPts) throws TransformException
     {
         if (srcPts != dstPts || srcOff != dstOff || getClass() != CylindricalEqualArea.class)
{
             super.transform(srcPts, srcOff, dstPts, dstOff, numPts);
         } else {
+            /*
+             * Override the super-class method only as an optimization in the special case
where the target coordinates
+             * are written at the same locations than the source coordinates. In such case,
we can take advantage of
+             * the fact that the λ values are not modified by the normalized Cylindrical
Equal Area projection.
+             */
             dstOff--;
             while (--numPts >= 0) {
                 final double φ = dstPts[dstOff += DIMENSION];           // Same as srcPts[srcOff
+ 1].
@@ -322,8 +322,8 @@ public class CylindricalEqualArea extend
          * {@inheritDoc}
          *
          * <div class="note"><b>Note:</b>
-         * This method must be overridden because the {@link Mercator} class overrides the
{@link NormalizedProjection}
-         * default implementation.</div>
+         * This method must be overridden because the {@link CylindricalEqualArea} class
+         * overrides the {@link NormalizedProjection} default implementation.</div>
          */
         @Override
         public void transform(final double[] srcPts, int srcOff,

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConicConformal.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConicConformal.java?rev=1804862&r1=1804861&r2=1804862&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConicConformal.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConicConformal.java
[UTF-8] Sat Aug 12 09:54:04 2017
@@ -21,7 +21,6 @@ import org.opengis.util.FactoryException
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransformFactory;
-import org.opengis.referencing.operation.TransformException;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.Matrix;
 import org.apache.sis.measure.Latitude;
@@ -446,36 +445,6 @@ public class LambertConicConformal exten
     }
 
     /**
-     * Converts a list of coordinate point ordinal values. This method is overridden as an
optimization only.
-     * It performs the exact same calculation than {@link #transform(double[], int, double[],
int, boolean)}.
-     *
-     * @throws TransformException if a point can not be converted.
-     */
-    @Override
-    public void transform(final double[] srcPts, int srcOff,
-                          final double[] dstPts, int dstOff, int numPts)
-            throws TransformException
-    {
-        if (srcPts == dstPts && srcOff < dstOff || getClass() != LambertConicConformal.class)
{
-            super.transform(srcPts, srcOff, dstPts, dstOff, numPts);
-        } else while (--numPts >= 0) {
-            final double θ    = srcPts[srcOff++];
-            final double φ    = srcPts[srcOff++];
-            final double absφ = abs(φ);
-            final double ρ;
-            if (absφ < PI/2) {
-                ρ = pow(expOfNorthing(φ, eccentricity*sin(φ)), n);
-            } else if (absφ < PI/2 + ANGULAR_TOLERANCE) {
-                ρ = (φ*n >= 0) ? POSITIVE_INFINITY : 0;
-            } else {
-                ρ = NaN;
-            }
-            dstPts[dstOff++] = ρ * sin(θ);
-            dstPts[dstOff++] = ρ * cos(θ);
-        }
-    }
-
-    /**
      * Converts the specified (<var>x</var>,<var>y</var>) coordinates
and stores the (θ,φ) result in {@code dstPts}.
      *
      * @throws ProjectionException if the point can not be converted.
@@ -496,24 +465,6 @@ public class LambertConicConformal exten
         dstPts[dstOff+1] = -φ(pow(hypot(x, y), 1/n));   // Equivalent to φ(pow(hypot(x,y),
-1/n)) but more accurate for n>0.
     }
 
-    /**
-     * Inverse converts an arbitrary amount of coordinates. This method is provided as an
optimization only.
-     * Formula shall be a copy of the formula used in {@link #inverseTransform(double[],
int, double[], int)}.
-     */
-    @Override
-    final void inverseTransform(final double[] srcPts, int srcOff,
-                                final double[] dstPts, int dstOff, int numPts) throws ProjectionException
-    {
-        if (getClass() != LambertConicConformal.class) {
-            super.inverseTransform(srcPts, srcOff, dstPts, dstOff, numPts);
-        } else while (--numPts >= 0) {
-            final double x = srcPts[srcOff++];
-            final double y = srcPts[srcOff++];
-            dstPts[dstOff++] = atan2(x, y);
-            dstPts[dstOff++] = -φ(pow(hypot(x, y), 1/n));
-        }
-    }
-
 
     /**
      * Provides the transform equations for the spherical case of the Lambert Conformal projection.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java?rev=1804862&r1=1804861&r2=1804862&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java
[UTF-8] Sat Aug 12 09:54:04 2017
@@ -373,12 +373,8 @@ public class Mercator extends ConformalP
     }
 
     /**
-     * Converts a list of coordinate point ordinal values.
-     *
-     * <div class="note"><b>Note:</b>
-     * We override the super-class method only as an optimization in the special case where
the target coordinates
-     * are written at the same locations than the source coordinates. In such case, we can
take advantage of the
-     * fact that the λ values are not modified by the normalized Mercator projection.</div>
+     * Converts a list of coordinate points. This method performs the same calculation than
above
+     * {@link #transform(double[], int, double[], int, boolean)} method, but is overridden
for efficiency.
      *
      * @throws TransformException if a point can not be converted.
      */
@@ -390,6 +386,11 @@ public class Mercator extends ConformalP
         if (srcPts != dstPts || srcOff != dstOff || getClass() != Mercator.class) {
             super.transform(srcPts, srcOff, dstPts, dstOff, numPts);
         } else {
+            /*
+             * Override the super-class method only as an optimization in the special case
where the target coordinates
+             * are written at the same locations than the source coordinates. In such case,
we can take advantage of
+             * the fact that the λ values are not modified by the normalized Mercator projection.
+             */
             dstOff--;
             while (--numPts >= 0) {
                 final double φ = dstPts[dstOff += DIMENSION];                   // Same
as srcPts[srcOff + 1].
@@ -429,26 +430,6 @@ public class Mercator extends ConformalP
         dstPts[dstOff+1] = φ(exp(-y));
     }
 
-    /**
-     * Inverse converts an arbitrary amount of coordinates. This method is provided as an
optimization only.
-     * Formula shall be a copy of the formula used in {@link #inverseTransform(double[],
int, double[], int)},
-     * except for the copy of {@code x} which can be skipped if the target array overwrites
the source array.
-     */
-    @Override
-    final void inverseTransform(final double[] srcPts, int srcOff,
-                                final double[] dstPts, int dstOff, int numPts) throws ProjectionException
-    {
-        if (srcPts != dstPts || srcOff != dstOff || getClass() != Mercator.class) {
-            super.inverseTransform(srcPts, srcOff, dstPts, dstOff, numPts);
-        } else {
-            dstOff--;
-            while (--numPts >= 0) {
-                dstOff += DIMENSION;
-                dstPts[dstOff] = φ(exp(-dstPts[dstOff]));
-            }
-        }
-    }
-
 
     /**
      * Provides the transform equations for the spherical case of the Mercator projection.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java?rev=1804862&r1=1804861&r2=1804862&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
[UTF-8] Sat Aug 12 09:54:04 2017
@@ -710,22 +710,6 @@ public abstract class NormalizedProjecti
             throws ProjectionException;
 
     /**
-     * Inverse converts an arbitrary amount of coordinates. This method is invoked only if
the conversions can be
-     * applied by a loop with indices in increasing order, without the need to copy an array
in a temporary buffer.
-     * The default implementation delegates to {@link #inverseTransform(double[], int, double[],
int)} in a loop,
-     * but subclasses can override.
-     */
-    void inverseTransform(final double[] srcPts, int srcOff,
-                          final double[] dstPts, int dstOff, int numPts) throws ProjectionException
-    {
-        while (--numPts >= 0) {
-            inverseTransform(srcPts, srcOff, dstPts, dstOff);
-            srcOff += DIMENSION;
-            dstOff += DIMENSION;
-        }
-    }
-
-    /**
      * Returns the inverse of this map projection.
      * Subclasses do not need to override this method, as they should override
      * {@link #inverseTransform(double[], int, double[], int) inverseTransform(…)} instead.
@@ -781,18 +765,19 @@ public abstract class NormalizedProjecti
         }
 
         /**
-         * Inverse transforms an arbitrary amount of coordinates. This method delegates to
the optimized
-         * {@link NormalizedProjection#inverseTransform(double[], int, double[], int, int)}
method if possible,
-         * or to the default implementation otherwise.
+         * Inverse transforms an arbitrary amount of coordinates. This method optimizes the
+         * case where conversions can be applied by a loop with indices in increasing order.
          */
         @Override
         public void transform(final double[] srcPts, int srcOff,
                               final double[] dstPts, int dstOff, int numPts) throws TransformException
         {
-            if (srcPts != dstPts || srcOff >= dstOff) {
-                inverseTransform(srcPts, srcOff, dstPts, dstOff, numPts);
-            } else {
+            if (srcPts == dstPts && srcOff < dstOff) {
                 super.transform(srcPts, srcOff, dstPts, dstOff, numPts);
+            } else while (--numPts >= 0) {
+                inverseTransform(srcPts, srcOff, dstPts, dstOff);
+                srcOff += DIMENSION;
+                dstOff += DIMENSION;
             }
         }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java?rev=1804862&r1=1804861&r2=1804862&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] Sat Aug 12 09:54:04 2017
@@ -357,8 +357,8 @@ public abstract class AbstractMathTransf
             throws TransformException;
 
     /**
-     * Transforms a list of coordinate point ordinal values. This method is provided for
efficiently
-     * transforming many points. The supplied array of ordinal values will contain packed
ordinal values.
+     * Transforms a list of coordinate points. This method is provided for efficiently transforming
many points.
+     * The supplied array of coordinate values will contain packed coordinate values.
      *
      * <div class="note"><b>Example:</b> if the source dimension is 3,
then the ordinates will be packed in this order:
      * (<var>x₀</var>,<var>y₀</var>,<var>z₀</var>,
@@ -477,7 +477,7 @@ public abstract class AbstractMathTransf
     }
 
     /**
-     * Transforms a list of coordinate point ordinal values. The default implementation delegates
+     * Transforms a list of coordinate points. The default implementation delegates
      * to {@link #transform(double[], int, double[], int, int)} using a temporary array of
doubles.
      *
      * <div class="note"><b>Implementation note:</b> see {@link IterationStrategy}
javadoc for a method skeleton.</div>
@@ -607,7 +607,7 @@ public abstract class AbstractMathTransf
     }
 
     /**
-     * Transforms a list of coordinate point ordinal values. The default implementation delegates
+     * Transforms a list of coordinate points. The default implementation delegates
      * to {@link #transform(double[], int, double[], int, int)} using a temporary array of
doubles.
      *
      * @param  srcPts  the array containing the source point coordinates.
@@ -670,7 +670,7 @@ public abstract class AbstractMathTransf
     }
 
     /**
-     * Transforms a list of coordinate point ordinal values. The default implementation delegates
+     * Transforms a list of coordinate points. The default implementation delegates
      * to {@link #transform(double[], int, double[], int, int)} using a temporary array of
doubles
      * if necessary.
      *



Mime
View raw message