Skip to content

Commit

Permalink
Add GiveUp exception and include chrono
Browse files Browse the repository at this point in the history
  • Loading branch information
eyal0 committed Feb 17, 2019
1 parent 542e019 commit 45dfa0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions path_finding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ boost::optional<linestring_type_fp> find_path(
bg::append(result, path_surface->get_point_by_index(0));
bg::reverse(result);
return make_optional(result);
} catch (GiveUp g) {
return boost::none;
}
return boost::none;
}
Expand Down
2 changes: 2 additions & 0 deletions path_finding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace path_finding {

class PathFindingSurface;

struct GiveUp {};

// Given a target location and a potential path length to get there, determine
// if it still makes sense to follow the path. Return true if it does,
// otherwise false.
Expand Down
5 changes: 4 additions & 1 deletion surface_vectorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ using std::vector;
using std::cerr;
using std::endl;

#include <chrono>

#include <utility>
using std::pair;
using std::make_pair;
Expand Down Expand Up @@ -324,8 +326,9 @@ optional<linestring_type_fp> do_milling(
auto t1 = system_clock::now();
path_finding::PathLimiter path_limiter =
[&](const point_type_fp& waypoint, const coordinate_type_fp& length_so_far) -> bool {
tries++;
if (system_clock::now() - t1 > seconds(1)) {
return true;
throw path_finding::GiveUp();
}
// Return true if this path needs to be clipped. The distance from
// a to target so far is length. At best, we'll have a stright
Expand Down

0 comments on commit 45dfa0f

Please sign in to comment.