/** * Square distance between 2 points. * * @param p1 first {@link Point} * @param p2 second Point * @return square of the distance between two input points */ private static double getSqDist(Point p1, Point p2) { double dx = p1.longitude() - p2.longitude(); double dy = p1.latitude() - p2.latitude(); return dx * dx + dy * dy; }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); } }
private static String formatCoordinates(List<Point> coordinates) { String[] coordinatesFormatted = new String[coordinates.size()]; int index = 0; for (Point point : coordinates) { coordinatesFormatted[index++] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude())); } return TextUtils.join(";", coordinatesFormatted); }
private static String formatCoordinates(List<Point> coordinates) { String[] coordinatesFormatted = new String[coordinates.size()]; int index = 0; for (Point point : coordinates) { coordinatesFormatted[index++] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude())); } return TextUtils.join(";", coordinatesFormatted); }
private static String formatCoordinates(List<Point> coordinates) { String[] coordinatesFormatted = new String[coordinates.size()]; int index = 0; for (Point point : coordinates) { coordinatesFormatted[index++] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(point.longitude()), TextUtils.formatCoordinate(point.latitude())); } return TextUtils.join(";", coordinatesFormatted); }
@Override public List<Double> unshiftPoint(Point shiftedPoint) { return Arrays.asList(shiftedPoint.longitude() - 3, shiftedPoint.latitude() - 5, shiftedPoint.altitude() - 8); }
@Test public void deserialize_sanity() throws Exception { String jsonString = "[100.0, 0.0]"; GsonBuilder gsonBuilder = new GsonBuilder() .registerTypeAdapter(Point.class, new PointDeserializer()); Point point = gsonBuilder.create().fromJson(jsonString, Point.class); assertEquals(100, point.longitude(), DELTA); assertEquals(0, point.latitude(), DELTA); }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_MULTIPOLYGON); MultiPolygon geo = MultiPolygon.fromJson(json); assertEquals(geo.type(), "MultiPolygon"); assertEquals(geo.coordinates().get(0).get(0).get(0).longitude(), 102.0, DELTA); assertEquals(geo.coordinates().get(0).get(0).get(0).latitude(), 2.0, DELTA); assertFalse(geo.coordinates().get(0).get(0).get(0).hasAltitude()); }
@Test public void longitude_doesReturnCorrectValue() throws Exception { Point point = Point.fromLngLat(1.0, 2.0, 5.0); assertEquals(1, point.longitude(), DELTA); }
@Test public void point_deserializeArray() throws Exception { String jsonString = "[100.0, 0.0, 200.0]"; GsonBuilder gsonBuilder = new GsonBuilder() .registerTypeAdapter(Point.class, new PointDeserializer()); Point point = gsonBuilder.create().fromJson(jsonString, Point.class); assertEquals(100, point.longitude(), DELTA); assertEquals(0, point.latitude(), DELTA); assertEquals(200, point.altitude(), DELTA); }
@Test public void fromJsonHoles() throws IOException { final String json = loadJsonFixture(SAMPLE_POLYGON_HOLES); Polygon geo = Polygon.fromJson(json); assertEquals("Polygon", geo.type()); assertEquals(100.0, geo.coordinates().get(0).get(0).longitude(), DELTA); assertEquals(0.0, geo.coordinates().get(0).get(0).latitude(), DELTA); assertEquals(2, geo.coordinates().size()); assertEquals(100.8, geo.coordinates().get(1).get(0).longitude(), DELTA); assertEquals(0.8, geo.coordinates().get(1).get(0).latitude(), DELTA); assertFalse(geo.coordinates().get(0).get(0).hasAltitude()); }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_POLYGON); Polygon geo = Polygon.fromJson(json); assertEquals("Polygon", geo.type()); assertEquals(100.0, geo.coordinates().get(0).get(0).longitude(), DELTA); assertEquals(0.0, geo.coordinates().get(0).get(0).latitude(), DELTA); assertFalse(geo.coordinates().get(0).get(0).hasAltitude()); }
@Test public void turfAlong_returnsZeroWhenRouteIsPoint() throws Exception { List<Point> coords = new ArrayList<>(); coords.add(Point.fromLngLat(1.0, 1.0)); LineString lineString = LineString.fromLngLats(coords); Point point = TurfMeasurement.along(lineString, 0, TurfConstants.UNIT_METERS); assertEquals(1.0, point.latitude(), DELTA); assertEquals(1.0, point.longitude(), DELTA); }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_MULTILINESTRING); MultiLineString geo = MultiLineString.fromJson(json); assertEquals("MultiLineString", geo.type()); assertEquals(geo.coordinates().get(0).get(0).longitude(), 100.0, DELTA); assertEquals(geo.coordinates().get(0).get(0).latitude(), 0.0, DELTA); assertFalse(geo.coordinates().get(0).get(0).hasAltitude()); }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_MULTIPOINT); MultiPoint geo = MultiPoint.fromJson(json); assertEquals(geo.type(), "MultiPoint"); assertEquals(geo.coordinates().get(0).longitude(), 100.0, DELTA); assertEquals(geo.coordinates().get(0).latitude(), 0.0, DELTA); assertEquals(geo.coordinates().get(1).longitude(), 101.0, DELTA); assertEquals(geo.coordinates().get(1).latitude(), 1.0, DELTA); assertFalse(geo.coordinates().get(0).hasAltitude()); assertEquals(Double.NaN, geo.coordinates().get(0).altitude(), DELTA); }
@Test public void testFromJson() { String stepIntersectionJsonString = "{\"out\": 0, \"entry\": [true], \"bearings\": [ 125 ], " + "\"location\": [ 13.426579, 52.508068 ] }"; StepIntersection stepIntersection = StepIntersection.fromJson(stepIntersectionJsonString); Point location = stepIntersection.location(); Assert.assertEquals(13.426579, location.longitude(), 0.0001); Assert.assertEquals(52.508068, location.latitude(), 0.0001); String jsonStr = stepIntersection.toJson(); compareJson(stepIntersectionJsonString, jsonStr); } }
@Test public void location_doesGetConvertedToGeoJsonPoint() throws Exception { DirectionsWaypoint waypoint = DirectionsWaypoint.builder() .rawLocation(new double[] {1.0, 2.0}) .build(); assertNotNull(waypoint.location()); assertEquals(1.0, waypoint.location().longitude(), DELTA); assertEquals(2.0, waypoint.location().latitude(), DELTA); }