Пример #1
0
 /**
  * This will traverse from current point to another given "distance" amount using the given
  * method.
  *
  * @param info Current traversal info.
  * @param distanceToTraverse How much to traverse on the path from current point
  * @param method Method of traversal. Use method constants.
  * @param affectRender Shall traversing this mark the points as traversed? If yes then all the
  *     pathnodes being traversed would not be drawn next time. If no, then everying stays the same
  *     for rendering.
  */
 public void traverse(
     TraversePointInfo info, float distanceFromCurPoint, int method, boolean affectRender) {
   if (distanceFromCurPoint == 0) info.setLastTraversedDistance(0);
   if (info == null || nodes.size() == 0) {
     return;
   }
   if (method == METHOD_LEFT) {
     traverseLeft(info, distanceFromCurPoint, method, affectRender);
   } else if (method == METHOD_RIGHT) {
     traverseRight(info, distanceFromCurPoint, method, affectRender);
   }
   //		updateRenderingInfo(distanceFromCurPoint);
   //		if(nodes.getLast() == info.getPathNode() && )
   //			info.initialize(nodes.getLast().getLocation(), nodes.getLast(), 0, 0, this, 0);
 }
Пример #2
0
  public void traverseRight(
      TraversePointInfo info, float distanceFromCurPoint, int method, boolean affectRender) {

    // if info.pathnode is null, then according to mehtod get one of the end path nodes
    if (info.getPathNode() == null) {
      PathNode pt = nodes.getFirst();
      info.initialize(pt.getLocation(), pt, 0, 0, this, 0);

      if (affectRender) pt.setActive(false);
      //			Helper.printKeyVal("info pathnode in null check: ", info.getPathNode().toString());
      return;
    }

    // info.pathnode is not null

    //		Helper.printKeyVal("\n\nCurrent distance: ", info.getDistance());
    //		Helper.println("distance from current point: " + distanceFromCurPoint);
    try {
      float traversedDistance = 0;
      float distanceToTraverse = distanceFromCurPoint + info.getDistance();
      float distance = info.getDistance();

      PathNode t = info.getPathNode();

      while (true) {
        nextNode = t.getNextTraversingNode(method);

        // current is the last node
        if (nextNode == null) {
          if (affectRender) t.setActive(false);
          info.initialize(
              t.getLocation(), t, this.totalDistance, this.totalDistance, this, traversedDistance);
          //					Helper.println("2 Right Return last");
          return;
        }

        if (!nextNode.isActive()) {
          info.setLastTraversedDistance(0);
          return;
        }

        //				Helper.printKeyVal("2 t.linkDistance: ", t.getDistance(method));
        //				Helper.printKeyVal("2 out of distanceToTraverse: ", distanceToTraverse);

        linkDistance = t.getDistance(method);
        if (linkDistance >= distanceToTraverse) {
          traversedDistance += distanceToTraverse;

          //					Helper.printKeyVal("\n3 traveresed distance: ", "" + traversedDistance);
          //					Helper.printKeyVal("3 out of : ", distanceToTraverse);

          Point retP = t.getPointAtDistance(distanceToTraverse, method);
          if (affectRender) t.setActive(false);
          //					Helper.printKeyVal("getPointAtDistance() returned point: ", retP.toString());

          //					Helper.printKeyVal("Right traverse Last distance: ", traversedDistance +
          // distanceToTraverse-info.getDistance());
          info.initialize(
              retP,
              t,
              distanceToTraverse,
              info.getTotalDistanceInPath() + distanceFromCurPoint,
              this,
              distanceFromCurPoint);
          //					Helper.println("2 Return good");
          return;
        }
        traversedDistance += linkDistance;

        distanceToTraverse = distanceToTraverse - linkDistance;
        distance = 0;

        t = nextNode;
        //				Helper.printKeyVal("Switching to new node: ", t.toString());
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #3
0
  public void traverseLeft(
      TraversePointInfo info, float distanceFromCurPoint, int method, boolean affectRender) {
    PathNode t;

    float dtv;
    float dis;

    /**
     * **************************************************
     *
     * <p><-----dtv-----> ********************* <-- t
     *
     * <p>*************************************************
     */
    t = info.getPathNode();
    if (t == null) {
      t = info.getPath().nodes.getLast();
      info.initialize(t.getLocation(), t, t.getLeftDistance(), totalDistance, this, 0);
      if (affectRender) t.setActive(false);
      //			Helper.println("Return from: " + t.getLocation().toString());
      return;
    }

    //		Helper.printKeyVal("Step 1: DFCP", distanceFromCurPoint);
    //		Helper.printKeyVal("Step 1: current distance", info.getDistance());

    if (t.getNextNode() == null) dtv = distanceFromCurPoint;
    else {
      if (info.getDistance() > 0) {
        dtv = t.getRightDistance() - info.getDistance() + distanceFromCurPoint;
        //				if(affectRender)
        //					t.setActive(false);
        t = t.getNextNode();
      } else {
        dtv = distanceFromCurPoint;
      }
    }

    //		Helper.printKeyVal("Step 1: DTV", dtv);
    //		Helper.printKeyVal("Step 1: t.getLeftDistance()", t.getLeftDistance());
    while (true) {
      if (dtv > t.getLeftDistance()) {
        //				Helper.printKeyVal("\nStep 2: DTV", dtv);
        //				Helper.printKeyVal("Step 2: t.getLeftDistance(): ", t.getLeftDistance());
        if (t.getPrevNode() == null) {
          if (affectRender) t.setActive(false);
          info.initialize(
              t.getLocation(),
              t,
              0,
              info.getTotalDistanceInPath() - (distanceFromCurPoint - dtv),
              this,
              distanceFromCurPoint - dtv);
          //					Helper.printKeyVal("Retrun: 1: ", info.getDistance());
          return;
        }

        dtv = dtv - t.getLeftDistance();
        if (affectRender) t.setActive(false);
        t = t.getPrevNode();

        if (!t.isActive()) {
          info.setLastTraversedDistance(0);
          return;
        }
        //				Helper.printKeyVal("Step 2: New DTV", dtv);
        //				Helper.printKeyVal("Step 2: Switched to new Node: ", t.getLocation().toString());
        //				Helper.printKeyVal("Step 2: New Node index: ", info.getPath().nodes.indexOf(t));
      } else break;
    }
    /** ************************************************* */
    Point p = t.getPointAtDistance(dtv, Path.METHOD_LEFT);
    info.initialize(
        p,
        t.getPrevNode(),
        t.getLeftDistance() - dtv,
        info.getTotalDistanceInPath() - distanceFromCurPoint,
        this,
        distanceFromCurPoint);
    //		t.setActive(false);

    //		Helper.printKeyVal("Step 2: New Node index: ", info.getPath().nodes.indexOf(t));
    //		Helper.printKeyVal("Step 2: New Node index: ",
    // info.getPath().nodes.indexOf(t.getPrevNode()));

    //		Helper.printKeyVal("Retruning point: ", p.toString());
    //		Helper.printKeyVal("Retrun: 2", info.getDistance());
  }