Location { public static boolean locationsCrossAntimeridian(List<? extends Location> locations) { if (locations == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Location", "locationsCrossAntimeridian", "missingList")); } int len = locations.size(); if (len < 2) { return false; } double lon1 = normalizeLongitude(locations.get(0).longitude); double sig1 = Math.signum(lon1); for (int idx = 1; idx < len; idx++) { double lon2 = normalizeLongitude(locations.get(idx).longitude); double sig2 = Math.signum(lon2); if (sig1 != sig2) { double delta = Math.abs(lon1 - lon2); if (delta > 180 && delta < 360) { return true; } } lon1 = lon2; sig1 = sig2; } return false; } Location();  Location(double latitude, double longitude);  Location(Location location); static Location fromDegrees(double latitudeDegrees, double longitudeDegrees); static Location fromRadians(double latitudeRadians, double longitudeRadians); static Location fromTimeZone(TimeZone timeZone); static double normalizeLatitude(double degrees); static double normalizeLongitude(double degrees); static double clampLatitude(double degrees); static double clampLongitude(double degrees); static boolean locationsCrossAntimeridian(List<? extends Location> locations); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Location set(double latitude, double longitude); Location set(Location location); Location interpolateAlongPath(Location endLocation, @WorldWind.PathType int pathType, double amount,
                                         Location result); double greatCircleAzimuth(Location location); double greatCircleDistance(Location location); Location greatCircleLocation(double azimuthDegrees, double distanceRadians, Location result); double rhumbAzimuth(Location location); double rhumbDistance(Location location); Location rhumbLocation(double azimuthDegrees, double distanceRadians, Location result); double linearAzimuth(Location location); double linearDistance(Location location); Location linearLocation(double azimuthDegrees, double distanceRadians, Location result); public double latitude; public double longitude; }
@Test public void testLocationsCrossAntimeridian() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, 165d)); locations.add(new Location(0d, -165d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertTrue("expected to cross", isCrossed); }
@Test public void testLocationsCrossAntimeridian_Antipodal() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, -90d)); locations.add(new Location(0d, 90d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertFalse("antipodal", isCrossed); }
@Test public void testLocationsCrossAntimeridian_AlmostAntipodal_DoesCross() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, -90.0000001d)); locations.add(new Location(0d, 90d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertTrue("nearly antipodal", isCrossed); }
@Test public void testLocationsCrossAntimeridian_AlmostAntipodal_DoesNotCross() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, -89.9999999d)); locations.add(new Location(0d, 90d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertFalse("nearly antipodal", isCrossed); }
@Test public void testLocationsCrossAntimeridian_OnAntimeridian_SameSideWest() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(90d, -180d)); locations.add(new Location(-90d, -180d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertFalse("coincident with antimerdian, west side", isCrossed); }
@Test public void testLocationsCrossAntimeridian_OnAntimeridian_SameSideEast() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(90d, 180d)); locations.add(new Location(-90d, 180d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertFalse("coincident with antimerdian, east side", isCrossed); }
@Test public void testLocationsCrossAntimeridian_OnAntimeridian_OppositeSides() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, -180d)); locations.add(new Location(0d, 180d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertFalse("coincident with antimerdian, opposite sides", isCrossed); }
@Test public void testLocationsCrossAntimeridian_OutsideNormalRange() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, -181d)); locations.add(new Location(0d, 181d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertTrue("181(-179) to -181(179) expected to cross", isCrossed); }
@Test public void testLocationsCrossAntimeridian_OutsideNormalRangeWest() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, -179d)); locations.add(new Location(0d, -181d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertTrue("-179 to -181(179) expected to cross", isCrossed); }
@Test public void testLocationsCrossAntimeridian_OutsideNormalRangeEast() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, 179d)); locations.add(new Location(0d, 181d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertTrue("179 to 181(-179) expected to cross", isCrossed); }
@Test public void testLocationsCrossAntimeridian_NaN() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(Double.NaN, Double.NaN)); locations.add(new Location(0d, -165d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertFalse("NaN", isCrossed); }
@Test public void testLocationsCrossAntimeridian_OneLocation() throws Exception { List<Location> locations = new ArrayList<>(); locations.add(new Location(0d, 165d)); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertFalse("list of one location is not expected to cross", isCrossed); }
@Test public void testLocationsCrossAntimeridian_NoLocations() throws Exception { List<Location> locations = new ArrayList<>(); boolean isCrossed = Location.locationsCrossAntimeridian(locations); assertFalse("empty list of locations is not expected to cross", isCrossed); }
@Test(expected = IllegalArgumentException.class) public void testLocationsCrossAntimeridian_WithNull() throws Exception { PowerMockito.mockStatic(Logger.class); Location.locationsCrossAntimeridian(null); fail("Expected an IllegalArgumentException to be thrown."); }
@Test public void testLocationsCrossAntimeridian_EmptyList() throws Exception { PowerMockito.mockStatic(Logger.class); boolean isCrossed = Location.locationsCrossAntimeridian(new ArrayList<Location>()); assertFalse("empty list", isCrossed); }