Program: 186352
Project: 186352
Buggy source:
/** 
 * create forces between all nodes depending on their position in the base terrain grid: <ul> <li> connect each TerrainPoint to its up to 4 grid neighbors <li> distribute other nodes to grid cells (quadrangle created by 4 TerrainPoints) and connect them with other nodes from the same cell as well as the corner TerrainPoints </ul>
 */
private void addNeighborshipForces(){
  final IntersectionGrid speedupGrid=new IntersectionGrid(new AxisAlignedBoundingBoxXZ(eleData.getBoundaryPolygonXZ().getVertices()).pad(20),50,50);
  for (  TerrainElevationCell cell : eleData.getCells()) {
    speedupGrid.insert(cell);
  }
  for (  Multimap<? extends MapElement,ForceNode> map : asList(lineMap,areaMap)) {
    for (    MapElement segment : map.keySet()) {
      if (segment.getPrimaryRepresentation() != null && segment.getPrimaryRepresentation().getGroundState() == GroundState.ON) {
        for (        ForceNode fNode : ((Multimap<Object,ForceNode>)map).get(segment)) {
          speedupGrid.insert(fNode);
        }
      }
    }
  }
  for (  MapNode node : nodeMap.keySet()) {
    if (node.getPrimaryRepresentation() != null && node.getPrimaryRepresentation().getGroundState() == GroundState.ON) {
      ForceNode fNode=nodeMap.get(node);
      speedupGrid.insert(fNode);
    }
  }
  for (  TerrainElevationCell cell : eleData.getCells()) {
    forces.add(new NeighborshipForce(terrainPointMap.get(cell.getTopLeft()),terrainPointMap.get(cell.getBottomLeft())));
    forces.add(new NeighborshipForce(terrainPointMap.get(cell.getTopLeft()),terrainPointMap.get(cell.getTopRight())));
    Set<ForceNode> forceNodesInCell=new HashSet<ForceNode>();
    Iterable<IntersectionTestObject> potentialNodes=Iterables.concat(speedupGrid.cellsFor(cell));
    for (    IntersectionTestObject potentialNode : potentialNodes) {
      if (potentialNode instanceof ForceNode) {
        ForceNode node=(ForceNode)potentialNode;
        if (cell.getPolygonXZ().contains(node.getPos())) {
          forceNodesInCell.add(node);
        }
      }
    }
    for (    final ForceNode fNode : forceNodesInCell) {
      TerrainPoint closestTerrainPoint=MinUtil.min(cell.getTerrainPoints(),new Function<TerrainPoint,Double>(){
        @Override public Double apply(        TerrainPoint p){
          return VectorXZ.distance(fNode.getPos(),p.getPos());
        }
      }
);
      forces.add(new NeighborshipForce(fNode,terrainPointMap.get(closestTerrainPoint)));
    }
  }
}

Fixed version (ground truth):
/** 
 * create forces between all nodes depending on their position in the base terrain grid: <ul> <li> connect each TerrainPoint to its up to 4 grid neighbors <li> distribute other nodes to grid cells (quadrangle created by 4 TerrainPoints) and connect them with other nodes from the same cell as well as the corner TerrainPoints </ul>
 */
private void addNeighborshipForces(){
  final IntersectionGrid speedupGrid=new IntersectionGrid(new AxisAlignedBoundingBoxXZ(eleData.getBoundaryPolygonXZ().getVertices()).pad(20),50,50);
  for (  TerrainElevationCell cell : eleData.getCells()) {
    speedupGrid.insert(cell);
  }
  for (  MapWaySegment segment : lineMap.keySet()) {
    if (segment.getPrimaryRepresentation() != null && segment.getPrimaryRepresentation().getGroundState() == GroundState.ON) {
      for (      ForceNode fNode : lineMap.get(segment)) {
        speedupGrid.insert(fNode);
      }
    }
  }
  for (  MapArea area : areaMap.keySet()) {
    if (area.getPrimaryRepresentation() != null && area.getPrimaryRepresentation().getGroundState() == GroundState.ON) {
      for (      ForceNode fNode : areaMap.get(area)) {
        speedupGrid.insert(fNode);
      }
    }
  }
  for (  MapNode node : nodeMap.keySet()) {
    if (node.getPrimaryRepresentation() != null && node.getPrimaryRepresentation().getGroundState() == GroundState.ON) {
      ForceNode fNode=nodeMap.get(node);
      speedupGrid.insert(fNode);
    }
  }
  for (  TerrainElevationCell cell : eleData.getCells()) {
    forces.add(new NeighborshipForce(terrainPointMap.get(cell.getTopLeft()),terrainPointMap.get(cell.getBottomLeft())));
    forces.add(new NeighborshipForce(terrainPointMap.get(cell.getTopLeft()),terrainPointMap.get(cell.getTopRight())));
    Set<ForceNode> forceNodesInCell=new HashSet<ForceNode>();
    Iterable<IntersectionTestObject> potentialNodes=Iterables.concat(speedupGrid.cellsFor(cell));
    for (    IntersectionTestObject potentialNode : potentialNodes) {
      if (potentialNode instanceof ForceNode) {
        ForceNode node=(ForceNode)potentialNode;
        if (cell.getPolygonXZ().contains(node.getPos())) {
          forceNodesInCell.add(node);
        }
      }
    }
    for (    final ForceNode fNode : forceNodesInCell) {
      TerrainPoint closestTerrainPoint=MinUtil.min(cell.getTerrainPoints(),new Function<TerrainPoint,Double>(){
        @Override public Double apply(        TerrainPoint p){
          return VectorXZ.distance(fNode.getPos(),p.getPos());
        }
      }
);
      forces.add(new NeighborshipForce(fNode,terrainPointMap.get(closestTerrainPoint)));
    }
  }
}