示例#1
0
void Router::backtrack(Coordinate *target, Coordinate *source){
  Coordinate *current = target;
  GridPoint currentGridPoint;
  GridPoint neighborGridPoint;
  do{
    currentGridPoint = getGridPointAt(current);
    //mark the route id
    markRoute(current);
    //find the next node

    Coordinate *neighbors = current->GetNeighbors();
    int i;
    //if any of them is the target, stop,
    for (i = 0; i < 4; i++) {
      if(!neighbors[i].InBound(rows, cols)){
        continue;
      }
      neighborGridPoint = getGridPointAt(&neighbors[i]);

      if((neighborGridPoint.StepId < currentGridPoint.StepId && neighborGridPoint.StepId != 0) || neighbors[i].Equals(source)){
        current = &neighbors[i];
        break;
      }
    }
    //repeat until is source reached
  }while(!current->Equals(source));
  //mark the source
  markRoute(source);
}