Skip to content

Commit

Permalink
fix: Specific boost::make_optional because it clashes with std::make_…
Browse files Browse the repository at this point in the history
…optional
  • Loading branch information
eyal0 committed Nov 4, 2021
1 parent 7491faa commit 01cd18a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
2 changes: 1 addition & 1 deletion path_finding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ optional<linestring_type_fp> PathFindingSurface::find_path(
open_set.pop();
if (current == goal) {
// We're done.
return make_optional(build_path(current, came_from));
return boost::make_optional(build_path(current, came_from));
}
if (closed_set.count(current) > 0) {
// Skip this because we already "removed it", sort of.
Expand Down
65 changes: 32 additions & 33 deletions path_finding_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "bg_helpers.hpp"

#include <boost/optional.hpp>
using boost::make_optional;

#include <boost/optional/optional_io.hpp>

Expand Down Expand Up @@ -126,7 +125,7 @@ BOOST_AUTO_TEST_CASE(box) {
multi_polygon_type_fp mp;
box_type_fp box{point_type_fp{0,0}, {10,10}};
bg::convert(box, mp);
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{1,1}, mp), make_optional(MPRingIndices({{0, {0}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{1,1}, mp), boost::make_optional(MPRingIndices({{0, {0}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{11,11}, mp), boost::none);
}

Expand All @@ -149,10 +148,10 @@ BOOST_AUTO_TEST_CASE(doughnuts) {
bg::convert(hole, hole_mp);
mp = mp - hole_mp;

BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{1,1}, mp), make_optional(MPRingIndices({{0, {0, 1}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{1,1}, mp), boost::make_optional(MPRingIndices({{0, {0, 1}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{11,11}, mp), boost::none);
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{5,5}, mp), boost::none);
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{21,1}, mp), make_optional(MPRingIndices({{1, {0, 1, 2}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{21,1}, mp), boost::make_optional(MPRingIndices({{1, {0, 1, 2}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{23.5,3.5}, mp), boost::none);
}

Expand All @@ -171,9 +170,9 @@ BOOST_AUTO_TEST_CASE(nested_doughnuts) {
hole = {point_type_fp{30,30}, {70,70}};
bg::convert(hole, hole_mp);
mp = mp - hole_mp;
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{1,1}, mp), make_optional(MPRingIndices({{0, {0, 1}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{1,1}, mp), boost::make_optional(MPRingIndices({{0, {0, 1}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{11,11}, mp), boost::none);
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{21,21}, mp), make_optional(MPRingIndices({{1, {0, 1}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{21,21}, mp), boost::make_optional(MPRingIndices({{1, {0, 1}}})));
BOOST_CHECK_EQUAL(inside_multipolygon(point_type_fp{31,31}, mp), boost::none);
}

Expand All @@ -190,7 +189,7 @@ BOOST_AUTO_TEST_CASE(box) {
box_type_fp box{point_type_fp{0,0}, {10,10}};
bg::convert(box, mp);
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{1,1}, mp), boost::none);
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{11,11}, mp), make_optional(MPRingIndices({{0, {0}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{11,11}, mp), boost::make_optional(MPRingIndices({{0, {0}}})));
}

BOOST_AUTO_TEST_CASE(doughnuts) {
Expand All @@ -213,10 +212,10 @@ BOOST_AUTO_TEST_CASE(doughnuts) {
mp = mp - hole_mp;

BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{1,1}, mp), boost::none);
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{11,11}, mp), make_optional(MPRingIndices({{0, {0}}, {1, {0}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{5,5}, mp), make_optional(MPRingIndices({{0, {1}}, {1, {0}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{11,11}, mp), boost::make_optional(MPRingIndices({{0, {0}}, {1, {0}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{5,5}, mp), boost::make_optional(MPRingIndices({{0, {1}}, {1, {0}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{21,1}, mp), boost::none);
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{23.5,3.5}, mp), make_optional(MPRingIndices({{0, {0}}, {1, {1}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{23.5,3.5}, mp), boost::make_optional(MPRingIndices({{0, {0}}, {1, {1}}})));
}

BOOST_AUTO_TEST_CASE(nested_doughnuts) {
Expand All @@ -236,9 +235,9 @@ BOOST_AUTO_TEST_CASE(nested_doughnuts) {
mp = mp - hole_mp;

BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{1,1}, mp), boost::none);
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{11,11}, mp), make_optional(MPRingIndices({{0, {1}}, {1, {0}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{11,11}, mp), boost::make_optional(MPRingIndices({{0, {1}}, {1, {0}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{21,21}, mp), boost::none);
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{31,31}, mp), make_optional(MPRingIndices({{0, {1}}, {1, {1}}})));
BOOST_CHECK_EQUAL(outside_multipolygon(point_type_fp{31,31}, mp), boost::make_optional(MPRingIndices({{0, {1}}, {1, {1}}})));
}

BOOST_AUTO_TEST_SUITE_END() // outside_multipolygon_tests
Expand All @@ -247,16 +246,16 @@ BOOST_AUTO_TEST_SUITE(nested_multipolygon_type_fp)

BOOST_AUTO_TEST_CASE(open_space) {
auto surface = PathFindingSurface(boost::none, multi_polygon_type_fp(), 5);
BOOST_CHECK_EQUAL(surface.in_surface({1,1}), make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({1,1}), boost::make_optional(size_t(0)));
}

BOOST_AUTO_TEST_CASE(barbell) {
multi_polygon_type_fp barbell{{{{0,0}, {0,100}, {40,100}, {40,2}, {60,2},
{60,100}, {100,100}, {100,0}, {0,0}}}};
auto surface = PathFindingSurface(boost::none, barbell, 5);
BOOST_CHECK_EQUAL(surface.in_surface({1,1}), make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({1,1}), boost::make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({6,6}), boost::none);
BOOST_CHECK_EQUAL(surface.in_surface({-10,-10}), make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({-10,-10}), boost::make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({10,10}), boost::none);
}

Expand All @@ -266,12 +265,12 @@ BOOST_AUTO_TEST_CASE(almost_doughnut) {
{51,80}, {51,100}, {100,100},
{100,0}, {0,0}}}};
auto surface = PathFindingSurface(almost_doughnut, multi_polygon_type_fp(), 5);
BOOST_CHECK_EQUAL(surface.in_surface({1,1}), make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({6,6}), make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({1,1}), boost::make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({6,6}), boost::make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({-10,-10}), boost::none);
BOOST_CHECK_EQUAL(surface.in_surface({50,1}), make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({50,1}), boost::make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({50,50}), boost::none);
BOOST_CHECK_EQUAL(surface.in_surface({50,90}), make_optional(size_t(0)));
BOOST_CHECK_EQUAL(surface.in_surface({50,90}), boost::make_optional(size_t(0)));
}

BOOST_AUTO_TEST_SUITE_END() // nested_multipolygon_type_fp
Expand All @@ -285,7 +284,7 @@ BOOST_AUTO_TEST_CASE(open_space) {
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(1, 1));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(simple) {
Expand All @@ -299,7 +298,7 @@ BOOST_AUTO_TEST_CASE(simple) {
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(1, 1));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(simple_limit0) {
Expand All @@ -309,7 +308,7 @@ BOOST_AUTO_TEST_CASE(simple_limit0) {
bg::convert(bounding_box, keep_in);
auto surface = PathFindingSurface(keep_in, multi_polygon_type_fp(), 0.1);
auto ret = surface.find_path(point_type_fp(0,0), point_type_fp(1,1),
infinity, make_optional(size_t(0)));
infinity, boost::make_optional(size_t(0)));
BOOST_CHECK_EQUAL(ret, boost::none);
}

Expand All @@ -320,11 +319,11 @@ BOOST_AUTO_TEST_CASE(simple_limit1) {
bg::convert(bounding_box, keep_in);
auto surface = PathFindingSurface(keep_in, multi_polygon_type_fp(), 0.1);
auto ret = surface.find_path(point_type_fp(0,0), point_type_fp(1,1),
infinity, make_optional(size_t(1)));
infinity, boost::make_optional(size_t(1)));
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(1, 1));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(simple_limit_length200) {
Expand All @@ -338,7 +337,7 @@ BOOST_AUTO_TEST_CASE(simple_limit_length200) {
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(100, 100));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(simple_limit_length100) {
Expand Down Expand Up @@ -368,7 +367,7 @@ BOOST_AUTO_TEST_CASE(hole) {
linestring_type_fp expected;
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(1, 1));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(hole_unreachable) {
Expand Down Expand Up @@ -410,7 +409,7 @@ BOOST_AUTO_TEST_CASE(box) {
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(3, 7));
expected.push_back(point_type_fp(10, 10));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(box_no_keep_in) {
Expand All @@ -434,7 +433,7 @@ BOOST_AUTO_TEST_CASE(box_no_keep_in) {
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(3, 7));
expected.push_back(point_type_fp(10, 10));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(unreachable_box) {
Expand Down Expand Up @@ -485,7 +484,7 @@ BOOST_AUTO_TEST_CASE(reuse_surface) {
expected.push_back(point_type_fp(0, 0));
expected.push_back(point_type_fp(3, 7));
expected.push_back(point_type_fp(10, 10));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(u_shape) {
Expand All @@ -512,7 +511,7 @@ BOOST_AUTO_TEST_CASE(u_shape) {
expected.push_back(point_type_fp(3, 3));
expected.push_back(point_type_fp(7, 3));
expected.push_back(point_type_fp(9, 9));
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(doughnut) {
Expand All @@ -526,7 +525,7 @@ BOOST_AUTO_TEST_CASE(doughnut) {
infinity, boost::none);

linestring_type_fp expected{{10, 10},{30, 70},{51, 80},{90, 90}};
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_CASE(barbell_search) {
Expand All @@ -542,7 +541,7 @@ BOOST_AUTO_TEST_CASE(barbell_search_limit) {
multi_polygon_type_fp barbell{{{{0,0}, {0,50}, {40,50}, {40,2}, {60,2},
{60,50}, {100,50}, {100,0}, {0,0}}}};
auto surface = PathFindingSurface(boost::none, barbell, 5);
BOOST_CHECK_EQUAL(surface.find_path({-10,-10},{110,60},infinity, make_optional(size_t(2))),
BOOST_CHECK_EQUAL(surface.find_path({-10,-10},{110,60},infinity, boost::make_optional(size_t(2))),
boost::none);
}

Expand All @@ -563,7 +562,7 @@ BOOST_AUTO_TEST_CASE(u_shape_keep_out) {
auto ret = surface.find_path({5,5}, point_type_fp(-1,-1),
infinity, boost::none);
linestring_type_fp expected{{5,5},{3,10},{0,10},{-1,-1}};
BOOST_CHECK_EQUAL(ret, make_optional(expected));
BOOST_CHECK_EQUAL(ret, boost::make_optional(expected));
}

BOOST_AUTO_TEST_SUITE_END()
14 changes: 7 additions & 7 deletions surface_vectorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ Surface_vectorial::PathFinder Surface_vectorial::make_path_finder(
const double max_g1_distance = std::isinf(mill->backtrack) ?
g0_time * horizontalG1speed :
mill->backtrack*g0_time / (1 + mill->backtrack/horizontalG1speed);
return path_finding_surface.find_path(a, b, max_g1_distance, make_optional(mill->path_finding_limit));
return path_finding_surface.find_path(a, b, max_g1_distance, boost::make_optional(mill->path_finding_limit));
};
}

Expand Down Expand Up @@ -839,7 +839,7 @@ vector<pair<linestring_type_fp, bool>> Surface_vectorial::get_single_toolpath(
if (!reverse_spikes) {
if (polygon_index > 0) {
spike_offset = diameter - overlap;
spikes_keep_out = make_optional(multi_polygon_type_fp{polygons[polygon_index - 1]});
spikes_keep_out = boost::make_optional(multi_polygon_type_fp{polygons[polygon_index - 1]});
} else {
spike_offset = 0;
}
Expand All @@ -850,17 +850,17 @@ vector<pair<linestring_type_fp, bool>> Surface_vectorial::get_single_toolpath(
if (extra_passes % 2 == 0) {
if (polygon_index + 1 < polygons.size()) {
spike_offset = diameter - overlap;
spikes_keep_in = make_optional(multi_polygon_type_fp{polygons[polygon_index + 1]});
spikes_keep_in = boost::make_optional(multi_polygon_type_fp{polygons[polygon_index + 1]});
} else {
spike_offset = 0;
}
} else {
if (polygon_index + 1 < polygons.size()) {
spike_offset = diameter - overlap;
spikes_keep_in = make_optional(multi_polygon_type_fp{polygons[polygon_index + 1]});
spikes_keep_in = boost::make_optional(multi_polygon_type_fp{polygons[polygon_index + 1]});
} else {
spike_offset = (diameter - overlap)/2;
spikes_keep_in = make_optional(multi_polygon_type_fp{current_voronoi});
spikes_keep_in = boost::make_optional(multi_polygon_type_fp{current_voronoi});
}
}
}
Expand Down Expand Up @@ -985,7 +985,7 @@ vector<pair<coordinate_type_fp, multi_linestring_type_fp>> Surface_vectorial::ge
for (const auto& poly : vectorial_surface->first) {
keep_outs.push_back(bg_helpers::buffer(poly, tool_diameter/2 + isolator->offset));
}
const auto path_finding_surface = path_finding::PathFindingSurface(mask ? make_optional(mask->vectorial_surface->first) : boost::none, sum(keep_outs), isolator->tolerance);
const auto path_finding_surface = path_finding::PathFindingSurface(mask ? boost::make_optional(mask->vectorial_surface->first) : boost::none, sum(keep_outs), isolator->tolerance);
for (size_t trace_index = 0; trace_index < trace_count; trace_index++) {
multi_polygon_type_fp already_milled_shrunk =
bg_helpers::buffer(already_milled[trace_index], -tool_diameter/2 + tolerance);
Expand Down Expand Up @@ -1033,7 +1033,7 @@ vector<pair<coordinate_type_fp, multi_linestring_type_fp>> Surface_vectorial::ge
const string tool_suffix = tool_count > 1 ? "_" + std::to_string(tool_index) : "";
write_svgs(tool_suffix, tool_diameter, new_trace_toolpaths, isolator->tolerance, tool_index == tool_count - 1);
auto new_toolpath = flatten(new_trace_toolpaths);
multi_linestring_type_fp combined_toolpath = post_process_toolpath(mill, make_optional(&path_finding_surface), new_toolpath);
multi_linestring_type_fp combined_toolpath = post_process_toolpath(mill, boost::make_optional(&path_finding_surface), new_toolpath);
write_svgs("_final" + tool_suffix, tool_diameter, combined_toolpath, isolator->tolerance, tool_index == tool_count - 1);
results[tool_index] = make_pair(tool_diameter, mirror_toolpath(combined_toolpath, mirror, ymirror));
}
Expand Down

0 comments on commit 01cd18a

Please sign in to comment.