Skip to content

Commit

Permalink
Longitude Compare at +180 degrees (#179)
Browse files Browse the repository at this point in the history
* Accurate longitude compare

* Class aware

* Final

* Add rectangle Test

* more tests
  • Loading branch information
jklamer authored and matthieun committed Aug 3, 2018
1 parent bf05984 commit 61447c0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/openstreetmap/atlas/utilities/scalars/Angle.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public int hashCode()
*/
public final boolean isGreaterThan(final Angle other)
{
if (other.getClass() == this.getClass())
{
return this.asDm7() > other.asDm7();
}
return this.getDm7() > other.getDm7();
}

Expand All @@ -222,6 +226,10 @@ public final boolean isGreaterThan(final Angle other)
*/
public final boolean isGreaterThanOrEqualTo(final Angle other)
{
if (other.getClass() == this.getClass())
{
return this.asDm7() >= other.asDm7();
}
return this.getDm7() >= other.getDm7();
}

Expand All @@ -234,6 +242,10 @@ public final boolean isGreaterThanOrEqualTo(final Angle other)
*/
public final boolean isLessThan(final Angle other)
{
if (other.getClass() == this.getClass())
{
return this.asDm7() < other.asDm7();
}
return this.getDm7() < other.getDm7();
}

Expand All @@ -246,6 +258,10 @@ public final boolean isLessThan(final Angle other)
*/
public final boolean isLessThanOrEqualTo(final Angle other)
{
if (other.getClass() == this.getClass())
{
return this.asDm7() <= other.asDm7();
}
return this.getDm7() <= other.getDm7();
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/openstreetmap/atlas/geography/LongitudeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ public void testCreation()
return;
}
}

@Test
public void testAssertCompareAntiMeridian()
{
final Longitude oneEighty = Longitude.degrees(180);
final Longitude minusOneEighty = Longitude.degrees(-180);
final Longitude ninety = Longitude.degrees(90);

Assert.assertTrue(oneEighty.isGreaterThan(minusOneEighty));
Assert.assertTrue(minusOneEighty.isLessThan(oneEighty));
Assert.assertFalse(minusOneEighty.isGreaterThanOrEqualTo(oneEighty));
Assert.assertTrue(oneEighty.isGreaterThanOrEqualTo(oneEighty));
Assert.assertTrue(oneEighty.isLessThanOrEqualTo(oneEighty));
Assert.assertTrue(oneEighty.isGreaterThan(ninety));
Assert.assertTrue(ninety.isLessThanOrEqualTo(oneEighty));
}
}
32 changes: 32 additions & 0 deletions src/test/java/org/openstreetmap/atlas/geography/RectangleTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.openstreetmap.atlas.geography;

import java.util.Arrays;

import org.junit.Assert;
import org.junit.Test;
import org.openstreetmap.atlas.utilities.scalars.Surface;
Expand Down Expand Up @@ -75,4 +77,34 @@ public void testSurface()
Assert.assertTrue(this.rectangle1.surface().add(this.rectangle2.surface())
.isLessThan(this.rectangle3.surface()));
}

@Test
public void testAntiMeridianEastRectangle()
{
final Location antiMeridian = new Location(Latitude.ZERO, Longitude.degrees(180));
final Location lowerLeftAntiMeridianRectangle = new Location(Latitude.degrees(-10),
Longitude.degrees(170));
final Location lowerLeftTestRectangle = new Location(Latitude.degrees(-10),
Longitude.degrees(150));
final Location upperRightTestRectangle1 = new Location(Latitude.ZERO,
Longitude.degrees(160));
final Location upperRightTestRectangle2 = new Location(Latitude.ZERO,
Longitude.degrees(175));

// List construction
final Rectangle antiMeridianRectangle1 = Rectangle
.forLocations(Arrays.asList(antiMeridian, lowerLeftAntiMeridianRectangle));
final Rectangle testRectangle1 = Rectangle
.forLocations(Arrays.asList(upperRightTestRectangle1, lowerLeftTestRectangle));
Assert.assertFalse(testRectangle1.overlaps(antiMeridianRectangle1));
Assert.assertFalse(antiMeridianRectangle1.overlaps(testRectangle1));

// Corners construction
final Rectangle antiMeridianRectangle2 = Rectangle
.forCorners(lowerLeftAntiMeridianRectangle, antiMeridian);
final Rectangle testRectangle2 = Rectangle.forCorners(lowerLeftTestRectangle,
upperRightTestRectangle2);
Assert.assertTrue(testRectangle2.overlaps(antiMeridianRectangle2));
Assert.assertTrue(antiMeridianRectangle2.overlaps(testRectangle2));
}
}

0 comments on commit 61447c0

Please sign in to comment.