From 6ae50a710a97e8379cb2f85392b0a6c90abd7d40 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 18 Jul 2019 17:31:11 +0200 Subject: [PATCH] Further refactoring --- src/libnest2d/include/libnest2d.h | 4 +-- src/libnest2d/include/libnest2d/libnest2d.hpp | 34 +++++++++---------- src/libnest2d/tests/test.cpp | 4 +-- src/libslic3r/Arrange.cpp | 8 ++--- src/slic3r/GUI/Plater.cpp | 2 +- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/libnest2d/include/libnest2d.h b/src/libnest2d/include/libnest2d.h index 5f7a29dfb..4661b4574 100644 --- a/src/libnest2d/include/libnest2d.h +++ b/src/libnest2d/include/libnest2d.h @@ -65,7 +65,7 @@ void nest(Iterator from, Iterator to, const typename Placer::Config& pconf = {}, const typename Selector::Config& sconf = {}) { - Nester nester(bin, dist, pconf, sconf); + _Nester nester(bin, dist, pconf, sconf); nester.execute(from, to); } @@ -80,7 +80,7 @@ void nest(Iterator from, Iterator to, const typename Placer::Config& pconf = {}, const typename Selector::Config& sconf = {}) { - Nester nester(bin, dist, pconf, sconf); + _Nester nester(bin, dist, pconf, sconf); if(prg) nester.progressIndicator(prg); if(scond) nester.stopCondition(scond); nester.execute(from, to); diff --git a/src/libnest2d/include/libnest2d/libnest2d.hpp b/src/libnest2d/include/libnest2d/libnest2d.hpp index d0d91838f..29d52c10f 100644 --- a/src/libnest2d/include/libnest2d/libnest2d.hpp +++ b/src/libnest2d/include/libnest2d/libnest2d.hpp @@ -741,12 +741,11 @@ public: }; /** - * The Arranger is the front-end class for the libnest2d library. It takes the - * input items and outputs the items with the proper transformations to be - * inside the provided bin. + * The _Nester is the front-end class for the libnest2d library. It takes the + * input items and changes their transformations to be inside the provided bin. */ template -class Nester { +class _Nester { using TSel = SelectionStrategyLike; TSel selector_; public: @@ -771,12 +770,12 @@ private: using TSItem = remove_cvref_t; StopCondition stopfn_; - - template using TVal = remove_cvref_t; + + template using TVal = remove_ref_t; template - using ConvertibleOnly = - enable_if_t< std::is_convertible, TPItem>::value, void>; + using ItemIteratorOnly = + enable_if_t&, TPItem&>::value, Out>; public: @@ -789,10 +788,8 @@ public: template - Nester( TBinType&& bin, - Coord min_obj_distance = 0, - const PConf& pconfig = PConf(), - const SConf& sconfig = SConf()): + _Nester(TBinType&& bin, Coord min_obj_distance = 0, + const PConf& pconfig = PConf(), const SConf& sconfig = SConf()): bin_(std::forward(bin)), pconfig_(pconfig), min_obj_distance_(min_obj_distance) @@ -817,14 +814,17 @@ public: } /** - * \brief Arrange an input sequence and return a PackGroup object with - * the packed groups corresponding to the bins. + * \brief Arrange an input sequence of _Item-s. + * + * To get the result, call the translation(), rotation() and binId() + * methods of each item. If only the transformed polygon is needed, call + * transformedShape() to get the properly transformed shapes. * * The number of groups in the pack group is the number of bins opened by * the selection algorithm. */ template - inline ConvertibleOnly execute(It from, It to) + inline ItemIteratorOnly execute(It from, It to) { auto infl = static_cast(std::ceil(min_obj_distance_/2.0)); if(infl > 0) std::for_each(from, to, [this, infl](Item& item) { @@ -840,13 +840,13 @@ public: } /// Set a progress indicator function object for the selector. - inline Nester& progressIndicator(ProgressFunction func) + inline _Nester& progressIndicator(ProgressFunction func) { selector_.progressIndicator(func); return *this; } /// Set a predicate to tell when to abort nesting. - inline Nester& stopCondition(StopCondition fn) + inline _Nester& stopCondition(StopCondition fn) { stopfn_ = fn; selector_.stopCondition(fn); return *this; } diff --git a/src/libnest2d/tests/test.cpp b/src/libnest2d/tests/test.cpp index 6891b16e1..29577344d 100644 --- a/src/libnest2d/tests/test.cpp +++ b/src/libnest2d/tests/test.cpp @@ -370,7 +370,7 @@ TEST(GeometryAlgorithms, ArrangeRectanglesTight) ASSERT_EQ(getX(bin.center()), 105); ASSERT_EQ(getY(bin.center()), 125); - Nester arrange(bin); + _Nester arrange(bin); arrange.execute(rects.begin(), rects.end()); @@ -438,7 +438,7 @@ TEST(GeometryAlgorithms, ArrangeRectanglesLoose) Coord min_obj_distance = 5; - Nester arrange(bin, min_obj_distance); + _Nester arrange(bin, min_obj_distance); arrange.execute(rects.begin(), rects.end()); diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index bc3eedb63..b02efa55c 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -66,10 +66,6 @@ using Circle = _Circle; using Segment = _Segment; using MultiPolygon = TMultiShape; -// The return value of nesting, a vector (for each logical bed) of Item -// reference vectors. -using PackGroup = _PackGroup; - // Summon the spatial indexing facilities from boost namespace bgi = boost::geometry::index; using SpatElement = std::pair; @@ -102,7 +98,7 @@ void fillConfig(PConf& pcfg) { pcfg.parallel = true; } -// Apply penality to object function result. This is used only when alignment +// Apply penalty to object function result. This is used only when alignment // after arrange is explicitly disabled (PConfig::Alignment::DONT_ALIGN) double fixed_overfit(const std::tuple& result, const Box &binbb) { @@ -123,7 +119,7 @@ public: // Useful type shortcuts... using Placer = typename placers::_NofitPolyPlacer; using Selector = selections::_FirstFitSelection; - using Packer = Nester; + using Packer = _Nester; using PConfig = typename Packer::PlacementConfig; using Distance = TCoord; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index d4697e7b3..58f0db292 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1609,7 +1609,7 @@ struct Plater::priv if (m_selected.empty()) m_selected.swap(m_unselected); // The strides have to be removed from the fixed items. For the - // arrangeable (selected) items it bed_idx is ignored and the + // arrangeable (selected) items bed_idx is ignored and the // translation is irrelevant. for (auto &p : m_unselected) p.translation(X) -= p.bed_idx * stride; }