Skip to content

Commit

Permalink
Make the keep_out mandatory in path finding.
Browse files Browse the repository at this point in the history
An empty keep_out will behave like a missing one anyway.
  • Loading branch information
eyal0 committed Jul 3, 2020
1 parent 68cca9d commit 1879336
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
12 changes: 4 additions & 8 deletions path_finding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ using std::make_shared;
class PathFindingSurface {
public:
PathFindingSurface(const multi_polygon_type_fp& keep_in,
const optional<multi_polygon_type_fp>& keep_out,
const coordinate_type_fp tolerance) {
const multi_polygon_type_fp& keep_out,
coordinate_type_fp tolerance) {
multi_polygon_type_fp total_keep_in;
total_keep_in = keep_in;
// By here, total_keep_in_grown is ready.
if (keep_out) {
total_keep_in = total_keep_in - *keep_out;
}
total_keep_in = total_keep_in - keep_out;

all_vertices.clear();
for (const auto& poly : total_keep_in) {
for (const auto& point : poly.outer()) {
all_vertices.push_back(point);
Expand Down Expand Up @@ -362,7 +358,7 @@ struct AstarGoalVisitor : public boost::default_astar_visitor {

const std::shared_ptr<const PathFindingSurface> create_path_finding_surface(
const multi_polygon_type_fp& keep_in,
const boost::optional<multi_polygon_type_fp>& keep_out,
const multi_polygon_type_fp& keep_out,
const coordinate_type_fp tolerance) {
boost::function_requires<boost::VertexListGraphConcept<PathSurface>>();
boost::function_requires<boost::IncidenceGraphConcept<PathSurface>>();
Expand Down
2 changes: 1 addition & 1 deletion path_finding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef std::function<bool(const point_type_fp& target, const coordinate_type_fp
// small epsilon value.
const std::shared_ptr<const PathFindingSurface> create_path_finding_surface(
const multi_polygon_type_fp& keep_in,
const boost::optional<multi_polygon_type_fp>& keep_out,
const multi_polygon_type_fp& keep_out,
const coordinate_type_fp tolerance);


Expand Down
10 changes: 5 additions & 5 deletions path_finding_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BOOST_AUTO_TEST_CASE(simple) {
bg::expand(bounding_box, point_type_fp(100, 100));
multi_polygon_type_fp keep_in;
bg::convert(bounding_box, keep_in);
auto surface = create_path_finding_surface(keep_in, boost::none, 0.1);
auto surface = create_path_finding_surface(keep_in, multi_polygon_type_fp(), 0.1);
auto ret = find_path(surface, point_type_fp(0,0), point_type_fp(1,1), nullptr);
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
Expand All @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(box) {
bg::expand(bounding_box, point_type_fp(100, 100));
multi_polygon_type_fp keep_in;
bg::convert(bounding_box, keep_in);
auto surface = create_path_finding_surface(keep_in, boost::make_optional(keep_out), 0.1);
auto surface = create_path_finding_surface(keep_in, keep_out, 0.1);
auto ret = find_path(surface, point_type_fp(0,0), point_type_fp(10,10), nullptr);

linestring_type_fp expected;
Expand All @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(unreachable_box) {
bg::expand(bounding_box, point_type_fp(100, 100));
multi_polygon_type_fp keep_in;
bg::convert(bounding_box, keep_in);
auto surface = create_path_finding_surface(keep_in, boost::make_optional(keep_out), 0.1);
auto surface = create_path_finding_surface(keep_in, keep_out, 0.1);
auto ret = find_path(surface, point_type_fp(0,0), point_type_fp(5,5), nullptr);

BOOST_CHECK_EQUAL(ret, boost::none);
Expand All @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(reuse_surface) {
bg::expand(bounding_box, point_type_fp(100, 100));
multi_polygon_type_fp keep_in;
bg::convert(bounding_box, keep_in);
auto surface = create_path_finding_surface(keep_in, boost::make_optional(keep_out), 0.1);
auto surface = create_path_finding_surface(keep_in, keep_out, 0.1);
auto ret = find_path(surface, point_type_fp(0,0), point_type_fp(5,5), nullptr);
BOOST_CHECK_EQUAL(ret, boost::none);

Expand All @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(u_shape) {
poly.outer() = u_shape;
multi_polygon_type_fp keep_in;
keep_in.push_back(poly);
auto surface = create_path_finding_surface(keep_in, boost::none, 0.1);
auto surface = create_path_finding_surface(keep_in, multi_polygon_type_fp(), 0.1);
auto ret = find_path(surface, point_type_fp(1,9), point_type_fp(9,9), nullptr);

linestring_type_fp expected;
Expand Down
2 changes: 1 addition & 1 deletion surface_vectorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ vector<pair<linestring_type_fp, bool>> Surface_vectorial::get_single_toolpath(
diameter, overlap, extra_passes + 1, do_voronoi, mill->offset);
multi_polygon_type_fp keep_in;
keep_in.push_back(current_voronoi);
optional<multi_polygon_type_fp> keep_out;
multi_polygon_type_fp keep_out;
if (current_trace) {
keep_out = bg_helpers::buffer(*current_trace, diameter/2 + mill->offset);
}
Expand Down

0 comments on commit 1879336

Please sign in to comment.