This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 200602de57efe00097430b48532f0b47f97f2928 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Mon May 2 17:45:00 2022 +0200 Make the `qm(sinφ)` method always safe to the spherical case. The reason is because `Spherical` inner classes are not public. Consequently users creating their own map projection subclasses could have a non-working instance. --- .../operation/projection/AlbersEqualArea.java | 2 +- .../operation/projection/CylindricalEqualArea.java | 8 ++++---- .../operation/projection/EqualAreaProjection.java | 18 +++++------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/AlbersEqualArea.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/AlbersEqualArea.java index fcfd6f0866..c72a3df34d 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/AlbersEqualArea.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/AlbersEqualArea.java @@ -244,7 +244,7 @@ public class AlbersEqualArea extends EqualAreaProjection { final double cosθ = cos(θ); final double sinθ = sin(θ); final double sinφ = sin(φ); - final double ρ = sqrt(C - nm*qm_ellipsoid(sinφ)); + final double ρ = sqrt(C - nm*qm(sinφ)); if (dstPts != null) { dstPts[dstOff ] = ρ * sinθ; dstPts[dstOff+1] = ρ * cosθ; diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java index a7f808b015..8ecd0f4b67 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/CylindricalEqualArea.java @@ -246,8 +246,8 @@ public class CylindricalEqualArea extends EqualAreaProjection { final double φ = srcPts[srcOff+1]; final double sinφ = sin(φ); if (dstPts != null) { - dstPts[dstOff ] = srcPts[srcOff]; // Multiplication by k₀ will be applied by the denormalization matrix. - dstPts[dstOff+1] = qm_ellipsoid(sinφ); // Multiplication by (1-ℯ²)/(2k₀) will be applied by the denormalization matrix. + dstPts[dstOff ] = srcPts[srcOff]; // Multiplication by k₀ will be applied by the denormalization matrix. + dstPts[dstOff+1] = qm(sinφ); // Multiplication by (1-ℯ²)/(2k₀) will be applied by the denormalization matrix. } /* * End of map projection. Now compute the derivative, if requested. @@ -275,8 +275,8 @@ public class CylindricalEqualArea extends EqualAreaProjection { */ dstOff--; while (--numPts >= 0) { - final double φ = dstPts[dstOff += DIMENSION]; // Same as srcPts[srcOff + 1]. - dstPts[dstOff] = qm_ellipsoid(sin(φ)); // Part of Snyder equation (10-15) + final double φ = dstPts[dstOff += DIMENSION]; // Same as srcPts[srcOff + 1]. + dstPts[dstOff] = qm(sin(φ)); // Part of Snyder equation (10-15) } } } diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/EqualAreaProjection.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/EqualAreaProjection.java index 3abebb6a42..06691ef8c3 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/EqualAreaProjection.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/EqualAreaProjection.java @@ -170,28 +170,20 @@ abstract class EqualAreaProjection extends NormalizedProjection { * <li>q(0) = 0</li> * </ul> * + * <h4>Spherical case</h4> * In the spherical case, <var>q</var> = 2⋅sinφ. + * We pay the cost of checking for the spherical case in each method invocation because otherwise, + * users creating their own map projection subclasses could get a non-working implementation. * * @param sinφ the sine of the latitude <var>q</var> is calculated for. * @return <var>q</var> from Snyder equation (3-12). */ final double qm(final double sinφ) { /* - * Check for zero eccentricity is required because qm_ellipsoid(sinφ) would + * Check for zero eccentricity is required because `qm(sinφ)` would * simplify to sinφ + atanh(0) / 0 == sinφ + 0/0, thus producing NaN. */ - return isSpherical ? 2*sinφ : qm_ellipsoid(sinφ); - } - - /** - * Same as {@link #qm(double)} but without check about whether the map projection is a spherical case. - * It is caller responsibility to ensure that this method is not invoked in the spherical case, since - * this implementation does not work in such case. - * - * @param sinφ the sine of the latitude <var>q</var> is calculated for. - * @return <var>q</var> from Snyder equation (3-12). - */ - final double qm_ellipsoid(final double sinφ) { + if (isSpherical) return 2*sinφ; final double ℯsinφ = eccentricity * sinφ; return sinφ / (1 - ℯsinφ*ℯsinφ) + atanh(ℯsinφ) / eccentricity; }