Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2019-10-07 18:16:40 +0300
committertamasmeszaros <meszaros.q@gmail.com>2019-10-07 18:16:40 +0300
commit72ac8d68f0351214dfe09492bb28dc4fac194a1d (patch)
tree60fdead418a30a902a5226e4a093b3b704447947 /src/libnest2d
parent555fcc151d50a8ff9539e96c9f5c18afeae7e0ab (diff)
Extend libnest tests, remove some warnings, faster catch2 compilation.
Also, improve libnest2d::nest interface.
Diffstat (limited to 'src/libnest2d')
-rw-r--r--src/libnest2d/include/libnest2d.h117
-rw-r--r--src/libnest2d/include/libnest2d/libnest2d.hpp13
-rw-r--r--src/libnest2d/src/libnest2d.cpp26
3 files changed, 77 insertions, 79 deletions
diff --git a/src/libnest2d/include/libnest2d.h b/src/libnest2d/include/libnest2d.h
index 4661b4574..76b133f4b 100644
--- a/src/libnest2d/include/libnest2d.h
+++ b/src/libnest2d/include/libnest2d.h
@@ -49,91 +49,84 @@ using BottomLeftPlacer = placers::_BottomLeftPlacer<PolygonImpl>;
extern template class Nester<NfpPlacer, FirstFitSelection>;
extern template class Nester<BottomLeftPlacer, FirstFitSelection>;
-extern template PackGroup Nester<NfpPlacer, FirstFitSelection>::execute(
+extern template std::size_t Nester<NfpPlacer, FirstFitSelection>::execute(
std::vector<Item>::iterator, std::vector<Item>::iterator);
-extern template PackGroup Nester<BottomLeftPlacer, FirstFitSelection>::execute(
+extern template std::size_t Nester<BottomLeftPlacer, FirstFitSelection>::execute(
std::vector<Item>::iterator, std::vector<Item>::iterator);
#endif
-template<class Placer = NfpPlacer,
- class Selector = FirstFitSelection,
- class Iterator = std::vector<Item>::iterator>
-void nest(Iterator from, Iterator to,
- const typename Placer::BinType& bin,
- Coord dist = 0,
- const typename Placer::Config& pconf = {},
- const typename Selector::Config& sconf = {})
-{
- _Nester<Placer, Selector> nester(bin, dist, pconf, sconf);
- nester.execute(from, to);
-}
+template<class Placer = NfpPlacer, class Selector = FirstFitSelection>
+struct NestConfig {
+ typename Placer::Config placer_config;
+ typename Selector::Config selector_config;
+ using Placement = typename Placer::Config;
+ using Selection = typename Selector::Config;
+
+ NestConfig() = default;
+ NestConfig(const typename Placer::Config &cfg) : placer_config{cfg} {}
+ NestConfig(const typename Selector::Config &cfg) : selector_config{cfg} {}
+ NestConfig(const typename Placer::Config & pcfg,
+ const typename Selector::Config &scfg)
+ : placer_config{pcfg}, selector_config{scfg} {}
+};
+
+struct NestControl {
+ ProgressFunction progressfn;
+ StopCondition stopcond = []{ return false; };
+
+ NestControl() = default;
+ NestControl(ProgressFunction pr) : progressfn{std::move(pr)} {}
+ NestControl(StopCondition sc) : stopcond{std::move(sc)} {}
+ NestControl(ProgressFunction pr, StopCondition sc)
+ : progressfn{std::move(pr)}, stopcond{std::move(sc)}
+ {}
+};
template<class Placer = NfpPlacer,
class Selector = FirstFitSelection,
class Iterator = std::vector<Item>::iterator>
-void nest(Iterator from, Iterator to,
- const typename Placer::BinType& bin,
- ProgressFunction prg,
- StopCondition scond = []() { return false; },
- Coord dist = 0,
- const typename Placer::Config& pconf = {},
- const typename Selector::Config& sconf = {})
+std::size_t nest(Iterator from, Iterator to,
+ const typename Placer::BinType & bin,
+ Coord dist = 0,
+ const NestConfig<Placer, Selector> &cfg = {},
+ NestControl ctl = {})
{
- _Nester<Placer, Selector> nester(bin, dist, pconf, sconf);
- if(prg) nester.progressIndicator(prg);
- if(scond) nester.stopCondition(scond);
- nester.execute(from, to);
+ _Nester<Placer, Selector> nester{bin, dist, cfg.placer_config, cfg.selector_config};
+ if(ctl.progressfn) nester.progressIndicator(ctl.progressfn);
+ if(ctl.stopcond) nester.stopCondition(ctl.stopcond);
+ return nester.execute(from, to);
}
#ifdef LIBNEST2D_STATIC
extern template class Nester<NfpPlacer, FirstFitSelection>;
extern template class Nester<BottomLeftPlacer, FirstFitSelection>;
-
-extern template void nest(std::vector<Item>::iterator from,
- std::vector<Item>::iterator to,
- const Box& bin,
- Coord dist = 0,
- const NfpPlacer::Config& pconf,
- const FirstFitSelection::Config& sconf);
-
-extern template void nest(std::vector<Item>::iterator from,
- std::vector<Item>::iterator to,
- const Box& bin,
- ProgressFunction prg,
- StopCondition scond,
- Coord dist = 0,
- const NfpPlacer::Config& pconf,
- const FirstFitSelection::Config& sconf);
+extern template std::size_t nest(std::vector<Item>::iterator from,
+ std::vector<Item>::iterator from to,
+ const Box & bin,
+ Coord dist,
+ const NestConfig<NfpPlacer, FirstFitSelection> &cfg,
+ NestControl ctl);
+extern template std::size_t nest(std::vector<Item>::iterator from,
+ std::vector<Item>::iterator from to,
+ const Box & bin,
+ Coord dist,
+ const NestConfig<BottomLeftPlacer, FirstFitSelection> &cfg,
+ NestControl ctl);
#endif
template<class Placer = NfpPlacer,
class Selector = FirstFitSelection,
class Container = std::vector<Item>>
-void nest(Container&& cont,
- const typename Placer::BinType& bin,
- Coord dist = 0,
- const typename Placer::Config& pconf = {},
- const typename Selector::Config& sconf = {})
-{
- nest<Placer, Selector>(cont.begin(), cont.end(), bin, dist, pconf, sconf);
-}
-
-template<class Placer = NfpPlacer,
- class Selector = FirstFitSelection,
- class Container = std::vector<Item>>
-void nest(Container&& cont,
- const typename Placer::BinType& bin,
- ProgressFunction prg,
- StopCondition scond = []() { return false; },
- Coord dist = 0,
- const typename Placer::Config& pconf = {},
- const typename Selector::Config& sconf = {})
+std::size_t nest(Container&& cont,
+ const typename Placer::BinType & bin,
+ Coord dist = 0,
+ const NestConfig<Placer, Selector> &cfg = {},
+ NestControl ctl = {})
{
- nest<Placer, Selector>(cont.begin(), cont.end(), bin, prg, scond, dist,
- pconf, sconf);
+ return nest<Placer, Selector>(cont.begin(), cont.end(), bin, dist, cfg, ctl);
}
}
diff --git a/src/libnest2d/include/libnest2d/libnest2d.hpp b/src/libnest2d/include/libnest2d/libnest2d.hpp
index 29d52c10f..91c98c62a 100644
--- a/src/libnest2d/include/libnest2d/libnest2d.hpp
+++ b/src/libnest2d/include/libnest2d/libnest2d.hpp
@@ -129,8 +129,12 @@ public:
sh_(sl::create<RawShape>(std::move(contour), std::move(holes))) {}
inline bool isFixed() const noexcept { return fixed_; }
- inline void markAsFixed(bool fixed = true) { fixed_ = fixed; }
-
+ inline void markAsFixedInBin(int binid)
+ {
+ fixed_ = binid >= 0;
+ binid_ = binid;
+ }
+
inline void binId(int idx) { binid_ = idx; }
inline int binId() const noexcept { return binid_; }
@@ -748,6 +752,7 @@ template<class PlacementStrategy, class SelectionStrategy >
class _Nester {
using TSel = SelectionStrategyLike<SelectionStrategy>;
TSel selector_;
+
public:
using Item = typename PlacementStrategy::Item;
using ShapeType = typename Item::ShapeType;
@@ -824,7 +829,7 @@ public:
* the selection algorithm.
*/
template<class It>
- inline ItemIteratorOnly<It, void> execute(It from, It to)
+ inline ItemIteratorOnly<It, size_t> execute(It from, It to)
{
auto infl = static_cast<Coord>(std::ceil(min_obj_distance_/2.0));
if(infl > 0) std::for_each(from, to, [this, infl](Item& item) {
@@ -837,6 +842,8 @@ public:
if(min_obj_distance_ > 0) std::for_each(from, to, [infl](Item& item) {
item.inflate(-infl);
});
+
+ return selector_.getResult().size();
}
/// Set a progress indicator function object for the selector.
diff --git a/src/libnest2d/src/libnest2d.cpp b/src/libnest2d/src/libnest2d.cpp
index 021458787..740f6e18d 100644
--- a/src/libnest2d/src/libnest2d.cpp
+++ b/src/libnest2d/src/libnest2d.cpp
@@ -5,19 +5,17 @@ namespace libnest2d {
template class Nester<NfpPlacer, FirstFitSelection>;
template class Nester<BottomLeftPlacer, FirstFitSelection>;
-template PackGroup nest(std::vector<Item>::iterator from,
- std::vector<Item>::iterator to,
- const Box& bin,
- Coord dist = 0,
- const NfpPlacer::Config& pconf,
- const FirstFitSelection::Config& sconf);
+template std::size_t nest(std::vector<Item>::iterator from,
+ std::vector<Item>::iterator from to,
+ const Box & bin,
+ Coord dist,
+ const NestConfig<NfpPlacer, FirstFitSelection> &cfg,
+ NestControl ctl);
-template PackGroup nest(std::vector<Item>::iterator from,
- std::vector<Item>::iterator to,
- const Box& bin,
- ProgressFunction prg,
- StopCondition scond,
- Coord dist = 0,
- const NfpPlacer::Config& pconf,
- const FirstFitSelection::Config& sconf);
+template std::size_t nest(std::vector<Item>::iterator from,
+ std::vector<Item>::iterator from to,
+ const Box & bin,
+ Coord dist,
+ const NestConfig<BottomLeftPlacer, FirstFitSelection> &cfg,
+ NestControl ctl);
}