Skip to content

Commit

Permalink
Merge pull request #486 from eyal0/overlapping_bridges
Browse files Browse the repository at this point in the history
Add a test for overlapping bridges
  • Loading branch information
eyal0 committed Oct 19, 2020
2 parents f2d51ad + 82fe2b4 commit 8f7cbbc
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 91 deletions.
11 changes: 4 additions & 7 deletions outline_bridges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,22 @@ static list<point_type_fp>::const_iterator insertPoint(list<point_type_fp>& path
*/
static vector<size_t> insertBridges(linestring_type_fp& path, const set<size_t>& bridges, double length) {
list<point_type_fp> path_list(path.cbegin(), path.cend());
set<list<point_type_fp>::const_iterator> bridge_pointers;
set<pair<list<point_type_fp>::const_iterator, double>> bridge_pointers;
{
auto p = path_list.cbegin();
size_t i = 0;
for (; p != path_list.cend(); i++, p++) {
if (bridges.count(i) > 0) {
bridge_pointers.insert(p);
bridge_pointers.insert(make_pair(p, bg::distance(path.at(i), path.at(i+1))));
}
}
}

set<list<point_type_fp>::const_iterator> bridge_segments;
for(const auto& bridge_pointer : bridge_pointers) {
auto segment_start = *bridge_pointer;
auto segment_end = *std::next(bridge_pointer);
auto segment_length = bg::distance(segment_start, segment_end);
//Insert the bridges in the path.
auto bridge_start = insertPoint(path_list, bridge_pointer, segment_length/2 - length/2);
auto bridge_end = insertPoint(path_list, bridge_pointer, segment_length/2 + length/2);
auto bridge_start = insertPoint(path_list, bridge_pointer.first, bridge_pointer.second/2 - length/2);
auto bridge_end = insertPoint(path_list, bridge_pointer.first, bridge_pointer.second/2 + length/2);
for (auto seg = bridge_start; seg != bridge_end; seg++) {
if (seg == path_list.cend()) {
seg = path_list.cbegin();
Expand Down
24 changes: 24 additions & 0 deletions outline_bridges_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,28 @@ BOOST_AUTO_TEST_CASE(rectangle) {
BOOST_CHECK_EQUAL(path, expected_path);
}

BOOST_AUTO_TEST_CASE(rectangle4) {
linestring_type_fp path{{0,0}, {0,100}, {10,100}, {10,0}, {0,0}};
auto ret = makeBridges(path, 4, 12);

vector<size_t> expected_ret{0,2,4,5,6,8,10,11,12};
linestring_type_fp expected_path{
{0,0},
{0,1},
{0,44},
{0,56},
{0,99},
{0,100},
{10,100},
{10,99},
{10,56},
{10,44},
{10,1},
{10,0},
{0,0},
};
BOOST_CHECK_EQUAL(ret, expected_ret);
BOOST_CHECK_EQUAL(path, expected_path);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 8f7cbbc

Please sign in to comment.