Skip to content

Commit

Permalink
Use xor in simplify cutins
Browse files Browse the repository at this point in the history
  • Loading branch information
eyal0 committed Feb 3, 2021
1 parent a94a11d commit 246bc23
Show file tree
Hide file tree
Showing 20 changed files with 1,758 additions and 1,766 deletions.
6 changes: 0 additions & 6 deletions bg_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,3 @@ bg::model::multi_polygon<polygon_type_t> operator+(const bg::model::multi_polygo
}

template multi_polygon_type_fp operator+(const multi_polygon_type_fp&, const multi_polygon_type_fp&);

template <>
multi_polygon_type_fp operator+(const multi_polygon_type_fp& lhs, const ring_type_fp& rhs) {
multi_polygon_type_fp rhs_mp{polygon_type_fp{rhs}};
return lhs + rhs_mp;
}
33 changes: 15 additions & 18 deletions gerberimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,30 +463,27 @@ vector<ring_type_fp> get_all_rings(const ring_type_fp& ring) {
}

multi_polygon_type_fp simplify_cutins(const ring_type_fp& ring) {
const auto area = bg::area(ring); // Positive if the original ring is clockwise, otherwise negative.
vector<ring_type_fp> all_rings = get_all_rings(ring);
if (ring.size() < 4) {
return {};
}
auto new_mls = eulerian_paths::make_eulerian_paths({linestring_type_fp(ring.cbegin(), ring.cend())}, true, false);
if (new_mls.size() != 1 || new_mls[0].front() != new_mls[0].back()) {
cerr << "Internal error in gerberimporter" << endl;
cerr << bg::wkt(ring) << std::endl;
cerr << bg::wkt(new_mls) << std::endl;
throw gerber_exception();
}
ring_type_fp new_ring(new_mls[0].cbegin(), new_mls[0].cend());
vector<ring_type_fp> all_rings = get_all_rings(new_ring);
multi_polygon_type_fp ret;
for (auto r : all_rings) {
const auto this_area = bg::area(r);
if (r.size() < 4 || this_area == 0) {
continue; // No area so ignore it.
}
if (this_area * area > 0) {
auto correct_r = r;
bg::correct(correct_r);
ret = ret + correct_r;
}
}
for (auto r : all_rings) {
const auto this_area = bg::area(r);
if (r.size() < 4 || this_area == 0) {
continue; // No area so ignore it.
}
if (this_area * area < 0) {
auto correct_r = r;
bg::correct(correct_r);
ret = ret - multi_polygon_type_fp{{correct_r}};
}
auto correct_r = r;
bg::correct(correct_r);
ret = ret ^ multi_polygon_type_fp{{correct_r}};
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ G01 X-2.66700 Y25.75979
G01 X-2.77216 Y25.74607
G01 X-2.98831 Y25.65641
G01 X-3.17398 Y25.51392
G01 X-3.31643 Y25.32824
G01 X-3.31640 Y25.32824
G01 X-3.40614 Y25.11209
G01 X-3.41986 Y25.00693
G01 X-3.16164 Y25.00691
Expand Down Expand Up @@ -336,7 +336,7 @@ G01 X-3.12009 Y24.62164
G01 X-3.16164 Y24.75293
G01 X-3.41986 Y24.75293
G01 X-3.40614 Y24.64778
G01 X-3.31643 Y24.43163
G01 X-3.31640 Y24.43163
G01 X-3.17398 Y24.24595
G01 X-2.98831 Y24.10346
G01 X-2.77216 Y24.01380
Expand Down Expand Up @@ -907,10 +907,10 @@ G01 X-38.19479 Y11.07928
G01 X-38.21448 Y10.90994
G01 X-38.19477 Y10.74057
G01 X-38.18306 Y10.68235
G01 X-38.12936 Y10.54108
G01 X-38.12936 Y10.54105
G01 X-38.09459 Y10.47059
G01 X-38.05095 Y10.40526
G01 X-37.95540 Y10.28809
G01 X-38.05098 Y10.40526
G01 X-37.95542 Y10.28809
G01 X-37.91085 Y10.24885
G01 X-37.77397 Y10.14707
G01 X-37.61755 Y10.07953
Expand All @@ -924,7 +924,7 @@ G01 X-36.89317 Y10.14710
G01 X-36.73577 Y10.26605
G01 X-36.71192 Y10.28809
G01 X-36.63226 Y10.38385
G01 X-36.57260 Y10.47064
G01 X-36.57260 Y10.47062
G01 X-36.53790 Y10.54103
G01 X-36.48428 Y10.68230
G01 X-36.47255 Y10.74057
Expand Down Expand Up @@ -1000,7 +1000,7 @@ G01 X-6.96128 Y10.52937
G01 X-6.77403 Y10.53084
G01 X-6.55452 Y10.50750
G01 X-6.39526 Y10.47364
G01 X-6.25704 Y10.43104
G01 X-6.25704 Y10.43102
G01 X-6.22562 Y10.31260
G01 X-6.17129 Y10.20755
G01 X-6.12661 Y10.15164
Expand Down Expand Up @@ -2041,10 +2041,10 @@ G01 X-35.05230 Y10.07021
G01 X-35.22165 Y10.14141
G01 X-35.24522 Y10.15502
G01 X-35.37085 Y10.24885
G01 X-35.41540 Y10.28809
G01 X-35.51095 Y10.40526
G01 X-35.41542 Y10.28809
G01 X-35.51098 Y10.40526
G01 X-35.55459 Y10.47059
G01 X-35.58936 Y10.54108
G01 X-35.58936 Y10.54105
G01 X-35.64306 Y10.68235
G01 X-35.65022 Y10.71402
G01 X-35.67448 Y10.90994
Expand Down Expand Up @@ -2129,11 +2129,11 @@ G01 X-6.96128 Y10.52937
G01 X-6.74604 Y10.52937
G01 X-6.55452 Y10.50750
G01 X-6.39526 Y10.47364
G01 X-6.25704 Y10.43104
G01 X-6.25704 Y10.43102
G01 X-6.17685 Y10.48093
G01 X-6.09476 Y10.51926
G01 X-6.01269 Y10.53203
G01 X-5.60047 Y10.53203
G01 X-6.09476 Y10.51923
G01 X-6.01269 Y10.53201
G01 X-5.60050 Y10.53201
G01 X-5.52623 Y10.54207
G01 X-5.44182 Y10.56229
G01 X-5.36783 Y10.60768
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ G01 X2.66700 Y25.75979
G01 X2.77216 Y25.74607
G01 X2.98831 Y25.65641
G01 X3.17398 Y25.51392
G01 X3.31643 Y25.32824
G01 X3.31640 Y25.32824
G01 X3.40614 Y25.11209
G01 X3.41986 Y25.00693
G01 X3.16164 Y25.00691
Expand Down Expand Up @@ -316,7 +316,7 @@ G01 X3.12009 Y24.62164
G01 X3.16164 Y24.75293
G01 X3.41986 Y24.75293
G01 X3.40614 Y24.64778
G01 X3.31643 Y24.43163
G01 X3.31640 Y24.43163
G01 X3.17398 Y24.24595
G01 X2.98831 Y24.10346
G01 X2.77216 Y24.01380
Expand Down Expand Up @@ -2346,7 +2346,7 @@ G01 X36.45286 Y10.90994
G01 X36.47712 Y10.71402
G01 X36.48428 Y10.68230
G01 X36.52738 Y10.56549
G01 X36.57260 Y10.47064
G01 X36.57260 Y10.47062
G01 X36.63226 Y10.38385
G01 X36.71192 Y10.28809
G01 X36.75647 Y10.24882
Expand All @@ -2360,7 +2360,7 @@ G01 X37.56106 Y10.06051
G01 X37.61755 Y10.07953
G01 X37.77397 Y10.14707
G01 X37.91085 Y10.24885
G01 X37.95540 Y10.28809
G01 X37.95542 Y10.28809
G01 X38.03503 Y10.38388
G01 X38.09459 Y10.47059
G01 X38.13988 Y10.56551
Expand Down Expand Up @@ -3160,7 +3160,7 @@ G01 X34.14123 Y10.05695
G01 X34.22561 Y10.10948
G01 X34.21220 Y10.16371
G01 X34.18152 Y10.25324
G01 X34.13628 Y10.33094
G01 X34.13628 Y10.33097
G01 X34.07631 Y10.40524
G01 X34.03260 Y10.47064
G01 X33.99790 Y10.54103
Expand Down Expand Up @@ -3193,10 +3193,10 @@ G01 X35.65479 Y11.07928
G01 X35.67448 Y10.90994
G01 X35.65477 Y10.74057
G01 X35.64306 Y10.68235
G01 X35.58936 Y10.54108
G01 X35.55459 Y10.47062
G01 X35.58936 Y10.54105
G01 X35.55459 Y10.47059
G01 X35.51095 Y10.40526
G01 X35.41283 Y10.28504
G01 X35.41283 Y10.28507
G01 X35.37923 Y10.23729
G01 X35.34715 Y10.17613
G01 X35.31718 Y10.09500
Expand Down Expand Up @@ -3318,7 +3318,7 @@ G01 X36.75647 Y7.70882
G01 X36.71192 Y7.74812
G01 X36.63226 Y7.84388
G01 X36.53638 Y7.98548
G01 X36.42119 Y8.01827
G01 X36.42116 Y8.01827
G01 X36.36815 Y8.04974
G01 X36.30803 Y8.09285
G01 X36.28774 Y8.10910
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 246bc23

Please sign in to comment.