예제 #1
0
파일: Paths.java 프로젝트: jpollo/rcrss
  private Path getNearestPath(Road road, List<Path> paths) {
    int range = 10000;
    int minDistance = Integer.MAX_VALUE;
    EntityID nearestPath = null;

    while (nearestPath == null) {
      Collection<StandardEntity> entities = world.getObjectsInRange(road, range);

      for (StandardEntity entity : entities) {
        if (entity instanceof Road) {
          EntityID pathId = roadHelper.getPathId(entity.getID());

          if (pathId != null) {
            int distance = Util.distance((Area) entity, road);
            if (distance < minDistance) {
              nearestPath = pathId;
              minDistance = distance;
            }
          }
        }
      }
      range += 10000;
    }

    for (Path path : paths) {
      if (path.getId().equals(nearestPath)) {
        return path;
      }
    }
    return null;
  }