@Test public void testCopyProperties() { graph = createGraph(); EdgeIteratorState edge = graph.edge(1, 3, 10, false).setName("testing").setWayGeometry(Helper.createPointList(1, 2)); EdgeIteratorState newEdge = graph.edge(1, 3, 10, false); edge.copyPropertiesTo(newEdge); assertEquals(edge.getName(), newEdge.getName()); assertEquals(edge.getDistance(), newEdge.getDistance(), 1e-7); assertEquals(edge.getFlags(), newEdge.getFlags()); assertEquals(edge.fetchWayGeometry(0), newEdge.fetchWayGeometry(0)); }
@Test public void testDetachEdge() { graph = createGraph(); graph.edge(0, 1, 2, true); long flags = carEncoder.setProperties(10, true, false); graph.edge(0, 2, 2, true).setWayGeometry(Helper.createPointList(1, 2, 3, 4)).setFlags(flags); graph.edge(1, 2, 2, true); EdgeIterator iter = graph.createEdgeExplorer().setBaseNode(0); try { // currently not possible to detach without next, without introducing a new property inside // EdgeIterable iter.detach(false); assertTrue(false); } catch (Exception ex) { } iter.next(); EdgeIteratorState edgeState2 = iter.detach(false); assertEquals(2, iter.getAdjNode()); assertEquals(1, edgeState2.fetchWayGeometry(0).getLatitude(0), 1e-1); assertEquals(2, edgeState2.getAdjNode()); assertTrue(carEncoder.isBool(edgeState2.getFlags(), FlagEncoder.K_FORWARD)); EdgeIteratorState edgeState3 = iter.detach(true); assertEquals(0, edgeState3.getAdjNode()); assertEquals(2, edgeState3.getBaseNode()); assertEquals(3, edgeState3.fetchWayGeometry(0).getLatitude(0), 1e-1); assertFalse(carEncoder.isBool(edgeState3.getFlags(), FlagEncoder.K_FORWARD)); assertEquals(GHUtility.getEdge(graph, 0, 2).getFlags(), edgeState2.getFlags()); assertEquals(GHUtility.getEdge(graph, 2, 0).getFlags(), edgeState3.getFlags()); iter.next(); assertEquals(1, iter.getAdjNode()); assertEquals(2, edgeState2.getAdjNode()); assertEquals(2, edgeState3.getBaseNode()); assertEquals(0, iter.fetchWayGeometry(0).size()); assertEquals(1, edgeState2.fetchWayGeometry(0).getLatitude(0), 1e-1); assertEquals(3, edgeState3.fetchWayGeometry(0).getLatitude(0), 1e-1); // #162 a directed self referencing edge should be able to reverse its state too graph.edge(3, 3, 2, true).setFlags(flags); EdgeIterator iter2 = graph.createEdgeExplorer().setBaseNode(3); iter2.next(); assertEquals(edgeState2.getFlags(), iter2.detach(false).getFlags()); assertEquals(edgeState3.getFlags(), iter2.detach(true).getFlags()); }
protected void checkGraph(Graph g) { NodeAccess na = g.getNodeAccess(); assertTrue(na.is3D()); assertTrue(g.getBounds().isValid()); assertEquals(new BBox(10, 20, 10, 12, 0, 1), g.getBounds()); assertEquals(10, na.getLatitude(0), 1e-2); assertEquals(10, na.getLongitude(0), 1e-2); EdgeExplorer explorer = g.createEdgeExplorer(carOutFilter); assertEquals(2, GHUtility.count(explorer.setBaseNode(0))); assertEquals(GHUtility.asSet(2, 1), GHUtility.getNeighbors(explorer.setBaseNode(0))); EdgeIterator iter = explorer.setBaseNode(0); assertTrue(iter.next()); assertEquals(Helper.createPointList3D(3.5, 4.5, 0, 5, 6, 0), iter.fetchWayGeometry(0)); assertTrue(iter.next()); assertEquals(Helper.createPointList3D(1.5, 1, 0, 2, 3, 0), iter.fetchWayGeometry(0)); assertEquals(Helper.createPointList3D(10, 10, 0, 1.5, 1, 0, 2, 3, 0), iter.fetchWayGeometry(1)); assertEquals(Helper.createPointList3D(1.5, 1, 0, 2, 3, 0, 11, 20, 1), iter.fetchWayGeometry(2)); assertEquals(11, na.getLatitude(1), 1e-2); assertEquals(20, na.getLongitude(1), 1e-2); assertEquals(2, GHUtility.count(explorer.setBaseNode(1))); assertEquals(GHUtility.asSet(2, 0), GHUtility.getNeighbors(explorer.setBaseNode(1))); assertEquals(12, na.getLatitude(2), 1e-2); assertEquals(12, na.getLongitude(2), 1e-2); assertEquals(1, GHUtility.count(explorer.setBaseNode(2))); assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(2))); EdgeIteratorState eib = GHUtility.getEdge(g, 1, 2); assertEquals(Helper.createPointList3D(), eib.fetchWayGeometry(0)); assertEquals(Helper.createPointList3D(11, 20, 1), eib.fetchWayGeometry(1)); assertEquals(Helper.createPointList3D(12, 12, 0.4), eib.fetchWayGeometry(2)); assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(2))); }