Skip to content

Commit

Permalink
Merge pull request #484 from eyal0/avoid_bridges_on_corners
Browse files Browse the repository at this point in the history
Only use small parts of the edge as bridges if necessary
  • Loading branch information
eyal0 committed Oct 19, 2020
2 parents 4a8db52 + 016a291 commit f2d51ad
Show file tree
Hide file tree
Showing 13 changed files with 2,840 additions and 2,944 deletions.
18 changes: 16 additions & 2 deletions outline_bridges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,32 @@ static inline vector<double> min_distance_to_clique(point_type_fp point,
*
* Returns the positions in path of the segments that need to be modified.
*/
static set<size_t> findBridgeSegments(const linestring_type_fp& path, size_t number) {
static set<size_t> findBridgeSegments(const linestring_type_fp& path, size_t number, double length) {
if (number < 1) {
return {};
}

// All the potential bridge segments and their locations.
map<size_t, point_type_fp> candidates;
for (size_t i = 0; i < path.size() - 1; i++) {
auto current_distance = bg::distance(path.at(i), path.at(i+1));
if (current_distance < length) {
continue;
}
candidates[i] = intermediatePoint(path.at(i),
path.at(i + 1),
0.5);
}
if (candidates.size() < number) {
// We didn't find enough places to put bridges with the length
// restriction so try again but this time allow small edges, too.
candidates.clear();
for (size_t i = 0; i < path.size() - 1; i++) {
candidates[i] = intermediatePoint(path.at(i),
path.at(i + 1),
0.5);
}
}

// Make a set of bridges that we will output. They must be unique. For now
// just take the first few.
Expand Down Expand Up @@ -262,7 +276,7 @@ static set<size_t> findBridgeSegments(const linestring_type_fp& path, size_t num
}

vector<size_t> makeBridges(linestring_type_fp& path, size_t number, double length) {
return insertBridges(path, findBridgeSegments(path, number), length);
return insertBridges(path, findBridgeSegments(path, number, length), length);
}

} // namespace outline_bridges
10 changes: 5 additions & 5 deletions outline_bridges_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ BOOST_AUTO_TEST_CASE(rectangle) {
linestring_type_fp path{{0,0}, {0,1}, {10,1}, {10,0}, {0,0}};
auto ret = makeBridges(path, 2, 2);

vector<size_t> expected_ret{0,1,3,4,5,7,8};
vector<size_t> expected_ret{2,6};
linestring_type_fp expected_path{
{0,0},
{0,1},
{0.5,1},
{9.5,1},
{4,1},
{6,1},
{10,1},
{10,0},
{9.5,0},
{0.5,0},
{6,0},
{4,0},
{0,0},
};
BOOST_CHECK_EQUAL(ret, expected_ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ G00 X-0.60000 Y0.00000 ( rapid move to begin. )
G01 Z-0.66667 F12.50000 ( plunge. )
G04 P0 ( dwell for no time -- G64 should not smooth over this point )
G01 F25.00000
G01 X-0.60000 Y10.16000
G01 X-0.59685 Y10.19198
G01 X-0.60000 Y4.23000
G00 Z-0.50000
G01 X-0.60000 Y5.93000
G01 Z-0.66667 F12.50000
G01 F25.00000
G01 X-0.60000 Y10.16000
G01 X-0.58847 Y10.27704
G01 X-0.55430 Y10.38959
G01 X-0.49888 Y10.49332
Expand All @@ -36,11 +39,11 @@ G01 X-0.33332 Y10.65888
G01 X-0.22959 Y10.71430
G01 X-0.11704 Y10.74847
G01 X0.00000 Y10.76000
G01 X0.79120 Y10.76000
G01 X6.77000 Y10.76000
G00 Z-0.50000
G01 X8.47000 Y10.76000
G01 Z-0.66667 F12.50000
G01 F25.00000
G01 X14.44880 Y10.76000
G00 Z-0.50000
G01 X15.24000 Y10.76000
G01 X15.35704 Y10.74847
G01 X15.46959 Y10.71430
Expand All @@ -49,13 +52,13 @@ G01 X15.66426 Y10.58426
G01 X15.73888 Y10.49332
G01 X15.79430 Y10.38959
G01 X15.82847 Y10.27704
G01 X15.83685 Y10.19198
G01 X15.84000 Y10.16000
G01 X15.84000 Y5.93000
G00 Z-0.50000
G01 X15.84000 Y4.23000
G01 Z-0.66667 F12.50000
G01 F25.00000
G01 X15.84000 Y10.16000
G01 X15.84000 Y0.00000
G01 X15.83685 Y-0.03198
G00 Z-0.50000
G01 X15.82847 Y-0.11704
G01 X15.79430 Y-0.22959
G01 X15.73888 Y-0.33332
Expand All @@ -64,11 +67,11 @@ G01 X15.57332 Y-0.49888
G01 X15.46959 Y-0.55430
G01 X15.35704 Y-0.58847
G01 X15.24000 Y-0.60000
G01 X14.44880 Y-0.60000
G01 X8.47000 Y-0.60000
G00 Z-0.50000
G01 X6.77000 Y-0.60000
G01 Z-0.66667 F12.50000
G01 F25.00000
G01 X0.79120 Y-0.60000
G00 Z-0.50000
G01 X0.00000 Y-0.60000
G01 X-0.11704 Y-0.58847
G01 X-0.22959 Y-0.55430
Expand All @@ -77,16 +80,16 @@ G01 X-0.42426 Y-0.42426
G01 X-0.49888 Y-0.33332
G01 X-0.55430 Y-0.22959
G01 X-0.58847 Y-0.11704
G01 X-0.59685 Y-0.03198
G01 Z-0.66667 F12.50000
G01 F25.00000
G01 X-0.60000 Y0.00000
G01 Z-1.33333 F12.50000 ( plunge. )
G04 P0 ( dwell for no time -- G64 should not smooth over this point )
G01 F25.00000
G01 X-0.60000 Y10.16000
G01 X-0.59685 Y10.19198
G01 X-0.60000 Y4.23000
G00 Z-0.50000
G01 X-0.60000 Y5.93000
G01 Z-1.33333 F12.50000
G01 F25.00000
G01 X-0.60000 Y10.16000
G01 X-0.58847 Y10.27704
G01 X-0.55430 Y10.38959
G01 X-0.49888 Y10.49332
Expand All @@ -95,11 +98,11 @@ G01 X-0.33332 Y10.65888
G01 X-0.22959 Y10.71430
G01 X-0.11704 Y10.74847
G01 X0.00000 Y10.76000
G01 X0.79120 Y10.76000
G01 X6.77000 Y10.76000
G00 Z-0.50000
G01 X8.47000 Y10.76000
G01 Z-1.33333 F12.50000
G01 F25.00000
G01 X14.44880 Y10.76000
G00 Z-0.50000
G01 X15.24000 Y10.76000
G01 X15.35704 Y10.74847
G01 X15.46959 Y10.71430
Expand All @@ -108,13 +111,13 @@ G01 X15.66426 Y10.58426
G01 X15.73888 Y10.49332
G01 X15.79430 Y10.38959
G01 X15.82847 Y10.27704
G01 X15.83685 Y10.19198
G01 X15.84000 Y10.16000
G01 X15.84000 Y5.93000
G00 Z-0.50000
G01 X15.84000 Y4.23000
G01 Z-1.33333 F12.50000
G01 F25.00000
G01 X15.84000 Y10.16000
G01 X15.84000 Y0.00000
G01 X15.83685 Y-0.03198
G00 Z-0.50000
G01 X15.82847 Y-0.11704
G01 X15.79430 Y-0.22959
G01 X15.73888 Y-0.33332
Expand All @@ -123,11 +126,11 @@ G01 X15.57332 Y-0.49888
G01 X15.46959 Y-0.55430
G01 X15.35704 Y-0.58847
G01 X15.24000 Y-0.60000
G01 X14.44880 Y-0.60000
G01 X8.47000 Y-0.60000
G00 Z-0.50000
G01 X6.77000 Y-0.60000
G01 Z-1.33333 F12.50000
G01 F25.00000
G01 X0.79120 Y-0.60000
G00 Z-0.50000
G01 X0.00000 Y-0.60000
G01 X-0.11704 Y-0.58847
G01 X-0.22959 Y-0.55430
Expand All @@ -136,16 +139,16 @@ G01 X-0.42426 Y-0.42426
G01 X-0.49888 Y-0.33332
G01 X-0.55430 Y-0.22959
G01 X-0.58847 Y-0.11704
G01 X-0.59685 Y-0.03198
G01 Z-1.33333 F12.50000
G01 F25.00000
G01 X-0.60000 Y0.00000
G01 Z-2.00000 F12.50000 ( plunge. )
G04 P0 ( dwell for no time -- G64 should not smooth over this point )
G01 F25.00000
G01 X-0.60000 Y10.16000
G01 X-0.59685 Y10.19198
G01 X-0.60000 Y4.23000
G00 Z-0.50000
G01 X-0.60000 Y5.93000
G01 Z-2.00000 F12.50000
G01 F25.00000
G01 X-0.60000 Y10.16000
G01 X-0.58847 Y10.27704
G01 X-0.55430 Y10.38959
G01 X-0.49888 Y10.49332
Expand All @@ -154,11 +157,11 @@ G01 X-0.33332 Y10.65888
G01 X-0.22959 Y10.71430
G01 X-0.11704 Y10.74847
G01 X0.00000 Y10.76000
G01 X0.79120 Y10.76000
G01 X6.77000 Y10.76000
G00 Z-0.50000
G01 X8.47000 Y10.76000
G01 Z-2.00000 F12.50000
G01 F25.00000
G01 X14.44880 Y10.76000
G00 Z-0.50000
G01 X15.24000 Y10.76000
G01 X15.35704 Y10.74847
G01 X15.46959 Y10.71430
Expand All @@ -167,13 +170,13 @@ G01 X15.66426 Y10.58426
G01 X15.73888 Y10.49332
G01 X15.79430 Y10.38959
G01 X15.82847 Y10.27704
G01 X15.83685 Y10.19198
G01 X15.84000 Y10.16000
G01 X15.84000 Y5.93000
G00 Z-0.50000
G01 X15.84000 Y4.23000
G01 Z-2.00000 F12.50000
G01 F25.00000
G01 X15.84000 Y10.16000
G01 X15.84000 Y0.00000
G01 X15.83685 Y-0.03198
G00 Z-0.50000
G01 X15.82847 Y-0.11704
G01 X15.79430 Y-0.22959
G01 X15.73888 Y-0.33332
Expand All @@ -182,11 +185,11 @@ G01 X15.57332 Y-0.49888
G01 X15.46959 Y-0.55430
G01 X15.35704 Y-0.58847
G01 X15.24000 Y-0.60000
G01 X14.44880 Y-0.60000
G01 X8.47000 Y-0.60000
G00 Z-0.50000
G01 X6.77000 Y-0.60000
G01 Z-2.00000 F12.50000
G01 F25.00000
G01 X0.79120 Y-0.60000
G00 Z-0.50000
G01 X0.00000 Y-0.60000
G01 X-0.11704 Y-0.58847
G01 X-0.22959 Y-0.55430
Expand All @@ -195,9 +198,6 @@ G01 X-0.42426 Y-0.42426
G01 X-0.49888 Y-0.33332
G01 X-0.55430 Y-0.22959
G01 X-0.58847 Y-0.11704
G01 X-0.59685 Y-0.03198
G01 Z-2.00000 F12.50000
G01 F25.00000
G01 X-0.60000 Y0.00000

G04 P0 ( dwell for no time -- G64 should not smooth over this point )
Expand Down
Loading

0 comments on commit f2d51ad

Please sign in to comment.