public boolean containsLatitude(Graph g, EdgeIterator iter, double latitude) {
   NodeAccess na = g.getNodeAccess();
   while (iter.next()) {
     if (Math.abs(na.getLatitude(iter.getAdjNode()) - latitude) < 1e-4) return true;
   }
   return false;
 }
  @Test
  public void testSimpleDelete3() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(7, 7, 1);
    na.setNode(8, 8, 1);
    na.setNode(9, 9, 1);
    na.setNode(11, 11, 1);

    // mini subnetwork which gets completely removed:
    graph.edge(5, 10, 510, true);
    graph.markNodeRemoved(3);
    graph.markNodeRemoved(4);
    graph.markNodeRemoved(5);
    graph.markNodeRemoved(10);

    graph.edge(9, 11, 911, true);
    graph.edge(7, 9, 78, true);
    graph.edge(8, 9, 89, true);

    // perform deletion
    graph.optimize();

    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph));

    assertEquals(3, GHUtility.count(carAllExplorer.setBaseNode(getIdOf(graph, 9))));
    assertEquals(1, GHUtility.count(carAllExplorer.setBaseNode(getIdOf(graph, 7))));
    assertEquals(1, GHUtility.count(carAllExplorer.setBaseNode(getIdOf(graph, 8))));
    assertEquals(1, GHUtility.count(carAllExplorer.setBaseNode(getIdOf(graph, 11))));
  }
  @Test
  public void testDeleteNodeForUnidir() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(10, 10, 1);
    na.setNode(6, 6, 1);
    na.setNode(20, 20, 1);
    na.setNode(21, 21, 1);

    graph.edge(10, 20, 10, false);
    graph.edge(21, 6, 10, false);

    graph.markNodeRemoved(0);
    graph.markNodeRemoved(7);
    assertEquals(22, graph.getNodes());
    graph.optimize();
    assertEquals(20, graph.getNodes());

    assertEquals(1, GHUtility.count(carInExplorer.setBaseNode(getIdOf(graph, 20))));
    assertEquals(0, GHUtility.count(carOutExplorer.setBaseNode(getIdOf(graph, 20))));

    assertEquals(1, GHUtility.count(carOutExplorer.setBaseNode(getIdOf(graph, 10))));
    assertEquals(0, GHUtility.count(carInExplorer.setBaseNode(getIdOf(graph, 10))));

    assertEquals(1, GHUtility.count(carInExplorer.setBaseNode(getIdOf(graph, 6))));
    assertEquals(0, GHUtility.count(carOutExplorer.setBaseNode(getIdOf(graph, 6))));

    assertEquals(1, GHUtility.count(carOutExplorer.setBaseNode(getIdOf(graph, 21))));
    assertEquals(0, GHUtility.count(carInExplorer.setBaseNode(getIdOf(graph, 21))));
  }
  @Test
  public void testGetAllEdgesWithDelete() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0, 5);
    na.setNode(1, 1, 5);
    na.setNode(2, 2, 5);
    na.setNode(3, 3, 5);
    graph.edge(0, 1, 1, true);
    graph.edge(0, 2, 1, true);
    graph.edge(1, 2, 1, true);
    graph.edge(2, 3, 1, true);
    AllEdgesIterator iter = graph.getAllEdges();
    assertEquals(4, GHUtility.count(iter));
    assertEquals(4, iter.getMaxId());

    // delete
    graph.markNodeRemoved(1);
    graph.optimize();
    iter = graph.getAllEdges();
    assertEquals(2, GHUtility.count(iter));
    assertEquals(4, iter.getMaxId());

    iter = graph.getAllEdges();
    iter.next();
    EdgeIteratorState eState = iter.detach(false);
    assertEquals(iter.toString(), eState.toString());
    iter.next();
    assertNotEquals(iter.toString(), eState.toString());

    EdgeIteratorState eState2 = iter.detach(true);
    assertEquals(iter.getAdjNode(), eState2.getBaseNode());
    iter.next();
    assertNotEquals(iter.getAdjNode(), eState2.getBaseNode());
  }
  @Test
  public void testSimpleDelete() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 38.33f, 135.3f);
    na.setNode(2, 3, 3);
    na.setNode(3, 78, 89);

    graph.edge(3, 0, 21, true);
    graph.edge(5, 0, 22, true);
    graph.edge(5, 3, 23, true);

    graph.markNodeRemoved(0);
    graph.markNodeRemoved(3);

    assertEquals(6, graph.getNodes());
    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph));

    // now actually perform deletion
    graph.optimize();

    assertEquals(4, graph.getNodes());
    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph));
    // shouldn't change anything
    graph.optimize();
    assertEquals(4, graph.getNodes());
    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph));
  }
 public static int getIdOf(Graph g, double latitude) {
   int s = g.getNodes();
   NodeAccess na = g.getNodeAccess();
   for (int i = 0; i < s; i++) {
     if (Math.abs(na.getLatitude(i) - latitude) < 1e-4) {
       return i;
     }
   }
   return -1;
 }
 @Test
 public void testDeleteAndOptimize() {
   graph = createGraph();
   NodeAccess na = graph.getNodeAccess();
   na.setNode(20, 10, 10);
   na.setNode(21, 10, 11);
   graph.markNodeRemoved(20);
   graph.optimize();
   assertEquals(11, na.getLongitude(20), 1e-5);
 }
  public void testDeleteNodes(int fillToSize) {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 38.33f, 135.3f);
    na.setNode(2, 3, 3);
    na.setNode(3, 78, 89);
    na.setNode(4, 2, 1);
    na.setNode(5, 2.5f, 1);

    int deleted = 2;
    for (int i = 6; i < fillToSize; i++) {
      na.setNode(i, i * 1.5, i * 1.6);
      if (i % 3 == 0) {
        graph.markNodeRemoved(i);
        deleted++;
      } else {
        // connect to
        // ... a deleted node
        graph.edge(i, 0, 10 * i, true);
        // ... a non-deleted and non-moved node
        graph.edge(i, 2, 10 * i, true);
        // ... a moved node
        graph.edge(i, fillToSize - 1, 10 * i, true);
      }
    }

    graph.edge(0, 1, 10, true);
    graph.edge(0, 3, 20, false);
    graph.edge(3, 5, 20, true);
    graph.edge(1, 5, 20, false);

    graph.markNodeRemoved(0);
    graph.markNodeRemoved(2);
    // no deletion happend
    assertEquals(fillToSize, graph.getNodes());

    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph));

    // now actually perform deletion
    graph.optimize();

    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph));

    assertEquals(fillToSize - deleted, graph.getNodes());
    int id1 = getIdOf(graph, 38.33f);
    assertEquals(135.3f, na.getLongitude(id1), 1e-4);
    assertTrue(containsLatitude(graph, carAllExplorer.setBaseNode(id1), 2.5));
    assertFalse(containsLatitude(graph, carAllExplorer.setBaseNode(id1), 12));

    int id3 = getIdOf(graph, 78);
    assertEquals(89, na.getLongitude(id3), 1e-4);
    assertTrue(containsLatitude(graph, carAllExplorer.setBaseNode(id3), 2.5));
    assertFalse(containsLatitude(graph, carAllExplorer.setBaseNode(id3), 12));
  }
 @Test
 public void testSetNodes() {
   graph = createGraph();
   NodeAccess na = graph.getNodeAccess();
   for (int i = 0; i < defaultSize * 2; i++) {
     na.setNode(i, 2 * i, 3 * i);
   }
   graph.edge(defaultSize + 1, defaultSize + 2, 10, true);
   graph.edge(defaultSize + 1, defaultSize + 3, 10, true);
   assertEquals(2, GHUtility.count(carAllExplorer.setBaseNode(defaultSize + 1)));
 }
 protected void initExampleGraph(Graph g) {
   NodeAccess na = g.getNodeAccess();
   na.setNode(0, 12, 23);
   na.setNode(1, 38.33f, 135.3f);
   na.setNode(2, 6, 139);
   na.setNode(3, 78, 89);
   na.setNode(4, 2, 1);
   na.setNode(5, 7, 5);
   g.edge(0, 1, 12, true);
   g.edge(0, 2, 212, true);
   g.edge(0, 3, 212, true);
   g.edge(0, 4, 212, true);
   g.edge(0, 5, 212, true);
 }
 @Test
 public void testNoErrorOnEdgeCase_lastIndex() {
   final EncodingManager encodingManager = new EncodingManager("car");
   int locs = 10000;
   Graph g =
       AbstractLocationIndexTester.this.createGHStorage(
           new MMapDirectory(location), encodingManager, false);
   NodeAccess na = g.getNodeAccess();
   Random rand = new Random(12);
   for (int i = 0; i < locs; i++) {
     na.setNode(i, (float) rand.nextDouble() * 10 + 10, (float) rand.nextDouble() * 10 + 10);
   }
   idx = createIndex(g, 200);
   Helper.close((Closeable) g);
 }
  @Test
  public void testSimpleDelete2() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    assertEquals(-1, getIdOf(graph, 12));
    na.setNode(9, 9, 1);
    assertEquals(-1, getIdOf(graph, 12));

    na.setNode(11, 11, 1);
    na.setNode(12, 12, 1);

    // mini subnetwork which gets completely removed:
    graph.edge(5, 10, 510, true);
    graph.markNodeRemoved(5);
    graph.markNodeRemoved(10);

    PointList pl = new PointList();
    pl.add(1, 2, Double.NaN);
    pl.add(1, 3, Double.NaN);
    graph.edge(9, 11, 911, true).setWayGeometry(pl);
    graph.edge(9, 12, 912, true).setWayGeometry(pl);

    assertEquals(13, graph.getNodes());
    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph));

    // perform deletion
    graph.optimize();

    assertEquals(11, graph.getNodes());
    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph));

    int id11 = getIdOf(graph, 11); // is now 10
    int id12 = getIdOf(graph, 12); // is now 5
    int id9 = getIdOf(graph, 9); // is now 9
    assertEquals(
        GHUtility.asSet(id12, id11), GHUtility.getNeighbors(carAllExplorer.setBaseNode(id9)));
    assertEquals(GHUtility.asSet(id9), GHUtility.getNeighbors(carAllExplorer.setBaseNode(id11)));
    assertEquals(GHUtility.asSet(id9), GHUtility.getNeighbors(carAllExplorer.setBaseNode(id12)));

    EdgeIterator iter = carAllExplorer.setBaseNode(id9);
    assertTrue(iter.next());
    assertEquals(id12, iter.getAdjNode());
    assertEquals(2, iter.fetchWayGeometry(0).getLongitude(0), 1e-7);

    assertTrue(iter.next());
    assertEquals(id11, iter.getAdjNode());
    assertEquals(2, iter.fetchWayGeometry(0).getLongitude(0), 1e-7);
  }
  @Test
  public void testBounds() {
    graph = createGraph();
    BBox b = graph.getBounds();
    assertEquals(BBox.INVERSE.maxLat, b.maxLat, 1e-6);

    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 10, 20);
    assertEquals(10, b.maxLat, 1e-6);
    assertEquals(20, b.maxLon, 1e-6);

    na.setNode(0, 15, -15);
    assertEquals(15, b.maxLat, 1e-6);
    assertEquals(20, b.maxLon, 1e-6);
    assertEquals(10, b.minLat, 1e-6);
    assertEquals(-15, b.minLon, 1e-6);
  }
  @Test
  public void testGetLocations() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 22, 23);
    assertEquals(2, graph.getNodes());

    graph.edge(0, 1, 10, true);
    assertEquals(2, graph.getNodes());

    graph.edge(0, 2, 10, true);
    assertEquals(3, graph.getNodes());
    Helper.close((Closeable) graph);

    graph = createGraph();
    assertEquals(0, graph.getNodes());
  }
  @Test
  public void testEnabledElevation() {
    graph = createGraph(defaultGraphLoc, true);
    NodeAccess na = graph.getNodeAccess();
    assertTrue(na.is3D());
    na.setNode(0, 10, 20, -10);
    na.setNode(1, 11, 2, 100);
    assertEquals(-10, na.getEle(0), 1e-1);
    assertEquals(100, na.getEle(1), 1e-1);

    graph.edge(0, 1).setWayGeometry(Helper.createPointList3D(10, 27, 72, 11, 20, 1));
    assertEquals(
        Helper.createPointList3D(10, 27, 72, 11, 20, 1),
        GHUtility.getEdge(graph, 0, 1).fetchWayGeometry(0));
    assertEquals(
        Helper.createPointList3D(10, 20, -10, 10, 27, 72, 11, 20, 1, 11, 2, 100),
        GHUtility.getEdge(graph, 0, 1).fetchWayGeometry(3));
    assertEquals(
        Helper.createPointList3D(11, 2, 100, 11, 20, 1, 10, 27, 72, 10, 20, -10),
        GHUtility.getEdge(graph, 1, 0).fetchWayGeometry(3));
  }
  @Test
  public void testClone() {
    graph = createGraph();
    graph.edge(1, 2, 10, true);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 8, 13);
    na.setNode(2, 2, 10);
    na.setNode(3, 5, 9);
    graph.edge(1, 3, 10, true);

    Graph clone = graph.copyTo(createGraph(locationParent + "/clone", false));
    assertEquals(graph.getNodes(), clone.getNodes());
    assertEquals(
        count(carOutExplorer.setBaseNode(1)),
        count(clone.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    clone.edge(1, 4, 10, true);
    assertEquals(3, count(clone.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    assertEquals(graph.getBounds(), clone.getBounds());
    Helper.close((Closeable) clone);
  }
 public void initSimpleGraph(Graph g) {
   //  6 |       4
   //  5 |
   //    |     6
   //  4 |              5
   //  3 |
   //  2 |    1
   //  1 |          3
   //  0 |    2
   // -1 | 0
   // ---|-------------------
   //    |-2 -1 0 1 2 3 4
   //
   NodeAccess na = g.getNodeAccess();
   na.setNode(0, -1, -2);
   na.setNode(1, 2, -1);
   na.setNode(2, 0, 1);
   na.setNode(3, 1, 2);
   na.setNode(4, 6, 1);
   na.setNode(5, 4, 4);
   na.setNode(6, 4.5, -0.5);
   g.edge(0, 1, 3.5, true);
   g.edge(0, 2, 2.5, true);
   g.edge(2, 3, 1, true);
   g.edge(3, 4, 3.2, true);
   g.edge(1, 4, 2.4, true);
   g.edge(3, 5, 1.5, true);
   // make sure 6 is connected
   g.edge(6, 4, 1.2, true);
 }
  @Test
  public void testSave_and_fileFormat() throws IOException {
    graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), true).create(defaultSize);
    NodeAccess na = graph.getNodeAccess();
    assertTrue(na.is3D());
    na.setNode(0, 10, 10, 0);
    na.setNode(1, 11, 20, 1);
    na.setNode(2, 12, 12, 0.4);

    EdgeIteratorState iter2 = graph.edge(0, 1, 100, true);
    iter2.setWayGeometry(Helper.createPointList3D(1.5, 1, 0, 2, 3, 0));
    EdgeIteratorState iter1 = graph.edge(0, 2, 200, true);
    iter1.setWayGeometry(Helper.createPointList3D(3.5, 4.5, 0, 5, 6, 0));
    graph.edge(9, 10, 200, true);
    graph.edge(9, 11, 200, true);
    graph.edge(1, 2, 120, false);

    iter1.setName("named street1");
    iter2.setName("named street2");

    checkGraph(graph);
    graph.flush();
    graph.close();

    graph = newGHStorage(new MMapDirectory(defaultGraphLoc), true);
    assertTrue(graph.loadExisting());

    assertEquals(12, graph.getNodes());
    checkGraph(graph);

    assertEquals(
        "named street1", graph.getEdgeIteratorState(iter1.getEdge(), iter1.getAdjNode()).getName());
    assertEquals(
        "named street2", graph.getEdgeIteratorState(iter2.getEdge(), iter2.getAdjNode()).getName());
    graph.edge(3, 4, 123, true).setWayGeometry(Helper.createPointList3D(4.4, 5.5, 0, 6.6, 7.7, 0));
    checkGraph(graph);
  }
  private void checkExampleGraph(Graph graph) {
    NodeAccess na = graph.getNodeAccess();
    assertEquals(12f, na.getLatitude(0), 1e-6);
    assertEquals(23f, na.getLongitude(0), 1e-6);

    assertEquals(38.33f, na.getLatitude(1), 1e-6);
    assertEquals(135.3f, na.getLongitude(1), 1e-6);

    assertEquals(6, na.getLatitude(2), 1e-6);
    assertEquals(139, na.getLongitude(2), 1e-6);

    assertEquals(78, na.getLatitude(3), 1e-6);
    assertEquals(89, na.getLongitude(3), 1e-6);

    assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(carOutExplorer.setBaseNode((1))));
    assertEquals(
        GHUtility.asSet(5, 4, 3, 2, 1), GHUtility.getNeighbors(carOutExplorer.setBaseNode(0)));
    try {
      assertEquals(0, count(carOutExplorer.setBaseNode(6)));
      // for now return empty iterator
      // assertFalse(true);
    } catch (Exception ex) {
    }
  }
  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)));
  }
Example #21
0
  public void setTurnCosts(int nodeIndex, int from, int to, int flags) {
    if (flags == 0) {
      // no need to store turn costs
      return;
    }

    // append
    int newEntryIndex = turnCostsCount;
    turnCostsCount++;
    ensureTurnCostsIndex(newEntryIndex);

    // determine if we already have an cost entry for this node
    int previousEntryIndex = getCostTableAdress(nodeIndex);
    if (previousEntryIndex == NO_COST_ENTRY) {
      // set cost-pointer to this new cost entry
      nodeAccess.setAdditionalNodeField(nodeIndex, newEntryIndex);
    } else {
      int i = 0;
      int tmp = previousEntryIndex;
      while ((tmp = turnCosts.getInt((long) tmp * turnCostsEntryBytes + TC_NEXT))
          != NO_COST_ENTRY) {
        previousEntryIndex = tmp;
        // search for the last added cost entry
        if (i++ > 1000) {
          throw new IllegalStateException(
              "Something unexpected happened. A node probably will not have 1000+ relations.");
        }
      }
      // set next-pointer to this new cost entry
      turnCosts.setInt((long) previousEntryIndex * turnCostsEntryBytes + TC_NEXT, newEntryIndex);
    }
    // add entry
    long costsBase = (long) newEntryIndex * turnCostsEntryBytes;
    turnCosts.setInt(costsBase + TC_FROM, from);
    turnCosts.setInt(costsBase + TC_TO, to);
    turnCosts.setInt(costsBase + TC_COSTS, flags);
    // next-pointer is NO_COST_ENTRY
    turnCosts.setInt(costsBase + TC_NEXT, NO_COST_ENTRY);
  }
Example #22
0
  private int getCostTableAdress(int index) {
    if (index >= graph.getNodes() || index < 0) return NO_COST_ENTRY;

    return nodeAccess.getAdditionalNodeField(index);
  }
  public Graph createSampleGraph(EncodingManager encodingManager) {
    Graph graph = AbstractLocationIndexTester.this.createGHStorage(encodingManager);
    // length does not matter here but lat,lon and outgoing edges do!

    //
    //   lat             /--------\
    //    5   o-        p--------\ q
    //          \  /-----\-----n | |
    //    4       k    /--l--    m/
    //           / \  j      \   |
    //    3     |   g  \  h---i  /
    //          |       \    /  /
    //    2     e---------f--  /
    //                   /  \-d
    //    1        /--b--      \
    //            |    \--------c
    //    0       a
    //
    //   lon: 0   1   2   3   4   5
    int a0 = 0;
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0, 1.0001f);
    int b1 = 1;
    na.setNode(1, 1, 2);
    int c2 = 2;
    na.setNode(2, 0.5f, 4.5f);
    int d3 = 3;
    na.setNode(3, 1.5f, 3.8f);
    int e4 = 4;
    na.setNode(4, 2.01f, 0.5f);
    int f5 = 5;
    na.setNode(5, 2, 3);
    int g6 = 6;
    na.setNode(6, 3, 1.5f);
    int h7 = 7;
    na.setNode(7, 2.99f, 3.01f);
    int i8 = 8;
    na.setNode(8, 3, 4);
    int j9 = 9;
    na.setNode(9, 3.3f, 2.2f);
    int k10 = 10;
    na.setNode(10, 4, 1);
    int l11 = 11;
    na.setNode(11, 4.1f, 3);
    int m12 = 12;
    na.setNode(12, 4, 4.5f);
    int n13 = 13;
    na.setNode(13, 4.5f, 4.1f);
    int o14 = 14;
    na.setNode(14, 5, 0);
    int p15 = 15;
    na.setNode(15, 4.9f, 2.5f);
    int q16 = 16;
    na.setNode(16, 5, 5);
    // => 17 locations

    graph.edge(a0, b1, 1, true);
    graph.edge(c2, b1, 1, true);
    graph.edge(c2, d3, 1, true);
    graph.edge(f5, b1, 1, true);
    graph.edge(e4, f5, 1, true);
    graph.edge(m12, d3, 1, true);
    graph.edge(e4, k10, 1, true);
    graph.edge(f5, d3, 1, true);
    graph.edge(f5, i8, 1, true);
    graph.edge(f5, j9, 1, true);
    graph.edge(k10, g6, 1, true);
    graph.edge(j9, l11, 1, true);
    graph.edge(i8, l11, 1, true);
    graph.edge(i8, h7, 1, true);
    graph.edge(k10, n13, 1, true);
    graph.edge(k10, o14, 1, true);
    graph.edge(l11, p15, 1, true);
    graph.edge(m12, p15, 1, true);
    graph.edge(q16, p15, 1, true);
    graph.edge(q16, m12, 1, true);
    return graph;
  }
  @Test
  public void testPillarNodes() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0.01, 0.01);
    na.setNode(4, 0.4, 0.4);
    na.setNode(14, 0.14, 0.14);
    na.setNode(10, 0.99, 0.99);

    PointList pointList = Helper.createPointList(1, 1, 1, 2, 1, 3);
    graph
        .edge(0, 4)
        .setDistance(100)
        .setFlags(carEncoder.setProperties(10, true, false))
        .setWayGeometry(pointList);
    pointList = Helper.createPointList(1, 5, 1, 6, 1, 7, 1, 8, 1, 9);
    graph
        .edge(4, 10)
        .setDistance(100)
        .setFlags(carEncoder.setProperties(10, true, false))
        .setWayGeometry(pointList);
    pointList = Helper.createPointList(1, 13, 1, 12, 1, 11);
    graph
        .edge(14, 0)
        .setDistance(100)
        .setFlags(carEncoder.setProperties(10, true, false))
        .setWayGeometry(pointList);

    EdgeIterator iter = carAllExplorer.setBaseNode(0);
    assertTrue(iter.next());
    assertEquals(14, iter.getAdjNode());
    assertPList(Helper.createPointList(1, 11, 1, 12, 1, 13.0), iter.fetchWayGeometry(0));
    assertPList(
        Helper.createPointList(0.01, 0.01, 1, 11, 1, 12, 1, 13.0), iter.fetchWayGeometry(1));
    assertPList(
        Helper.createPointList(1, 11, 1, 12, 1, 13.0, 0.14, 0.14), iter.fetchWayGeometry(2));
    assertPList(
        Helper.createPointList(0.01, 0.01, 1, 11, 1, 12, 1, 13.0, 0.14, 0.14),
        iter.fetchWayGeometry(3));

    assertTrue(iter.next());
    assertEquals(4, iter.getAdjNode());
    assertPList(Helper.createPointList(1, 1, 1, 2, 1, 3), iter.fetchWayGeometry(0));
    assertPList(Helper.createPointList(0.01, 0.01, 1, 1, 1, 2, 1, 3), iter.fetchWayGeometry(1));
    assertPList(Helper.createPointList(1, 1, 1, 2, 1, 3, 0.4, 0.4), iter.fetchWayGeometry(2));
    assertPList(
        Helper.createPointList(0.01, 0.01, 1, 1, 1, 2, 1, 3, 0.4, 0.4), iter.fetchWayGeometry(3));

    assertFalse(iter.next());

    iter = carOutExplorer.setBaseNode(0);
    assertTrue(iter.next());
    assertEquals(4, iter.getAdjNode());
    assertPList(Helper.createPointList(1, 1, 1, 2, 1, 3), iter.fetchWayGeometry(0));
    assertFalse(iter.next());

    iter = carInExplorer.setBaseNode(10);
    assertTrue(iter.next());
    assertEquals(4, iter.getAdjNode());
    assertPList(Helper.createPointList(1, 9, 1, 8, 1, 7, 1, 6, 1, 5), iter.fetchWayGeometry(0));
    assertPList(
        Helper.createPointList(0.99, 0.99, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5), iter.fetchWayGeometry(1));
    assertPList(
        Helper.createPointList(1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 0.4, 0.4), iter.fetchWayGeometry(2));
    assertPList(
        Helper.createPointList(0.99, 0.99, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 0.4, 0.4),
        iter.fetchWayGeometry(3));
    assertFalse(iter.next());
  }
  @Test
  public void testGrid() {
    Graph g = createSampleGraph(new EncodingManager("car"));
    int locs = g.getNodes();

    idx = createIndex(g, -1);
    // if we would use less array entries then some points gets the same key so avoid that for this
    // test
    // e.g. for 16 we get "expected 6 but was 9" i.e 6 was overwritten by node j9 which is a bit
    // closer to the grid center
    // go through every point of the graph if all points are reachable
    NodeAccess na = g.getNodeAccess();
    for (int i = 0; i < locs; i++) {
      double lat = na.getLatitude(i);
      double lon = na.getLongitude(i);
      assertEquals("nodeId:" + i + " " + (float) lat + "," + (float) lon, i, findID(idx, lat, lon));
    }

    // hit random lat,lon and compare result to full index
    Random rand = new Random(12);
    LocationIndex fullIndex;
    if (hasEdgeSupport()) fullIndex = new Location2IDFullWithEdgesIndex(g);
    else fullIndex = new Location2IDFullIndex(g);

    DistanceCalc dist = new DistanceCalcEarth();
    for (int i = 0; i < 100; i++) {
      double lat = rand.nextDouble() * 5;
      double lon = rand.nextDouble() * 5;
      int fullId = findID(fullIndex, lat, lon);
      double fullLat = na.getLatitude(fullId);
      double fullLon = na.getLongitude(fullId);
      float fullDist = (float) dist.calcDist(lat, lon, fullLat, fullLon);
      int newId = findID(idx, lat, lon);
      double newLat = na.getLatitude(newId);
      double newLon = na.getLongitude(newId);
      float newDist = (float) dist.calcDist(lat, lon, newLat, newLon);

      if (testGridIgnore(i)) {
        continue;
      }

      assertTrue(
          i
              + " orig:"
              + (float) lat
              + ","
              + (float) lon
              + " full:"
              + fullLat
              + ","
              + fullLon
              + " fullDist:"
              + fullDist
              + " found:"
              + newLat
              + ","
              + newLon
              + " foundDist:"
              + newDist,
          Math.abs(fullDist - newDist) < 50000);
    }
    fullIndex.close();
    Helper.close((Closeable) g);
  }