Beispiel #1
0
  private FastList<AbstractNodeLoc> constructPath(AbstractNode node) {
    FastList<AbstractNodeLoc> path = new FastList<AbstractNodeLoc>();
    int previousDirectionX = Integer.MIN_VALUE;
    int previousDirectionY = Integer.MIN_VALUE;
    int directionX, directionY;

    while (node.getParent() != null) {
      if (!Config.ADVANCED_DIAGONAL_STRATEGY && (node.getParent().getParent() != null)) {
        int tmpX = node.getLoc().getNodeX() - node.getParent().getParent().getLoc().getNodeX();
        int tmpY = node.getLoc().getNodeY() - node.getParent().getParent().getLoc().getNodeY();
        if (Math.abs(tmpX) == Math.abs(tmpY)) {
          directionX = tmpX;
          directionY = tmpY;
        } else {
          directionX = node.getLoc().getNodeX() - node.getParent().getLoc().getNodeX();
          directionY = node.getLoc().getNodeY() - node.getParent().getLoc().getNodeY();
        }
      } else {
        directionX = node.getLoc().getNodeX() - node.getParent().getLoc().getNodeX();
        directionY = node.getLoc().getNodeY() - node.getParent().getLoc().getNodeY();
      }

      // only add a new route point if moving direction changes
      if ((directionX != previousDirectionX) || (directionY != previousDirectionY)) {
        previousDirectionX = directionX;
        previousDirectionY = directionY;

        path.addFirst(node.getLoc());
        node.setLoc(null);
      }

      node = node.getParent();
    }

    return path;
  }