Skip to content

Commit

Permalink
Remove degenerate paths after trim_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
eyal0 committed Jun 16, 2020
1 parent c858686 commit fcb681b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions trim_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using std::pair;
using std::vector;
using std::multiset;
using std::reverse;
using std::remove_if;

// Returns true if the segment described by the two points is in the
// haystack. Finds reversed segments if the segment is reversible.
Expand Down Expand Up @@ -148,6 +149,14 @@ void trim_paths(vector<pair<linestring_type_fp, bool>>& toolpaths,
ls = reverse_ls;
}
}
toolpaths.erase(
remove_if(
toolpaths.begin(),
toolpaths.end(),
[](pair<linestring_type_fp, bool> const& p) {
return p.first.size() < 2;
}),
toolpaths.cend());
}

} // namespace trim_paths
24 changes: 24 additions & 0 deletions trim_paths_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,29 @@ BOOST_AUTO_TEST_CASE(trim_reversible) {
BOOST_CHECK_EQUAL(paths, expected);
}

BOOST_AUTO_TEST_CASE(directed_square_and_diagonal) {
vector<pair<linestring_type_fp, bool>> paths{
{{{0,0}, {0,5}}, false},
{{{0,5}, {5,5}}, false},
{{{5,5}, {5,0}}, false},
{{{5,0}, {0,0}}, false},
{{{5,5}, {0,0}}, false},
{{{0,0}, {0,5}}, false},
{{{0,5}, {5,5}}, false},
};
vector<pair<linestring_type_fp, bool>> backtracks{
{{{0,0}, {0,5}}, false},
{{{0,5}, {5,5}}, false},
};
trim_paths::trim_paths(paths, backtracks);
vector<pair<linestring_type_fp, bool>> expected{
{{{5,5}, {5,0}}, false},
{{{5,0}, {0,0}}, false},
{{{5,5}, {0,0}}, false},
{{{0,0}, {0,5}}, false},
{{{0,5}, {5,5}}, false},
};
BOOST_CHECK_EQUAL(paths, expected);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit fcb681b

Please sign in to comment.