Author: desruisseaux
Date: Mon Mar 5 14:15:17 2018
New Revision: 1825899
URL: http://svn.apache.org/viewvc?rev=1825899&view=rev
Log:
Make AbstractMathTransform.Inverse inner class static for more serialization
stability and avoiding redundant fields.
https://issues.apache.org/jira/browse/SIS-410
Modified:
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/projection/ZonedGridSystem.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/package-info.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform1D.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform2D.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/SpecializableTransform.java
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=1825899&r1=1825898&r2=1825899&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] Mon Mar 5 14:15:17 2018
@@ -437,7 +437,7 @@ public abstract class NormalizedProjecti
context = initializer.context;
eccentricitySquared = initializer.eccentricitySquared.value;
eccentricity = sqrt(eccentricitySquared); //
DoubleDouble.sqrt() does not make any difference here.
- inverse = new Inverse();
+ inverse = new Inverse(this);
}
/**
@@ -450,7 +450,7 @@ public abstract class NormalizedProjecti
context = other.context;
eccentricity = other.eccentricity;
eccentricitySquared = other.eccentricitySquared;
- inverse = new Inverse();
+ inverse = new Inverse(this);
}
/**
@@ -725,20 +725,34 @@ public abstract class NormalizedProjecti
* Inverse of a normalized map projection.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
* @since 0.6
* @module
*/
- private final class Inverse extends AbstractMathTransform2D.Inverse {
+ private static final class Inverse extends AbstractMathTransform2D.Inverse
implements Serializable {
/**
* For cross-version compatibility.
*/
- private static final long serialVersionUID = -9138242780765956870L;
+ private static final long serialVersionUID = 6014176098150309651L;
+
+ /**
+ * The enclosing transform.
+ */
+ private final NormalizedProjection forward;
/**
* Default constructor.
*/
- Inverse() {
+ Inverse(final NormalizedProjection forward) {
+ this.forward = forward;
+ }
+
+ /**
+ * Returns the inverse of this math transform.
+ */
+ @Override
+ public MathTransform2D inverse() {
+ return forward;
}
/**
@@ -752,15 +766,15 @@ public abstract class NormalizedProjecti
final boolean derivate) throws
TransformException
{
if (!derivate) {
- inverseTransform(srcPts, srcOff, dstPts, dstOff);
+ forward.inverseTransform(srcPts, srcOff, dstPts, dstOff);
return null;
} else {
if (dstPts == null) {
dstPts = new double[DIMENSION];
dstOff = 0;
}
- inverseTransform(srcPts, srcOff, dstPts, dstOff);
- return
Matrices.inverse(NormalizedProjection.this.transform(dstPts, dstOff, null, 0,
true));
+ forward.inverseTransform(srcPts, srcOff, dstPts, dstOff);
+ return Matrices.inverse(forward.transform(dstPts, dstOff,
null, 0, true));
}
}
@@ -775,7 +789,7 @@ public abstract class NormalizedProjecti
if (srcPts == dstPts && srcOff < dstOff) {
super.transform(srcPts, srcOff, dstPts, dstOff, numPts);
} else while (--numPts >= 0) {
- inverseTransform(srcPts, srcOff, dstPts, dstOff);
+ forward.inverseTransform(srcPts, srcOff, dstPts, dstOff);
srcOff += DIMENSION;
dstOff += DIMENSION;
}
@@ -796,7 +810,7 @@ public abstract class NormalizedProjecti
* - false if applyOtherFirst == false since we have
(inverse projection) → (affine) → (projection).
* - true if applyOtherFirst == true since we have
(projection) → (affine) → (inverse projection).
*/
- return
NormalizedProjection.this.tryConcatenate(applyOtherFirst, m, factory);
+ return forward.tryConcatenate(applyOtherFirst, m, factory);
}
return super.tryConcatenate(applyOtherFirst, other, factory);
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ZonedGridSystem.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ZonedGridSystem.java?rev=1825899&r1=1825898&r2=1825899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ZonedGridSystem.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ZonedGridSystem.java
[UTF-8] Mon Mar 5 14:15:17 2018
@@ -131,7 +131,7 @@ public class ZonedGridSystem extends Abs
final MatrixSIS normalize =
initializer.context.getMatrix(ContextualParameters.MatrixRole.NORMALIZATION);
normalize.convertBefore(0, null, zoneWidth / -2);
projection = (AbstractMathTransform) new
TransverseMercator(initializer).createMapProjection(factory);
- inverse = new Inverse();
+ inverse = new Inverse(this);
}
@@ -185,15 +185,20 @@ public class ZonedGridSystem extends Abs
* Inverse of a zoned grid system.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
* @since 0.8
* @module
*/
- private final class Inverse extends AbstractMathTransform2D.Inverse {
+ private static final class Inverse extends AbstractMathTransform2D.Inverse
implements Serializable {
/**
* For cross-version compatibility.
*/
- private static final long serialVersionUID = 1900563285661407519L;
+ private static final long serialVersionUID = -4417726238412154175L;
+
+ /**
+ * The enclosing transform.
+ */
+ private final ZonedGridSystem forward;
/**
* The projection that performs the actual work after we removed the
zone number.
@@ -203,15 +208,24 @@ public class ZonedGridSystem extends Abs
/**
* Default constructor.
*/
- Inverse() throws FactoryException {
+ Inverse(final ZonedGridSystem forward) throws FactoryException {
+ this.forward = forward;
try {
- inverseProjection = (AbstractMathTransform)
projection.inverse();
+ inverseProjection = (AbstractMathTransform)
forward.projection.inverse();
} catch (NoninvertibleTransformException e) {
throw new FactoryException(e); // Should not
happen.
}
}
/**
+ * Returns the inverse of this math transform.
+ */
+ @Override
+ public MathTransform2D inverse() {
+ return forward;
+ }
+
+ /**
* Inverse transforms the specified {@code srcPts} and stores the
result in {@code dstPts}.
* If the derivative has been requested, then this method will
delegate the derivative
* calculation to the enclosing class and inverts the resulting matrix.
@@ -228,7 +242,7 @@ public class ZonedGridSystem extends Abs
dstPts[dstOff ] = x;
dstPts[dstOff+1] = y;
final Matrix derivative = inverseProjection.transform(dstPts,
dstOff, dstPts, dstOff, derivate);
- dstPts[dstOff] += zone * zoneWidth + initialLongitude;
+ dstPts[dstOff] += zone * forward.zoneWidth +
forward.initialLongitude;
return derivative;
}
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/package-info.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/package-info.java?rev=1825899&r1=1825898&r2=1825899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/package-info.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/package-info.java
[UTF-8] Mon Mar 5 14:15:17 2018
@@ -159,7 +159,7 @@
* @author Martin Desruisseaux (Geomatys)
* @author Rémi Maréchal (Geomatys)
* @author Adrian Custer (Geomatys)
- * @version 0.8
+ * @version 1.0
*
* @see <a href="http://www.remotesensing.org/geotiff/proj_list">Projections
list on RemoteSensing.org</a>
* @see <a href="http://mathworld.wolfram.com/MapProjection.html">Map
projections on MathWorld</a>
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=1825899&r1=1825898&r2=1825899&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] Mon Mar 5 14:15:17 2018
@@ -18,7 +18,6 @@ package org.apache.sis.referencing.opera
import java.util.List;
import java.util.Arrays;
-import java.io.Serializable;
import org.opengis.util.FactoryException;
import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.MismatchedDimensionException;
@@ -988,34 +987,20 @@ public abstract class AbstractMathTransf
/**
* Base class for implementations of inverse math transforms.
- * This inner class is the inverse of the enclosing {@link
AbstractMathTransform}.
+ * Subclasses need to implement the {@link #inverse()} method.
*
* <div class="section">Serialization</div>
- * Instances of this class are serializable only if the enclosing math
transform is also serializable.
- * Serialized math transforms are not guaranteed to be compatible with
future SIS versions.
- * Serialization, if allowed, should be used only for short term storage
or RMI between applications
+ * This object may or may not be serializable, at implementation choices.
+ * Most Apache SIS implementations are serializable, but the serialized
objects are not guaranteed to be compatible
+ * with future SIS versions. Serialization should be used only for short
term storage or RMI between applications
* running the same SIS version.
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 0.6
+ * @version 1.0
* @since 0.5
* @module
*/
- protected abstract class Inverse extends AbstractMathTransform implements
Serializable {
- /**
- * Serial number for inter-operability with different versions.
- *
- * Note: the default {@code serialVersionUID} computation does not
produce consistent results
- * across implementation of different Java compilers because different
compilers may generate
- * different names for synthetic members used in the implementation of
inner classes. Fixing
- * the serial number here avoid this issue, but may create new
problems since reading a class
- * serialized with an Apache SIS library compiled with a different
compiler may not recognize
- * the fields that are named differently. See:
- *
- * http://developer.java.sun.com/developer/bugParade/bugs/4211550.html
- */
- private static final long serialVersionUID = 3528274816628012283L;
-
+ protected abstract static class Inverse extends AbstractMathTransform {
/**
* Constructs an inverse math transform.
*/
@@ -1024,29 +1009,32 @@ public abstract class AbstractMathTransf
/**
* Gets the dimension of input points.
- * The implementation returns the dimension of output points of the
enclosing math transform.
+ * The default implementation returns the dimension of output points
+ * of the {@linkplain #inverse() inverse} math transform.
*
* @return {@inheritDoc}
*/
@Override
- public final int getSourceDimensions() {
- return AbstractMathTransform.this.getTargetDimensions();
+ public int getSourceDimensions() {
+ return inverse().getTargetDimensions();
}
/**
* Gets the dimension of output points.
- * The implementation returns the dimension of input points of the
enclosing math transform.
+ * The default implementation returns the dimension of input points
+ * of the {@linkplain #inverse() inverse} math transform.
*
* @return {@inheritDoc}
*/
@Override
- public final int getTargetDimensions() {
- return AbstractMathTransform.this.getSourceDimensions();
+ public int getTargetDimensions() {
+ return inverse().getSourceDimensions();
}
/**
* Gets the derivative of this transform at a point.
- * The default implementation computes the inverse of the matrix
returned by the enclosing math transform.
+ * The default implementation computes the inverse of the matrix
+ * returned by the {@linkplain #inverse() inverse} math transform.
*
* @return {@inheritDoc}
* @throws NullPointerException if the derivative depends on
coordinate and {@code point} is {@code null}.
@@ -1058,28 +1046,27 @@ public abstract class AbstractMathTransf
if (point != null) {
point = this.transform(point, null);
}
- return
Matrices.inverse(AbstractMathTransform.this.derivative(point));
+ return Matrices.inverse(inverse().derivative(point));
}
/**
- * Returns the inverse of this math transform, which is the enclosing
math transform.
+ * Returns the inverse of this math transform.
+ * The returned transform should be the enclosing math transform.
*
- * @return the enclosing math transform.
+ * @return the inverse of this transform.
*/
@Override
- public MathTransform inverse() {
- return AbstractMathTransform.this;
- }
+ public abstract MathTransform inverse();
/**
* Tests whether this transform does not move any points.
- * The default implementation delegates this tests to the enclosing
math transform.
+ * The default implementation delegates this tests to the {@linkplain
#inverse() inverse} math transform.
*
* @return {@inheritDoc}
*/
@Override
public boolean isIdentity() {
- return AbstractMathTransform.this.isIdentity();
+ return inverse().isIdentity();
}
/**
@@ -1089,13 +1076,13 @@ public abstract class AbstractMathTransf
*/
@Override
protected int computeHashCode() {
- return super.computeHashCode() +
31*AbstractMathTransform.this.hashCode();
+ return super.computeHashCode() + 31 * inverse().hashCode();
}
/**
* Compares the specified object with this inverse math transform for
equality.
- * The default implementation tests if {@code object} in an instance
of the same class
- * than {@code this}, and if so compares their enclosing {@code
AbstractMathTransform}.
+ * The default implementation tests if {@code object} in an instance
of the same class than {@code this},
+ * and if so compares their {@linkplain #inverse() inverse} {@code
MathTransform}.
*
* @return {@inheritDoc}
*/
@@ -1105,7 +1092,13 @@ public abstract class AbstractMathTransf
return true; //
Slight optimization
}
if (object != null && object.getClass() == getClass()) {
- return AbstractMathTransform.this.equals(((Inverse)
object).inverse(), mode);
+ final MathTransform other = ((Inverse) object).inverse();
+ final MathTransform inverse = inverse();
+ if (inverse instanceof LenientComparable) {
+ return ((LenientComparable) inverse).equals(other, mode);
+ } else {
+ return inverse.equals(other);
+ }
} else {
return false;
}
@@ -1121,7 +1114,12 @@ public abstract class AbstractMathTransf
if (parameters != null) {
return parameters.beforeFormat(transforms, index, inverse);
} else {
- return AbstractMathTransform.this.beforeFormat(transforms,
index, !inverse);
+ final MathTransform inv = inverse();
+ if (inv instanceof AbstractMathTransform) {
+ return ((AbstractMathTransform)
inv).beforeFormat(transforms, index, !inverse);
+ } else {
+ return index;
+ }
}
}
@@ -1146,7 +1144,7 @@ public abstract class AbstractMathTransf
return WKTKeywords.Param_MT;
} else {
formatter.newLine();
- formatter.append((FormattableObject)
AbstractMathTransform.this);
+ formatter.append((FormattableObject) inverse());
return WKTKeywords.Inverse_MT;
}
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform1D.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform1D.java?rev=1825899&r1=1825898&r2=1825899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform1D.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform1D.java
[UTF-8] Mon Mar 5 14:15:17 2018
@@ -156,22 +156,17 @@ public abstract class AbstractMathTransf
* This inner class is the inverse of the enclosing {@link
AbstractMathTransform1D}.
*
* <div class="section">Serialization</div>
- * Instances of this class are serializable only if the enclosing math
transform is also serializable.
- * Serialized math transforms are not guaranteed to be compatible with
future SIS versions.
- * Serialization, if allowed, should be used only for short term storage
or RMI between applications
+ * This object may or may not be serializable, at implementation choices.
+ * Most Apache SIS implementations are serializable, but the serialized
objects are not guaranteed to be compatible
+ * with future SIS versions. Serialization should be used only for short
term storage or RMI between applications
* running the same SIS version.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 1.0
* @since 0.7
* @module
*/
- protected abstract class Inverse extends AbstractMathTransform.Inverse
implements MathTransform1D {
- /**
- * Serial number for inter-operability with different versions.
- */
- private static final long serialVersionUID = 2018412413506158560L;
-
+ protected abstract static class Inverse extends
AbstractMathTransform.Inverse implements MathTransform1D {
/**
* Constructs an inverse math transform.
*/
@@ -179,12 +174,11 @@ public abstract class AbstractMathTransf
}
/**
- * Returns the enclosing math transform.
+ * Returns the inverse of this math transform.
+ * The returned transform should be the enclosing math transform.
*/
@Override
- public MathTransform1D inverse() {
- return (MathTransform1D) super.inverse();
- }
+ public abstract MathTransform1D inverse();
/**
* Transforms a single point in the given array and opportunistically
computes its derivative if requested.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java?rev=1825899&r1=1825898&r2=1825899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java
[UTF-8] Mon Mar 5 14:15:17 2018
@@ -319,22 +319,17 @@ public abstract class AbstractMathTransf
* This inner class is the inverse of the enclosing {@link
AbstractMathTransform2D}.
*
* <div class="section">Serialization</div>
- * Instances of this class are serializable only if the enclosing math
transform is also serializable.
- * Serialized math transforms are not guaranteed to be compatible with
future SIS versions.
- * Serialization, if allowed, should be used only for short term storage
or RMI between applications
+ * This object may or may not be serializable, at implementation choices.
+ * Most Apache SIS implementations are serializable, but the serialized
objects are not guaranteed to be compatible
+ * with future SIS versions. Serialization should be used only for short
term storage or RMI between applications
* running the same SIS version.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.5
+ * @version 1.0
* @since 0.5
* @module
*/
- protected abstract class Inverse extends AbstractMathTransform.Inverse
implements MathTransform2D {
- /**
- * Serial number for inter-operability with different versions.
- */
- private static final long serialVersionUID = 5751908928042026412L;
-
+ protected abstract static class Inverse extends
AbstractMathTransform.Inverse implements MathTransform2D {
/**
* Constructs an inverse math transform.
*/
@@ -342,12 +337,11 @@ public abstract class AbstractMathTransf
}
/**
- * Returns the enclosing math transform.
+ * Returns the inverse of this math transform.
+ * The returned transform should be the enclosing math transform.
*/
@Override
- public MathTransform2D inverse() {
- return (MathTransform2D) super.inverse();
- }
+ public abstract MathTransform2D inverse();
/**
* Transforms the specified {@code ptSrc} and stores the result in
{@code ptDst}.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java?rev=1825899&r1=1825898&r2=1825899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
[UTF-8] Mon Mar 5 14:15:17 2018
@@ -299,7 +299,7 @@ public class EllipsoidToCentricTransform
final MatrixSIS normalize =
context.getMatrix(ContextualParameters.MatrixRole.NORMALIZATION);
normalize.convertBefore(2, a, null); // Divide ellipsoidal
height by a.
}
- inverse = new Inverse();
+ inverse = new Inverse(this);
}
/**
@@ -779,20 +779,34 @@ next: while (--numPts >= 0) {
* to ellipsoidal coordinates (λ,φ) or (λ,φ,<var>h</var>).
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 0.7
+ * @version 1.0
* @since 0.7
* @module
*/
- private final class Inverse extends AbstractMathTransform.Inverse
implements Serializable {
+ private static final class Inverse extends AbstractMathTransform.Inverse
implements Serializable {
/**
* Serial number for inter-operability with different versions.
*/
- private static final long serialVersionUID = 6942084702259211803L;
+ private static final long serialVersionUID = 33004303758761821L;
+
+ /**
+ * The enclosing transform.
+ */
+ private final EllipsoidToCentricTransform forward;
/**
* Creates the inverse of the enclosing transform.
*/
- Inverse() {
+ Inverse(final EllipsoidToCentricTransform forward) {
+ this.forward = forward;
+ }
+
+ /**
+ * Returns the inverse of this math transform.
+ */
+ @Override
+ public MathTransform inverse() {
+ return forward;
}
/**
@@ -801,7 +815,7 @@ next: while (--numPts >= 0) {
*/
@Override
protected ContextualParameters getContextualParameters() {
- return context.inverse(GeocentricToGeographic.PARAMETERS);
+ return forward.context.inverse(GeocentricToGeographic.PARAMETERS);
}
/**
@@ -812,7 +826,7 @@ next: while (--numPts >= 0) {
@Override
public ParameterValueGroup getParameterValues() {
final ParameterValueGroup pg =
getParameterDescriptors().createValue();
-
pg.values().addAll(EllipsoidToCentricTransform.this.getParameterValues().values());
+ pg.values().addAll(forward.getParameterValues().values());
return pg;
}
@@ -830,7 +844,7 @@ next: while (--numPts >= 0) {
public ParameterDescriptorGroup getParameterDescriptors() {
return new
DefaultParameterDescriptorGroup(Collections.singletonMap(ParameterDescriptorGroup.NAME_KEY,
new ImmutableIdentifier(Citations.SIS,
Constants.SIS, "Centric to ellipsoid (radians domain)")),
-
EllipsoidToCentricTransform.this.getParameterDescriptors());
+ forward.getParameterDescriptors());
}
/**
@@ -860,14 +874,14 @@ next: while (--numPts >= 0) {
{
final double[] point;
final int offset;
- if (derivate && (dstPts == null || !withHeight)) {
+ if (derivate && (dstPts == null || !forward.withHeight)) {
point = new double[3];
offset = 0;
} else {
point = dstPts;
offset = dstOff;
}
- inverseTransform(srcPts, srcOff, point, offset, 1);
+ forward.inverseTransform(srcPts, srcOff, point, offset, 1);
if (!derivate) {
return null;
}
@@ -876,9 +890,9 @@ next: while (--numPts >= 0) {
dstPts[dstOff+1] = point[1];
}
// We need to keep h during matrix inversion because (λ,φ,h)
values are not independent.
- Matrix matrix = EllipsoidToCentricTransform.this.derivative(new
DirectPositionView.Double(point, offset, 3));
+ Matrix matrix = forward.derivative(new
DirectPositionView.Double(point, offset, 3));
matrix = Matrices.inverse(matrix);
- if (!withHeight) {
+ if (!forward.withHeight) {
matrix = MatrixSIS.castOrCopy(matrix).removeRows(2, 3); //
Drop height only after matrix inversion is done.
}
return matrix;
@@ -892,7 +906,7 @@ next: while (--numPts >= 0) {
public void transform(double[] srcPts, int srcOff, double[] dstPts,
int dstOff, int numPts)
throws TransformException
{
- inverseTransform(srcPts, srcOff, dstPts, dstOff, numPts);
+ forward.inverseTransform(srcPts, srcOff, dstPts, dstOff, numPts);
}
/**
@@ -918,7 +932,7 @@ next: while (--numPts >= 0) {
protected MathTransform tryConcatenate(final boolean applyOtherFirst,
final MathTransform other,
final MathTransformFactory factory) throws FactoryException
{
- if (!applyOtherFirst && withHeight && other instanceof
LinearTransform && other.getTargetDimensions() == 2) {
+ if (!applyOtherFirst && forward.withHeight && other instanceof
LinearTransform && other.getTargetDimensions() == 2) {
/*
* Found a 3×4 matrix after this transform. We can reduce to a
3×3 matrix only if no dimension
* use the column that we are about to drop (i.e. all
coefficients in that column are zero).
@@ -929,7 +943,7 @@ next: while (--numPts >= 0) {
matrix.getElement(2,2) == 0)
{
matrix = MatrixSIS.castOrCopy(matrix).removeColumns(2, 3);
- final MathTransform tr2D = create2D().inverse();
+ final MathTransform tr2D = forward.create2D().inverse();
if (factory != null) {
return factory.createConcatenatedTransform(tr2D,
factory.createAffineTransform(matrix));
} else {
@@ -951,7 +965,7 @@ next: while (--numPts >= 0) {
@Override
final int beforeFormat(final List<Object> transforms, int index, final
boolean inverse) {
index = super.beforeFormat(transforms, index, inverse);
- if (!withHeight) {
+ if (!forward.withHeight) {
transforms.add(++index, new Geographic3Dto2D.WKT(false));
}
return index;
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java?rev=1825899&r1=1825898&r2=1825899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
[UTF-8] Mon Mar 5 14:15:17 2018
@@ -18,6 +18,7 @@ package org.apache.sis.referencing.opera
import java.util.Arrays;
import java.util.Objects;
+import java.io.Serializable;
import javax.measure.Unit;
import javax.measure.Quantity;
import org.opengis.util.FactoryException;
@@ -382,7 +383,7 @@ public class InterpolatedTransform exten
* To overridden by the two-dimensional transform case.
*/
InterpolatedTransform.Inverse createInverse() {
- return new Inverse();
+ return new Inverse(this);
}
/**
@@ -416,15 +417,20 @@ public class InterpolatedTransform exten
*
* @author Rueben Schulz (UBC)
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 0.7
+ * @version 1.0
* @since 0.7
* @module
*/
- class Inverse extends AbstractMathTransform.Inverse {
+ static class Inverse extends AbstractMathTransform.Inverse implements
Serializable {
/**
* Serial number for inter-operability with different versions.
*/
- private static final long serialVersionUID = -6779719408779847014L;
+ private static final long serialVersionUID = 4335801994727826360L;
+
+ /**
+ * The enclosing transform.
+ */
+ private final InterpolatedTransform forward;
/**
* Difference allowed in iterative computations, in units of grid cell
size.
@@ -434,15 +440,24 @@ public class InterpolatedTransform exten
/**
* Creates an inverse transform.
*/
- Inverse() {
- tolerance = grid.getCellPrecision();
- if (!(tolerance > 0)) { // Use ! for catching NaN.
+ Inverse(final InterpolatedTransform forward) {
+ this.forward = forward;
+ tolerance = forward.grid.getCellPrecision();
+ if (!(tolerance > 0)) { // Use
! for catching NaN.
throw new IllegalArgumentException(Errors.format(
Errors.Keys.ValueNotGreaterThanZero_2,
"grid.cellPrecision", tolerance));
}
}
/**
+ * Returns the inverse of this math transform.
+ */
+ @Override
+ public MathTransform inverse() {
+ return forward;
+ }
+
+ /**
* Transforms a single coordinate in a list of ordinal values,
* and optionally returns the derivative at that location.
*
@@ -452,6 +467,7 @@ public class InterpolatedTransform exten
public final Matrix transform(final double[] srcPts, final int srcOff,
double[] dstPts, int dstOff,
final boolean derivate) throws
TransformException
{
+ final int dimension = forward.dimension;
if (dstPts == null) {
dstPts = new double[dimension];
dstOff = 0;
@@ -462,7 +478,7 @@ public class InterpolatedTransform exten
final double[] vector = new double[dimension];
int it = Formulas.MAXIMUM_ITERATIONS;
do {
- grid.interpolateInCell(xi, yi, vector);
+ forward.grid.interpolateInCell(xi, yi, vector);
final double ox = xi;
final double oy = yi;
xi = x - vector[0];
@@ -487,7 +503,7 @@ public class InterpolatedTransform exten
dstPts[dstOff ] = xi; // Shall not be done before
above loop.
dstPts[dstOff+1] = yi;
if (derivate) {
- return
Matrices.inverse(InterpolatedTransform.this.derivative(
+ return Matrices.inverse(forward.derivative(
new DirectPositionView.Double(dstPts, dstOff,
dimension)));
}
return null;
@@ -505,6 +521,7 @@ public class InterpolatedTransform exten
public final void transform(double[] srcPts, int srcOff, final
double[] dstPts, int dstOff, int numPts)
throws TransformException
{
+ final int dimension = forward.dimension;
int inc = dimension;
if (srcPts == dstPts) {
switch (IterationStrategy.suggest(srcOff, inc, dstOff, inc,
numPts)) {
@@ -531,7 +548,7 @@ nextPoint: while (--numPts >= 0) {
final double y = yi = srcPts[srcOff+1];
int it = Formulas.MAXIMUM_ITERATIONS;
do {
- grid.interpolateInCell(xi, yi, vector);
+ forward.grid.interpolateInCell(xi, yi, vector);
final double ox = xi;
final double oy = yi;
xi = x - vector[0];
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform2D.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform2D.java?rev=1825899&r1=1825898&r2=1825899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform2D.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform2D.java
[UTF-8] Mon Mar 5 14:15:17 2018
@@ -84,14 +84,14 @@ final class InterpolatedTransform2D exte
*/
@Override
InterpolatedTransform.Inverse createInverse() {
- return new Inverse();
+ return new Inverse(this);
}
/**
* The inverse of the enclosing {@link InterpolatedTransform2D}.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 1.0
* @since 0.7
* @module
*/
@@ -99,12 +99,13 @@ final class InterpolatedTransform2D exte
/**
* Serial number for inter-operability with different versions.
*/
- private static final long serialVersionUID = 5739665311481484972L;
+ private static final long serialVersionUID = 4802773675799229357L;
/**
* Constructs the inverse of an interpolated transform.
*/
- Inverse() {
+ Inverse(final InterpolatedTransform2D forward) {
+ super(forward);
}
/**
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java?rev=1825899&r1=1825898&r2=1825899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java
[UTF-8] Mon Mar 5 14:15:17 2018
@@ -97,7 +97,7 @@ final class LinearInterpolator1D extends
return;
}
}
- inverse = new Inverse();
+ inverse = new Inverse(this);
}
/**
@@ -303,16 +303,30 @@ final class LinearInterpolator1D extends
* a bilinear search for locating the lower and upper <var>x</var> values
as integers, then interpolates the
* <var>x</var> real value.
*/
- private final class Inverse extends AbstractMathTransform1D.Inverse
implements MathTransform1D {
+ private static final class Inverse extends AbstractMathTransform1D.Inverse
implements MathTransform1D, Serializable {
/**
* For cross-version compatibility.
*/
- private static final long serialVersionUID = 3179638888992528901L;
+ private static final long serialVersionUID = -5112948223332095009L;
+
+ /**
+ * The enclosing transform.
+ */
+ private final LinearInterpolator1D forward;
/**
* Creates a new inverse transform.
*/
- Inverse() {
+ Inverse(final LinearInterpolator1D forward) {
+ this.forward = forward;
+ }
+
+ /**
+ * Returns the inverse of this math transform.
+ */
+ @Override
+ public MathTransform1D inverse() {
+ return forward;
}
/**
@@ -326,7 +340,7 @@ final class LinearInterpolator1D extends
final boolean derivate) throws
TransformException
{
final double d, x, y = srcPts[srcOff];
- final double[] values = LinearInterpolator1D.this.values;
+ final double[] values = forward.values;
int i = Arrays.binarySearch(values, y);
if (i >= 0) {
x = i;
@@ -361,7 +375,7 @@ final class LinearInterpolator1D extends
*/
@Override
public double transform(final double y) {
- final double[] values = LinearInterpolator1D.this.values;
+ final double[] values = forward.values;
int i = Arrays.binarySearch(values, y);
if (i >= 0) {
return i;
@@ -390,7 +404,7 @@ final class LinearInterpolator1D extends
*/
@Override
public double derivative(final double y) {
- final double[] values = LinearInterpolator1D.this.values;
+ final double[] values = forward.values;
int i = Arrays.binarySearch(values, y);
if (i < 0) {
i = ~i;
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=1825899&r1=1825898&r2=1825899&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] Mon Mar 5 14:15:17 2018
@@ -562,7 +562,7 @@ next: for (final Map.Entry<Envelope,Ma
@Override
public final synchronized MathTransform inverse() throws
NoninvertibleTransformException {
if (inverse == null) {
- inverse = new Inverse(generic);
+ inverse = new Inverse(this);
}
return inverse;
}
@@ -570,7 +570,17 @@ next: for (final Map.Entry<Envelope,Ma
/**
* The inverse of {@link SpecializableTransform}.
*/
- private final class Inverse extends AbstractMathTransform.Inverse {
+ private static final class Inverse extends AbstractMathTransform.Inverse
implements Serializable {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = 1060617594604917167L;
+
+ /**
+ * The enclosing transform.
+ */
+ private final SpecializableTransform forward;
+
/**
* The inverse of {@link SpecializableTransform#generic}.
*/
@@ -579,21 +589,30 @@ next: for (final Map.Entry<Envelope,Ma
/**
* Creates the inverse of a specialized transform having the given
properties.
*/
- Inverse(final MathTransform generic) throws
NoninvertibleTransformException {
- this.generic = generic.inverse();
- for (final SubArea domain : domains) {
+ Inverse(final SpecializableTransform forward) throws
NoninvertibleTransformException {
+ this.forward = forward;
+ this.generic = forward.generic.inverse();
+ for (final SubArea domain : forward.domains) {
SubArea.createInverse(domain);
}
}
/**
+ * Returns the inverse of this math transform.
+ */
+ @Override
+ public MathTransform inverse() {
+ return forward;
+ }
+
+ /**
* Inverse transforms the specified {@code ptSrc} and stores the
result in {@code ptDst}.
*/
@Override
public final DirectPosition transform(final DirectPosition ptSrc,
DirectPosition ptDst) throws TransformException {
final double[] source = ptSrc.getCoordinate(); // Needs to be
first in case ptDst overwrites ptSrc.
ptDst = generic.transform(ptSrc, ptDst);
- final SubArea domain = SubArea.find(domains, ptDst);
+ final SubArea domain = SubArea.find(forward.domains, ptDst);
if (domain != null) {
ptDst = domain.inverse.transform(new
DirectPositionView.Double(source, 0, source.length), ptDst);
}
@@ -642,7 +661,7 @@ next: for (final Map.Entry<Envelope,Ma
derivative = derivate ? tr.derivative(new
DirectPositionView.Double(srcPts, srcOff, srcInc)) : null;
}
if (secondTry) break;
- final SubArea domain = SubArea.find(domains, new
DirectPositionView.Double(dstPts, dstOff, dstInc));
+ final SubArea domain = SubArea.find(forward.domains, new
DirectPositionView.Double(dstPts, dstOff, dstInc));
if (domain != null) {
tr = domain.inverse;
secondTry = true;
@@ -659,7 +678,7 @@ next: for (final Map.Entry<Envelope,Ma
private void transform(final TransformCall transform, final double[]
dstPts,
int srcOff, int dstOff, int srcInc, int dstInc, int numPts)
throws TransformException
{
- final SubArea[] domains = SpecializableTransform.this.domains;
+ final SubArea[] domains = forward.domains;
transform.apply(generic, srcOff, dstOff, numPts);
final DirectPositionView dst = new
DirectPositionView.Double(dstPts, dstOff, dstInc);
while (numPts > 0) {