From 03fd0d8f5385b42cbb41114048f9cd56c7956d1b Mon Sep 17 00:00:00 2001 From: Grigorios Dimopoulos Date: Wed, 31 Oct 2018 12:53:14 +0200 Subject: [PATCH] [Mercator] Code review changes --- .../mercator/EllipticalMercator.java | 28 +++++++------------ .../mercator/EllipticalMercatorUnitTest.java | 5 +--- .../mercator/SphericalMercatorUnitTest.java | 6 +--- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java index 8c3e4c554f..8f007dc00e 100644 --- a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java @@ -1,25 +1,17 @@ -package com.baeldung.algorithms.mercator; +package com.mercator; class EllipticalMercator extends Mercator { @Override double yAxisProjection(double input) { - if (input > 89.5) { - input = 89.5; - } - if (input < -89.5) { - input = -89.5; - } - double temp = RADIUS_MINOR / RADIUS_MAJOR; - double es = 1.0 - (temp * temp); - double eccent = Math.sqrt(es); - double phi = Math.toRadians(input); - double sinphi = Math.sin(phi); - double con = eccent * sinphi; - double com = 0.5 * eccent; - con = Math.pow(((1.0 - con)/(1.0+con)), com); - double ts = Math.tan(0.5 * ((Math.PI*0.5) - phi))/con; - double y = 0 - RADIUS_MAJOR * Math.log(ts); - return y; + + input = Math.min(Math.max(input, -89.5), 89.5); + double earthDimensionalRateNormalized = 1.0 - Math.pow(RADIUS_MINOR / RADIUS_MAJOR, 2); + + double inputOnEarthProj = Math.sqrt(earthDimensionalRateNormalized) * Math.sin( Math.toRadians(input)); + + inputOnEarthProj = Math.pow(((1.0 - inputOnEarthProj)/(1.0+inputOnEarthProj)), 0.5 * Math.sqrt(earthDimensionalRateNormalized)); + double inputOnEarthProjNormalized = Math.tan(0.5 * ((Math.PI*0.5) - Math.toRadians(input)))/inputOnEarthProj; + return (-1) * RADIUS_MAJOR * Math.log(inputOnEarthProjNormalized); } @Override diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java index 13618e80a7..535a6c2c99 100644 --- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java +++ b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java @@ -1,12 +1,9 @@ -package com.baeldung.algorithms.mercator; +package com.mercator; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; import static junit.framework.TestCase.assertEquals; -@RunWith(MockitoJUnitRunner.class) public class EllipticalMercatorUnitTest { @Test diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java index f1152441b8..3fe765f218 100644 --- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java +++ b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java @@ -1,12 +1,8 @@ -package com.baeldung.algorithms.mercator; +package com.mercator; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - import static junit.framework.TestCase.assertEquals; -@RunWith(MockitoJUnitRunner.class) public class SphericalMercatorUnitTest { @Test