Skip to content

Commit

Permalink
fix crash after rework apporach on tile connect neighbour
Browse files Browse the repository at this point in the history
  • Loading branch information
mg4gh committed Apr 12, 2024
1 parent 29c73c0 commit d2ff0f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private BBox getGraphDetails(PointModel pmTap, MultiPointModelImpl multiPointMod
GNeighbour neighbour = node.getNeighbour();
while ((neighbour = gGraphTile.getNextNeighbour(node, neighbour)) != null) {
GNode neighbourNode = neighbour.getNeighbourNode();
if (PointModelUtil.compareTo(node, neighbourNode) < 0){ // neighbour relations exist in both direction - here we can reduce to one
if (GNode.sameTile(node,neighbourNode) && (PointModelUtil.compareTo(node, neighbourNode) < 0)){ // neighbour relations exist in both direction - here we can reduce to one
BBox bBoxPart = new BBox().extend(node).extend(neighbourNode);

boolean bIntersects = bBoxTap.intersects(bBoxPart);
Expand All @@ -167,15 +167,17 @@ private BBox getGraphDetails(PointModel pmTap, MultiPointModelImpl multiPointMod

GNode lastNode = null;
for (GNode node : nodes){
multiPointModel.addPoint(node);
if (lastNode != null){
final GNode last = lastNode;
double distance = PointModelUtil.distance(last,node);
double verticalDistance = PointModelUtil.verticalDistance(last, node);
mgLog.d(()-> String.format(Locale.ENGLISH, " segment dist=%.2f vertDist=%.2f ascend=%.1f cost=%.2f revCost=%.2f",distance,verticalDistance,verticalDistance*100/distance,last.getNeighbour(node).getCost(),node.getNeighbour(last).getCost()));
if (GNode.sameTile(bestNode,node)){
multiPointModel.addPoint(node);
if (lastNode != null){
final GNode last = lastNode;
double distance = PointModelUtil.distance(last,node);
double verticalDistance = PointModelUtil.verticalDistance(last, node);
mgLog.d(()-> String.format(Locale.ENGLISH, " segment dist=%.2f vertDist=%.2f ascend=%.1f cost=%.2f revCost=%.2f",distance,verticalDistance,verticalDistance*100/distance,last.getNeighbour(node).getCost(),node.getNeighbour(last).getCost()));
}
mgLog.d(()-> "Point "+ node + getRefDetails(node.getNodeRef()) + getRefDetails(node.getNodeRef(true)));
lastNode = node;
}
mgLog.d(()-> "Point "+ node + getRefDetails(node.getNodeRef()) + getRefDetails(node.getNodeRef(true)));
lastNode = node;
}
}
return (bestTile==null)?null:bestTile.getTileBBox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,21 @@ MultiPointModelImpl calcRouting(RoutePointModel source, RoutePointModel target,
}
gFactory.serviceCache();
if (sourceApproachModel != null){
sourceApproachModel.getNode1().removeNeighbourNode(0);
sourceApproachModel.getNode2().removeNeighbourNode(0);
if (sourceApproachModel.getNode1() != null){
sourceApproachModel.getNode1().removeNeighbourNode(0);
}
if (sourceApproachModel.getNode2() != null){
sourceApproachModel.getNode2().removeNeighbourNode(0);
}
gStart.getNeighbour().setNextNeighbour(null);
}
if (targetApproachModel != null){
targetApproachModel.getNode1().removeNeighbourNode(0);
targetApproachModel.getNode2().removeNeighbourNode(0);
if (targetApproachModel.getNode1() != null){
targetApproachModel.getNode1().removeNeighbourNode(0);
}
if (targetApproachModel.getNode2() != null){
targetApproachModel.getNode2().removeNeighbourNode(0);
}
gEnd.getNeighbour().setNextNeighbour(null);
}
}
Expand Down Expand Up @@ -439,7 +447,7 @@ TreeSet<ApproachModel> calcApproaches(PointModel pointModel, int closeThreshold)
GNeighbour neighbour = node.getNeighbour();
while ((neighbour = gGraphTile.getNextNeighbour(node, neighbour)) != null) {
GNode neighbourNode = neighbour.getNeighbourNode();
if (PointModelUtil.compareTo(node, neighbourNode) < 0){ // neighbour relations exist in both direction - here we can reduce to one
if (GNode.sameTile(node, neighbourNode) && (PointModelUtil.compareTo(node, neighbourNode) < 0)){ // neighbour relations exist in both direction - here we can reduce to one
BBox bBoxPart = new BBox().extend(node).extend(neighbourNode);
boolean bIntersects = mtlpBBox.intersects(bBoxPart);
if (bIntersects){ // ok, is candidate for close
Expand Down
4 changes: 4 additions & 0 deletions mgmap/src/main/java/mg/mgmap/generic/graph/GNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,8 @@ public void removeNeighbourNode(int tileIdx){
public GGraphTile getTile(GGraphTileFactory gFactory){
return gFactory.getGGraphTile(tileIdx>>16, tileIdx&0xFFFF);
}

public static boolean sameTile(GNode node1, GNode node2){
return node1.tileIdx == node2.tileIdx;
}
}

0 comments on commit d2ff0f5

Please sign in to comment.