Skip to content

Commit 03fd0d8

Browse files
[Mercator] Code review changes
1 parent 381dc12 commit 03fd0d8

3 files changed

Lines changed: 12 additions & 27 deletions

File tree

‎algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
package com.baeldung.algorithms.mercator;
1+
package com.mercator;
22

33
class EllipticalMercator extends Mercator {
44
@Override
55
double yAxisProjection(double input) {
6-
if (input > 89.5) {
7-
input = 89.5;
8-
}
9-
if (input < -89.5) {
10-
input = -89.5;
11-
}
12-
double temp = RADIUS_MINOR / RADIUS_MAJOR;
13-
double es = 1.0 - (temp * temp);
14-
double eccent = Math.sqrt(es);
15-
double phi = Math.toRadians(input);
16-
double sinphi = Math.sin(phi);
17-
double con = eccent * sinphi;
18-
double com = 0.5 * eccent;
19-
con = Math.pow(((1.0 - con)/(1.0+con)), com);
20-
double ts = Math.tan(0.5 * ((Math.PI*0.5) - phi))/con;
21-
double y = 0 - RADIUS_MAJOR * Math.log(ts);
22-
return y;
6+
7+
input = Math.min(Math.max(input, -89.5), 89.5);
8+
double earthDimensionalRateNormalized = 1.0 - Math.pow(RADIUS_MINOR / RADIUS_MAJOR, 2);
9+
10+
double inputOnEarthProj = Math.sqrt(earthDimensionalRateNormalized) * Math.sin( Math.toRadians(input));
11+
12+
inputOnEarthProj = Math.pow(((1.0 - inputOnEarthProj)/(1.0+inputOnEarthProj)), 0.5 * Math.sqrt(earthDimensionalRateNormalized));
13+
double inputOnEarthProjNormalized = Math.tan(0.5 * ((Math.PI*0.5) - Math.toRadians(input)))/inputOnEarthProj;
14+
return (-1) * RADIUS_MAJOR * Math.log(inputOnEarthProjNormalized);
2315
}
2416

2517
@Override

‎algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
package com.baeldung.algorithms.mercator;
1+
package com.mercator;
22

33
import org.junit.Test;
4-
import org.junit.runner.RunWith;
5-
import org.mockito.junit.MockitoJUnitRunner;
64

75
import static junit.framework.TestCase.assertEquals;
86

9-
@RunWith(MockitoJUnitRunner.class)
107
public class EllipticalMercatorUnitTest {
118

129
@Test

‎algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
package com.baeldung.algorithms.mercator;
1+
package com.mercator;
22

33
import org.junit.Test;
4-
import org.junit.runner.RunWith;
5-
import org.mockito.junit.MockitoJUnitRunner;
6-
74
import static junit.framework.TestCase.assertEquals;
85

9-
@RunWith(MockitoJUnitRunner.class)
106
public class SphericalMercatorUnitTest {
117

128
@Test

0 commit comments

Comments
 (0)