@Override public Location center() { return new Segment(this.lowerLeft, this.upperRight).middle(); }
private static Segment candidateSegment(final List<PolyLine> candidates, final int polyLineIndex, final int segmentIndex) { return new Segment(candidates.get(polyLineIndex).get(segmentIndex), segmentIndex < candidates.get(polyLineIndex).size() - 1 ? candidates.get(polyLineIndex).get(segmentIndex + 1) : candidates.get(polyLineIndex).first()); }
@Override public Segment reversed() { return new Segment(end(), start()); }
@Override public List<Segment> segments() { final List<Segment> result = super.segments(); // close the loop result.add(new Segment(last(), first())); return result; }
@Test public void testIntersection() { Assert.assertEquals(null, new Segment(Location.TEST_1, Location.TEST_2) .intersection(new Segment(Location.TEST_4, Location.TEST_3))); Assert.assertEquals(false, new Segment(Location.TEST_1, Location.TEST_2) .intersects(new Segment(Location.TEST_4, Location.TEST_3))); Assert.assertEquals( new Location(Latitude.degrees(37.3273389), Longitude.degrees(-122.0287109)), new Segment(Location.TEST_1, Location.TEST_3) .intersection(new Segment(Location.TEST_4, Location.TEST_2))); Assert.assertEquals(true, new Segment(Location.TEST_1, Location.TEST_3) .intersects(new Segment(Location.TEST_4, Location.TEST_2))); } }
public Segment segmentForIndex(final int index) { if (index >= size()) { throw new CoreException("Invalid index"); } return new Segment(this.get(index), index == size() - 1 ? this.get(0) : this.get(index + 1)); }
@Test public void testIntegrity() { final AtlasPrimitiveObjectStore store = new AtlasPrimitiveObjectStore(); store.addNode(new AtlasPrimitiveLocationItem(1, Location.TEST_6, EMPTY)); store.addNode(new AtlasPrimitiveLocationItem(2, Location.TEST_5, EMPTY)); store.addEdge(new AtlasPrimitiveLineItem(11, new Segment(Location.TEST_6, Location.TEST_5), EMPTY)); Assert.assertFalse(store.checkDataIntegrity().isPresent()); // Add an edge reference to a not existed node store.addEdge(new AtlasPrimitiveLineItem(12, new Segment(Location.TEST_1, Location.TEST_6), EMPTY)); final Optional<TemporaryObjectStore> missingObjects = store.checkDataIntegrity(); Assert.assertTrue(missingObjects.isPresent()); Assert.assertEquals(Location.TEST_1, missingObjects.get().getLocations().iterator().next()); Assert.assertEquals(1, missingObjects.get().size()); }
@Test public void testBuild() { final AtlasPrimitiveObjectStore store = new AtlasPrimitiveObjectStore(); store.addNode(new AtlasPrimitiveLocationItem(1, Location.TEST_6, EMPTY)); store.addNode(new AtlasPrimitiveLocationItem(2, Location.TEST_5, EMPTY)); store.addEdge(new AtlasPrimitiveLineItem(11, new Segment(Location.TEST_6, Location.TEST_5), EMPTY)); store.addEdge(new AtlasPrimitiveLineItem(-11, new Segment(Location.TEST_5, Location.TEST_6), EMPTY)); final Atlas atlas = store.build(); Assert.assertEquals(2, atlas.numberOfEdges()); Assert.assertEquals(2, atlas.numberOfNodes()); }
/** * @return The same segment but pointing north if it is not already, by reversing it if it * points south. */ public Segment pointingNorth() { if (this.isEastWest()) { return this; } if (start().getLatitude().isLessThan(end().getLatitude())) { return this; } return new Segment(end(), start()); }
@Test public void testIntersects() { final Set<Location> intersection = this.quadrant.intersections(new Segment(Location.TEST_5, new Location(Location.TEST_3.getLatitude(), Location.TEST_5.getLongitude()))); Assert.assertEquals(2, intersection.size()); final Set<Location> intersections = this.quadrant.intersections(this.rectangle); Assert.assertEquals(3, intersections.size()); Assert.assertTrue(this.quadrant.intersects(this.rectangle)); }
@Test public void testLoadingPbfWithWayThatReferencesMissingNode() { final AtlasPrimitiveObjectStore store = new AtlasPrimitiveObjectStore(); // Add Points store.addPoint(new AtlasPrimitiveLocationItem(1, Location.TEST_1, EMPTY)); store.addPoint(new AtlasPrimitiveLocationItem(2, Location.TEST_2, EMPTY)); // Add Lines store.addLine(new AtlasPrimitiveLineItem(3, new Segment(Location.TEST_1, Location.TEST_2), EMPTY)); store.addLine(new AtlasPrimitiveLineItem(4, new Segment(Location.TEST_3, Location.TEST_4), EMPTY)); @SuppressWarnings("resource") final OsmosisReaderMock osmosis = new OsmosisReaderMock(store); final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(() -> osmosis, AtlasLoadingOption.createOptionWithNoSlicing(), MultiPolygon.MAXIMUM); // The raw Atlas should not get built, as one of the nodes referenced by the PBF is missing. final Atlas atlas = rawAtlasGenerator.build(); // Verify Atlas Entities assertBasicRawAtlasPrinciples(atlas); Assert.assertEquals(1, atlas.numberOfLines()); Assert.assertEquals(2, atlas.numberOfPoints()); Assert.assertEquals(0, atlas.numberOfRelations()); }
@Test public void testContains() { final PolyLine line = PolyLine .wkt("LINESTRING (10.5553105 48.3419094, 10.5552096 48.3417501, 10.5551312 48.3416583, " + "10.5551027 48.341611, 10.5550183 48.3415143, 10.5549357 48.3414668, " + "10.5548325 48.3414164, 10.5548105 48.3415201, 10.5548015 48.3415686, " + "10.5548925 48.3416166, 10.5550334 48.3416375, 10.5551312 48.3416583)"); Assert.assertTrue("Verifying PolyLine contains Location", line.contains(Location.forString("48.3419094, 10.5553105"))); Assert.assertFalse("Verifying PolyLine doesn't contain Location", line.contains(Location.COLOSSEUM)); Assert.assertTrue("Verifying PolyLine contains Segment", line.contains(new Segment(Location.forString("48.3419094, 10.5553105"), Location.forString("48.3417501, 10.5552096")))); Assert.assertFalse("Verifying PolyLine doesn't contain Segment", line.contains(new Segment(Location.TEST_2, 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)); }
@Test public void testContains() { final Rectangle rectangle = Rectangle.TEST_RECTANGLE; final Polygon polygon = new Polygon(rectangle); Assert.assertTrue("Checking that the Location exists in the Polygon", polygon.contains(Rectangle.TEST_RECTANGLE.first())); Assert.assertTrue("Checking that the Segent that closes the Polygon exists", polygon.contains(new Segment(Rectangle.TEST_RECTANGLE.last(), Rectangle.TEST_RECTANGLE.first()))); }
@Test public void testDifferentGeometry() { final PackedAtlasBuilder baseBuilder = new PackedAtlasBuilder(); final PackedAtlasBuilder alterBuilder = new PackedAtlasBuilder(); final Map<String, String> tags = RandomTagsSupplier.randomTags(5); baseBuilder.addNode(1, Location.TEST_1, tags); baseBuilder.addNode(2, Location.TEST_2, tags); alterBuilder.addNode(1, Location.TEST_1, tags); alterBuilder.addNode(2, Location.TEST_2, tags); baseBuilder.addEdge(0, new Segment(Location.TEST_1, Location.TEST_2), tags); alterBuilder.addEdge(0, new PolyLine(Location.TEST_1, Location.TEST_7, Location.TEST_2), tags); final Atlas base = baseBuilder.get(); final Atlas alter = alterBuilder.get(); final SortedSet<Diff> diffs = new AtlasDelta(base, alter).generate().getDifferences(); Assert.assertEquals(1, diffs.size()); final Diff diff = diffs.first(); logger.debug("testDifferentGeometry(): {}", Diff.toString(diffs)); Assert.assertEquals(DiffType.CHANGED, diff.getDiffType()); }
alterBuilder.addNode(2, Location.TEST_7, tags); alterBuilder.addNode(3, Location.TEST_2, tags); baseBuilder.addEdge(0, new Segment(Location.TEST_2, Location.TEST_1), tags); alterBuilder.addEdge(0, new Segment(Location.TEST_2, Location.TEST_1), tags); final Atlas base = baseBuilder.get(); final Atlas alter = alterBuilder.get();
@Test public void testConcave() { final Polygon concave = new Polygon(Location.forString("1, -1"), Location.forString("1,1"), Location.forString("-1,1"), Location.forString("0,0"), Location.forString("-1,-1")); final Location outside1 = Location.forString("-1, 0"); final Location outside2 = Location.forString("0, 2"); final Location outside3 = Location.forString("-2, 0"); final Location inside1 = Location.forString("-0.5, 0.8"); final Location onBoundary1 = Location.forString("-0.5, 0.5"); final Location onBoundary2 = Location.forString("0, 1"); Assert.assertTrue(concave.fullyGeometricallyEncloses(inside1)); Assert.assertTrue(concave.fullyGeometricallyEncloses(onBoundary1)); // see awt definition of contains Assert.assertFalse(concave.fullyGeometricallyEncloses(onBoundary2)); Assert.assertFalse(concave.fullyGeometricallyEncloses(outside1)); Assert.assertFalse(concave.fullyGeometricallyEncloses(outside2)); Assert.assertTrue(concave.intersects(new Segment(outside1, inside1))); Assert.assertTrue(concave.intersects(new Segment(outside1, outside2))); Assert.assertFalse(concave.intersects(new Segment(outside1, outside3))); }
alterBuilder.addNode(1, Location.TEST_1, tags); alterBuilder.addNode(2, Location.TEST_2, tags); alterBuilder.addEdge(0, new Segment(Location.TEST_1, Location.TEST_2), tags); final Atlas base = baseBuilder.get(); final Atlas alter = alterBuilder.get();
@Test public void testRemoved() { final PackedAtlasBuilder baseBuilder = new PackedAtlasBuilder(); final PackedAtlasBuilder alterBuilder = new PackedAtlasBuilder(); final Map<String, String> tags = RandomTagsSupplier.randomTags(5); baseBuilder.addNode(1, Location.TEST_1, tags); baseBuilder.addNode(2, Location.TEST_2, tags); alterBuilder.addNode(1, Location.TEST_1, tags); alterBuilder.addNode(2, Location.TEST_2, tags); baseBuilder.addEdge(0, new Segment(Location.TEST_1, Location.TEST_2), tags); final Atlas base = baseBuilder.get(); final Atlas alter = alterBuilder.get(); final SortedSet<Diff> diffs = new AtlasDelta(base, alter).generate().getDifferences(); Assert.assertEquals(3, diffs.size()); logger.debug("testRemoved(): {}", Diff.toString(diffs)); boolean foundEdge = false; for (final Diff diff : diffs) { if (diff.getItemType() == ItemType.EDGE) { Assert.assertEquals(DiffType.REMOVED, diff.getDiffType()); foundEdge = true; } } if (!foundEdge) { Assert.fail("Did not find a diff on an Edge."); } }