diff options
author | jaseg <git@jaseg.de> | 2021-01-26 23:44:17 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2021-01-26 23:44:17 +0100 |
commit | f9a871f9b2737881e23f1ef1b06583394bc4043d (patch) | |
tree | 90520c8e147557d16535bc35cb3969a8b3767a9c /src/out_flattener.cpp | |
parent | 3cee5d4f018be6d4f494fb2ab1018fbf53b2f15f (diff) | |
download | gerbolyze-f9a871f9b2737881e23f1ef1b06583394bc4043d.tar.gz gerbolyze-f9a871f9b2737881e23f1ef1b06583394bc4043d.tar.bz2 gerbolyze-f9a871f9b2737881e23f1ef1b06583394bc4043d.zip |
Speed up flatterner through randomization
Diffstat (limited to 'src/out_flattener.cpp')
-rw-r--r-- | src/out_flattener.cpp | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/src/out_flattener.cpp b/src/out_flattener.cpp index 9bc4cbe..4351ecc 100644 --- a/src/out_flattener.cpp +++ b/src/out_flattener.cpp @@ -17,6 +17,7 @@ */ #include <cmath> +#include <random> #include <algorithm> #include <string> #include <iostream> @@ -46,10 +47,15 @@ namespace gerbolyze { class Flattener_D { public: vector<cavc::Polyline<double>> dark_polys; + vector<cavc::Polyline<double>> clear_polys; void add_dark_polygon(const Polygon &in) { polygon_to_cavc(in, dark_polys.emplace_back()); } + + void add_clear_polygon(const Polygon &in) { + polygon_to_cavc(in, clear_polys.emplace_back()); + } }; } @@ -65,28 +71,12 @@ void Flattener::header(d2p origin, d2p size) { m_sink.header(origin, size); } +void Flattener::render_out_clear_polys() { + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(d->clear_polys.begin(), d->clear_polys.end(), g); - -Flattener &Flattener::operator<<(GerberPolarityToken pol) { - if (m_current_polarity != pol) { - m_current_polarity = pol; - } - - return *this; -} - -Flattener &Flattener::operator<<(const Polygon &poly) { - static int i=0, j=0; - - if (m_current_polarity == GRB_POL_DARK) { - d->add_dark_polygon(poly); - cerr << "dark primitive " << i++ << endl; - } else { /* clear */ - cerr << "clear primitive " << j++ << endl; - - cavc::Polyline<double> sub; - polygon_to_cavc (poly, sub); - + for (auto &sub : d->clear_polys) { vector<cavc::Polyline<double>> new_dark_polys; new_dark_polys.reserve(d->dark_polys.size()); @@ -98,7 +88,7 @@ Flattener &Flattener::operator<<(const Polygon &poly) { new_dark_polys.push_back(std::move(rem)); } - } else { + } else { /* custom one-hole deholing code */ assert (res.remaining.size() == 1); assert (res.subtracted.size() == 1); @@ -144,11 +134,40 @@ Flattener &Flattener::operator<<(const Polygon &poly) { d->dark_polys = std::move(new_dark_polys); } + d->clear_polys.clear(); +} + +Flattener &Flattener::operator<<(GerberPolarityToken pol) { + if (m_current_polarity != pol) { + m_current_polarity = pol; + + if (pol == GRB_POL_DARK) { + render_out_clear_polys(); + } + } + + return *this; +} + +Flattener &Flattener::operator<<(const Polygon &poly) { + static int i=0, j=0; + + if (m_current_polarity == GRB_POL_DARK) { + d->add_dark_polygon(poly); + cerr << "dark primitive " << i++ << endl; + + } else { /* clear */ + cerr << "clear primitive " << j++ << endl; + d->add_clear_polygon(poly); + } return *this; } void Flattener::footer() { + if (m_current_polarity == GRB_POL_CLEAR) { + render_out_clear_polys(); + } m_sink << GRB_POL_DARK; for (auto &poly : d->dark_polys) { |