Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
ppicazo committed Oct 30, 2024
1 parent 14f99ef commit b10cfd0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/smerty/jham/Angle.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public Angle() {
* angle in radians
*/
public Angle(final double radiansIn) {
this.radians = new BigDecimal(radiansIn);
if (Double.isNaN(radiansIn) || Double.isInfinite(radiansIn)) {
this.radians = null;
} else {
this.radians = new BigDecimal(radiansIn);
}
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/smerty/jham/Latitude.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public int hashCode() {
* @return latitude object
*/
public static Latitude fromDegrees(final double degrees) {
if (Double.isNaN(degrees) || Double.isInfinite(degrees)) {
return null;
}
Latitude latitude = new Latitude();
latitude.radians = Angle.degreesToRadians(new BigDecimal(degrees),
MathContext.DECIMAL128);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/smerty/jham/Longitude.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ public int hashCode() {
* @return longitude object
*/
public static Longitude fromDegrees(final double degrees) {
if (Double.isNaN(degrees) || Double.isInfinite(degrees)) {
return null;
}
Longitude longitude = new Longitude();
longitude.radians = Angle.degreesToRadians(new BigDecimal(degrees),
MathContext.DECIMAL128);
return longitude;
}


}
6 changes: 3 additions & 3 deletions src/test/java/org/smerty/jham/AngleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public void testEqualsHashCode() {
@Test
public void testInvalidInputs() {
Angle angleNaN = new Angle(Double.NaN);
assertTrue(Double.isNaN(angleNaN.getRadians()));
assertTrue(angleNaN == null);

Angle anglePosInf = new Angle(Double.POSITIVE_INFINITY);
assertTrue(Double.isInfinite(anglePosInf.getRadians()));
assertTrue(anglePosInf == null);

Angle angleNegInf = new Angle(Double.NEGATIVE_INFINITY);
assertTrue(Double.isInfinite(angleNegInf.getRadians()));
assertTrue(angleNegInf == null);
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/smerty/jham/LatitudeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public void testEquals() {
@Test
public void testInvalidInputs() {
Latitude latNaN = Latitude.fromDegrees(Double.NaN);
assertTrue(Double.isNaN(latNaN.toDegrees()));
assertTrue(latNaN == null);

Latitude latPosInf = Latitude.fromDegrees(Double.POSITIVE_INFINITY);
assertTrue(Double.isInfinite(latPosInf.toDegrees()));
assertTrue(latPosInf == null);

Latitude latNegInf = Latitude.fromDegrees(Double.NEGATIVE_INFINITY);
assertTrue(Double.isInfinite(latNegInf.toDegrees()));
assertTrue(latNegInf == null);
}

@Test
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/smerty/jham/LocationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,24 @@ public void testEquals() {
public void testInvalidInputs() {
try {
Location locNaN = new Location(Double.NaN, Double.NaN);
assertTrue(Double.isNaN(locNaN.getLatitude().toDegrees()));
assertTrue(Double.isNaN(locNaN.getLongitude().toDegrees()));
assertTrue(locNaN.getLatitude() == null);
assertTrue(locNaN.getLongitude() == null);
} catch (Exception e) {
assertTrue(false);
}

try {
Location locPosInf = new Location(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
assertTrue(Double.isInfinite(locPosInf.getLatitude().toDegrees()));
assertTrue(Double.isInfinite(locPosInf.getLongitude().toDegrees()));
assertTrue(locPosInf.getLatitude() == null);
assertTrue(locPosInf.getLongitude() == null);
} catch (Exception e) {
assertTrue(false);
}

try {
Location locNegInf = new Location(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
assertTrue(Double.isInfinite(locNegInf.getLatitude().toDegrees()));
assertTrue(Double.isInfinite(locNegInf.getLongitude().toDegrees()));
assertTrue(locNegInf.getLatitude() == null);
assertTrue(locNegInf.getLongitude() == null);
} catch (Exception e) {
assertTrue(false);
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/smerty/jham/LongitudeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public void testEquals() {
@Test
public void testInvalidInputs() {
Longitude lonNaN = Longitude.fromDegrees(Double.NaN);
assertTrue(Double.isNaN(lonNaN.toDegrees()));
assertTrue(lonNaN == null);

Longitude lonPosInf = Longitude.fromDegrees(Double.POSITIVE_INFINITY);
assertTrue(Double.isInfinite(lonPosInf.toDegrees()));
assertTrue(lonPosInf == null);

Longitude lonNegInf = Longitude.fromDegrees(Double.NEGATIVE_INFINITY);
assertTrue(Double.isInfinite(lonNegInf.toDegrees()));
assertTrue(lonNegInf == null);
}

@Test
Expand Down

0 comments on commit b10cfd0

Please sign in to comment.