You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2015/10/29 12:48:00 UTC
svn commit: r1711230 - in /sis/branches/JDK8/core/sis-referencing/src:
main/java/org/apache/sis/referencing/operation/projection/
main/java/org/apache/sis/referencing/operation/transform/
test/java/org/apache/sis/referencing/operation/transform/
Author: desruisseaux
Date: Thu Oct 29 11:48:00 2015
New Revision: 1711230
URL: http://svn.apache.org/viewvc?rev=1711230&view=rev
Log:
Documentation and added serialization test.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ConformalProjection.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/EllipsoidalToCartesianTransform.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransformTest.java
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ConformalProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ConformalProjection.java?rev=1711230&r1=1711229&r2=1711230&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ConformalProjection.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/ConformalProjection.java [UTF-8] Thu Oct 29 11:48:00 2015
@@ -117,7 +117,9 @@ abstract class ConformalProjection exten
* in which case the {@link #φ(double)} method will need to use an iterative method.
*
* <p><strong>Consider this field as final!</strong>
- * It is not final only for the purpose of {@link #readObject(ObjectInputStream)}.</p>
+ * It is not final only for the purpose of {@link #readObject(ObjectInputStream)}.
+ * This field is not serialized because its value may depend on the version of this
+ * {@code ConformalProjection} class.</p>
*/
private transient boolean useIterations;
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=1711230&r1=1711229&r2=1711230&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] Thu Oct 29 11:48:00 2015
@@ -203,6 +203,12 @@ public abstract class NormalizedProjecti
/**
* The inverse of this map projection.
+ *
+ * <div class="note"><b>Note:</b>
+ * creation of this object is not deferred to the first call to the {@link #inverse()} method because this
+ * object is lightweight and typically needed soon anyway (may be as soon as {@code ConcatenatedTransform}
+ * construction time). In addition this field is part of serialization form in order to preserve the
+ * references graph.</div>
*/
private final MathTransform2D inverse;
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java?rev=1711230&r1=1711229&r2=1711230&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java [UTF-8] Thu Oct 29 11:48:00 2015
@@ -17,6 +17,8 @@
package org.apache.sis.referencing.operation.transform;
import java.util.Arrays;
+import java.io.IOException;
+import java.io.ObjectInputStream;
import java.io.Serializable;
import javax.measure.unit.Unit;
import javax.measure.quantity.Length;
@@ -140,15 +142,31 @@ public class EllipsoidalToCartesianTrans
* (because of the work performed by the normalization matrices), we just drop <var>a</var>
* in the formulas - so this field can be written as just <var>b</var>.
*
- * <p>This value is related to the ε value used in EPSG guide by ε = ℯ²/b² (assuming a=1).</p>
+ * <p>This value is related to {@link #excentricitySquared} and to the ε value used in EPSG guide
+ * by (assuming a=1):</p>
+ * <ul>
+ * <li>ℯ² = 1 - b²</li>
+ * <li>ε = ℯ²/b²</li>
+ * </ul>
+ *
+ * <p><strong>Consider this field as final!</strong>
+ * It is not final only for the purpose of {@link #readObject(ObjectInputStream)}.
+ * This field is recomputed from {@link #excentricitySquared} on deserialization.</p>
+ */
+ private transient double b;
+
+ /**
+ * Whether calculation of φ should use an iterative method after the first φ approximation.
+ * The current implementation sets this field to {@code true} at construction time when the excentricity value
+ * is greater than or equals to {@link #EXCENTRICITY_THRESHOLD}, but this policy may change in any future SIS
+ * version (for example we do not take the <var>h</var> values in account yet).
+ *
+ * <p><strong>Consider this field as final!</strong>
+ * It is not final only for the purpose of {@link #readObject(ObjectInputStream)}.
+ * This field is not serialized because its value may depend on the version of this
+ * {@code EllipsoidalToCartesianTransform} class.</p>
*/
- private final double b;
-
- /**
- * {@code true} if the excentricity value is greater than or equals to {@link #EXCENTRICITY_THRESHOLD},
- * in which case the calculation of φ will need to use an iterative method.
- */
- private final boolean useIterations;
+ private transient boolean useIterations;
/**
* {@code true} if ellipsoidal coordinates include an ellipsoidal height (i.e. are 3-D).
@@ -167,7 +185,12 @@ public class EllipsoidalToCartesianTrans
/**
* The inverse of this transform.
- * Created at construction time because needed soon anyway.
+ *
+ * <div class="note"><b>Note:</b>
+ * creation of this object is not deferred to the first call to the {@link #inverse()} method because this
+ * object is lightweight and typically needed soon anyway (may be as soon as {@code ConcatenatedTransform}
+ * construction time). In addition this field is part of serialization form in order to preserve the
+ * references graph.</div>
*/
private final AbstractMathTransform inverse;
@@ -221,6 +244,15 @@ public class EllipsoidalToCartesianTrans
}
/**
+ * Restores transient fields after deserialization.
+ */
+ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ useIterations = (excentricitySquared >= EXCENTRICITY_THRESHOLD * EXCENTRICITY_THRESHOLD);
+ b = sqrt(1 - excentricitySquared);
+ }
+
+ /**
* Creates a transform from geographic to geocentric coordinates. This convenience method combines the
* {@code EllipsoidalToCartesianTransform} instance with the steps needed for converting degrees to radians and
* expressing the results in units of the given ellipsoid.
Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransformTest.java?rev=1711230&r1=1711229&r2=1711230&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransformTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransformTest.java [UTF-8] Thu Oct 29 11:48:00 2015
@@ -37,6 +37,8 @@ import org.apache.sis.test.DependsOnMeth
import org.apache.sis.test.DependsOn;
import org.junit.Test;
+import static org.apache.sis.test.Assert.*;
+
/**
* Tests {@link EllipsoidalToCartesianTransform}.
@@ -56,7 +58,7 @@ public final strictfp class EllipsoidalT
* This test uses the example given in EPSG guidance note #7.
* The point in WGS84 is 53°48'33.820"N, 02°07'46.380"E, 73.00 metres.
*
- * @throws TransformException should never happen.
+ * @throws TransformException if conversion of the sample point failed.
*/
@Test
public void testGeographicToGeocentric() throws TransformException {
@@ -75,7 +77,7 @@ public final strictfp class EllipsoidalT
* Tests conversion of a single point from geocentric to geographic coordinates.
* This method uses the same point than {@link #testGeographicToGeocentric()}.
*
- * @throws TransformException should never happen.
+ * @throws TransformException if conversion of the sample point failed.
*/
@Test
public void testGeocentricToGeographic() throws TransformException {
@@ -116,7 +118,7 @@ public final strictfp class EllipsoidalT
* for reaching the expected precision.
*
* @throws FactoryException if an error occurred while creating the transform.
- * @throws TransformException if a conversion failed.
+ * @throws TransformException if conversion of the sample point failed.
*/
@Test
public void testHighExcentricity() throws TransformException, FactoryException {
@@ -179,4 +181,27 @@ public final strictfp class EllipsoidalT
testDerivative(CommonCRS.WGS84.ellipsoid(), true);
testDerivative(CommonCRS.WGS84.ellipsoid(), false);
}
+
+ /**
+ * Tests serialization. This method performs the same test than {@link #testGeographicToGeocentric()}
+ * and {@link #testGeocentricToGeographic()}, but on the deserialized instance. This allow us to verify
+ * that transient fields have been correctly restored.
+ *
+ * @throws TransformException if conversion of the sample point failed.
+ */
+ @Test
+ @DependsOnMethod("testRandomPoints")
+ public void testSerialization() throws TransformException {
+ transform = EllipsoidalToCartesianTransform.createGeodeticConversion(CommonCRS.WGS84.ellipsoid(), true);
+ transform = assertSerializedEquals(transform);
+ /*
+ * Below is basically a copy-and-paste of testGeographicToGeocentric(), but
+ * with isInverseTransformSupported = true for testing inverse conversion.
+ */
+ final double delta = toRadians(100.0 / 60) / 1852;
+ derivativeDeltas = new double[] {delta, delta, 100};
+ tolerance = GeocentricTranslationTest.precision(2);
+ verifyTransform(GeocentricTranslationTest.samplePoint(1),
+ GeocentricTranslationTest.samplePoint(2));
+ }
}