@Override public PolyLine convert(final String object) { final StringList split = StringList.split(object, PolyLine.SEPARATOR); final List<Location> locations = new ArrayList<>(); for (final String location : split) { locations.add(Location.forString(location)); } return new PolyLine(locations); } }
@Override public Polygon convert(final String object) { final StringList split = StringList.split(object, PolyLine.SEPARATOR); final List<Location> locations = new ArrayList<>(); for (final String location : split) { locations.add(Location.forString(location)); } return new Polygon(locations); }
@Test public void testAsGeoJsonGeometry() { final Polygon tennisCourt = new Polygon(Location.forString("47.6778433, -122.2012807"), Location.forString("47.6779773, -122.2008187"), Location.forString("47.6776721, -122.2006229"), Location.forString("47.6775366, -122.2010923"), Location.forString("47.6776969, -122.2011787"), Location.forString("47.6778433, -122.2012807")); final String geoJson = "{\"type\":\"Polygon\",\"coordinates\":[[[-122.2012807,47.6778433],[-122.2008187,47.6779773],[-122.2006229,47.6776721],[-122.2010923,47.6775366],[-122.2011787,47.6776969],[-122.2012807,47.6778433]]]}"; final JsonObject geometry = tennisCourt.asGeoJsonGeometry(); Assert.assertEquals(geoJson, geometry.toString()); } }
@Test public void testMultiPolygon() { final MultiPolygon shape = MultiPolygon.TEST_MULTI_POLYGON; final Location origin1 = Location.forString("37.328709, -122.032873"); final Location origin2 = Location.forString("37.324014, -122.046642"); Assert.assertEquals(Location.forString("37.3283544,-122.0322605"), origin1.snapTo(shape)); Assert.assertEquals(Location.forString("37.3249067,-122.0459561"), origin2.snapTo(shape)); }
private void parseNode(final PackedAtlasBuilder builder, final String line) { final StringList split = StringList.split(line, SEPARATOR); final long identifier = Long.parseLong(split.get(0)); final Location geometry = Location.forString(split.get(1)); final Map<String, String> tags = parseTags(split.get(2)); builder.addNode(identifier, geometry, tags); }
private void parsePoint(final PackedAtlasBuilder builder, final String line) { final StringList split = StringList.split(line, SEPARATOR); final long identifier = Long.parseLong(split.get(0)); final Location geometry = Location.forString(split.get(1)); final Map<String, String> tags = parseTags(split.get(2)); builder.addPoint(identifier, geometry, tags); }
@Test public void testAngleLocation() { final PolyLine polyLine = new PolyLine(this.quadrant); Assert.assertEquals(Location.forString("37.33531,-122.009566"), polyLine.maximumAngleLocation().get()); }
@Test public void testAreasNoIntersectingPolygon() { final Atlas atlas = this.rule.getNoIntersectionAtlas(); final Polygon triangle = new Polygon(Location.forString("47.6263, -122.209198"), Location.forString("47.628685, -122.209305"), Location.forString("47.628704, -122.211761")); Assert.assertEquals("There should be no intersecting area", 0, Iterables.size(atlas.areasIntersecting(triangle))); Assert.assertEquals("There should be no intersecting area", 0, Iterables.size(atlas.areasIntersecting(triangle.bounds()))); }
@Test public void testSelfIntersectsTouchLast() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 3 1, 3 2, 2 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsClosedLoop() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 2 2, 3 3, 3 1, 1 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,1"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsTouchMiddle() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 3 1, 3 2, 2 1, 1 2)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsTouchFirst() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(2 1, 3 2, 3 1, 1 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testFindingAnglesGreaterThanTarget() { final PolyLine polyLine = new PolyLine(this.quadrant); // Find all angles greater than or equal to 140 degrees. final List<Tuple<Angle, Location>> result = polyLine .anglesGreaterThanOrEqualTo(Angle.degrees(140)); Assert.assertEquals(1, result.size()); Assert.assertEquals(Tuple.createTuple(Angle.degrees(148.2126213), Location.forString("37.33531,-122.009566")), result.get(0)); }
@Test public void testOverlappingAtAntimeridian() { final Atlas subAtlas1 = this.setup.subAtlasOnAntimeridianEast(); final Atlas subAtlas2 = this.setup.subAtlasOnAntimeridianWest(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); final Router router = AStarRouter.dijkstra(multiAtlas, Distance.meters(40)); final Route route = router.route( Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_1_LOCATION), Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_4_LOCATION)); Assert.assertEquals(2, route.size()); }
@Test public void testFindingAnglesLessThanTarget() { final PolyLine polyLine = new PolyLine(this.quadrant); // Find all angles less than or equal to 30 degrees. final List<Tuple<Angle, Location>> result = polyLine .anglesLessThanOrEqualTo(Angle.degrees(30)); Assert.assertEquals(1, result.size()); Assert.assertEquals(Tuple.createTuple(Angle.degrees(28.3372516), Location.forString("37.332451,-122.028932")), result.get(0)); }
@Test public void testOverlappingNodes() { final Atlas subAtlas1 = this.setup.overlappingSubAtlas1(); final Atlas subAtlas2 = this.setup.overlappingSubAtlas2(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); final Router router = AStarRouter.dijkstra(multiAtlas, Distance.meters(40)); final Route route = router.route( Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_5_LOCATION), Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_8_LOCATION)); Assert.assertEquals(2, route.size()); }
@Test public void testOffset() { Assert.assertEquals(Location.TEST_3, this.quadrant.offsetFromStart(Ratio.MINIMUM)); Assert.assertEquals(Location.TEST_3, this.quadrant.offsetFromStart(Ratio.MAXIMUM)); Assert.assertEquals(Location.forString("37.3352356,-122.0096687"), this.quadrant.middle()); }
@Test public void testPolyLine() { final PolyLine shape = new PolyLine(Location.TEST_6, Location.TEST_1, Location.EIFFEL_TOWER); final Location origin = Location.TEST_2; Assert.assertEquals(Location.forString("37.3268107,-122.030562"), origin.snapTo(shape)); Assert.assertEquals(Location.TEST_6, shape.snapFrom(Location.TEST_3)); Assert.assertEquals(Location.EIFFEL_TOWER, shape.snapFrom(Location.COLOSSEUM)); }
@Test public void testSegment() { final Segment shape = new Segment(Location.TEST_6, Location.TEST_1); final Location origin = Location.TEST_2; Assert.assertEquals(Location.forString("37.3268107,-122.030562"), origin.snapTo(shape)); Assert.assertEquals(Location.TEST_6, shape.snapFrom(Location.TEST_3)); Assert.assertEquals(Location.TEST_1, shape.snapFrom(Location.EIFFEL_TOWER)); }