diff --git a/xs/src/libnest2d/libnest2d/libnest2d.hpp b/xs/src/libnest2d/libnest2d/libnest2d.hpp index 60d9c1ff4e..c661dc5992 100644 --- a/xs/src/libnest2d/libnest2d/libnest2d.hpp +++ b/xs/src/libnest2d/libnest2d/libnest2d.hpp @@ -687,6 +687,17 @@ public: selector_.configure(std::forward(sconfig)); } + void configure(const PlacementConfig& pconf) { pconfig_ = pconf; } + void configure(const SelectionConfig& sconf) { selector_.configure(sconf); } + void configure(const PlacementConfig& pconf, const SelectionConfig& sconf) { + pconfig_ = pconf; + selector_.configure(sconf); + } + void configure(const SelectionConfig& sconf, const PlacementConfig& pconf) { + pconfig_ = pconf; + selector_.configure(sconf); + } + /** * \brief Arrange an input sequence and return a PackGroup object with * the packed groups corresponding to the bins. diff --git a/xs/src/libnest2d/libnest2d/placers/nfpplacer.hpp b/xs/src/libnest2d/libnest2d/placers/nfpplacer.hpp index 7ad983b61c..26a0a20487 100644 --- a/xs/src/libnest2d/libnest2d/placers/nfpplacer.hpp +++ b/xs/src/libnest2d/libnest2d/placers/nfpplacer.hpp @@ -28,6 +28,9 @@ struct NfpPConfig { /// Where to align the resulting packed pile Alignment alignment; + std::function&, double, double, double)> + object_function; + NfpPConfig(): rotations({0.0, Pi/2.0, Pi, 3*Pi/2}), alignment(Alignment::CENTER) {} }; @@ -213,7 +216,16 @@ class _NofitPolyPlacer: public PlacerBoilerplate<_NofitPolyPlacer, const double norm_; const double penality_; - bool static wouldFit(const RawShape& chull, const RawShape& bin) { +public: + + using Pile = const Nfp::Shapes&; + + inline explicit _NofitPolyPlacer(const BinType& bin): + Base(bin), + norm_(std::sqrt(ShapeLike::area(bin))), + penality_(1e6*norm_) {} + + bool static inline wouldFit(const RawShape& chull, const RawShape& bin) { auto bbch = ShapeLike::boundingBox(chull); auto bbin = ShapeLike::boundingBox(bin); auto d = bbin.minCorner() - bbch.minCorner(); @@ -222,18 +234,16 @@ class _NofitPolyPlacer: public PlacerBoilerplate<_NofitPolyPlacer, return ShapeLike::isInside(chullcpy, bbin); } - bool static wouldFit(const RawShape& chull, const Box& bin) + bool static inline wouldFit(const RawShape& chull, const Box& bin) { auto bbch = ShapeLike::boundingBox(chull); - return bbch.width() <= bin.width() && bbch.height() <= bin.height(); + return wouldFit(bbch, bin); } -public: - - inline explicit _NofitPolyPlacer(const BinType& bin): - Base(bin), - norm_(std::sqrt(ShapeLike::area(bin))), - penality_(1e6*norm_) {} + bool static inline wouldFit(const Box& bb, const Box& bin) + { + return bb.width() <= bin.width() && bb.height() <= bin.height(); + } PackResult trypack(Item& item) { @@ -291,21 +301,13 @@ public: pile_area += mitem.area(); } - // Our object function for placement - auto objfunc = [&] (double relpos) + auto _objfunc = config_.object_function? + config_.object_function : + [this](const Nfp::Shapes& pile, double occupied_area, + double /*norm*/, double penality) { - Vertex v = getNfpPoint(relpos); - auto d = v - iv; - d += startpos; - item.translation(d); - - pile.emplace_back(item.transformedShape()); - - double occupied_area = pile_area + item.area(); auto ch = ShapeLike::convexHull(pile); - pile.pop_back(); - // The pack ratio -- how much is the convex hull occupied double pack_rate = occupied_area/ShapeLike::area(ch); @@ -317,7 +319,27 @@ public: // (larger) values. auto score = std::sqrt(waste); - if(!wouldFit(ch, bin_)) score = 2*penality_ - score; + if(!wouldFit(ch, bin_)) score = 2*penality - score; + + return score; + }; + + // Our object function for placement + auto objfunc = [&] (double relpos) + { + Vertex v = getNfpPoint(relpos); + auto d = v - iv; + d += startpos; + item.translation(d); + + pile.emplace_back(item.transformedShape()); + + double occupied_area = pile_area + item.area(); + + double score = _objfunc(pile, occupied_area, + norm_, penality_); + + pile.pop_back(); return score; }; diff --git a/xs/src/libnest2d/tests/main.cpp b/xs/src/libnest2d/tests/main.cpp index db890cdca6..88b958c078 100644 --- a/xs/src/libnest2d/tests/main.cpp +++ b/xs/src/libnest2d/tests/main.cpp @@ -76,360 +76,433 @@ void arrangeRectangles() { std::vector crasher = { { - {-10836093, -2542602}, - {-10834392, -1849197}, - {-10826793, 1172203}, - {-10824993, 1884506}, - {-10823291, 2547500}, - {-10822994, 2642700}, - {-10807392, 2768295}, - {-10414295, 3030403}, - {-9677799, 3516204}, - {-9555896, 3531204}, - {-9445194, 3534698}, - {9353008, 3487297}, - {9463504, 3486999}, - {9574008, 3482902}, - {9695903, 3467399}, - {10684803, 2805702}, - {10814098, 2717803}, - {10832805, 2599502}, - {10836200, 2416801}, - {10819705, -2650299}, - {10800403, -2772300}, - {10670505, -2859596}, - {9800403, -3436599}, - {9678203, -3516197}, - {9556308, -3531196}, - {9445903, -3534698}, - {9084011, -3533798}, - {-9234294, -3487701}, - {-9462894, -3486999}, - {-9573497, -3483001}, - {-9695392, -3467300}, - {-9816898, -3387199}, - {-10429492, -2977798}, - {-10821193, -2714096}, - {-10836200, -2588195}, - {-10836093, -2542602}, + {-5000000, 8954050}, + {5000000, 8954050}, + {5000000, -45949}, + {4972609, -568549}, + {3500000, -8954050}, + {-3500000, -8954050}, + {-4972609, -568549}, + {-5000000, -45949}, + {-5000000, 8954050}, }, { - {-3533699, -9084051}, - {-3487197, 9352449}, - {-3486797, 9462949}, - {-3482795, 9573547}, - {-3467201, 9695350}, - {-3386997, 9816949}, - {-2977699, 10429548}, - {-2713897, 10821249}, - {-2587997, 10836149}, - {-2542396, 10836149}, - {-2054698, 10834949}, - {2223503, 10824150}, - {2459800, 10823547}, - {2555002, 10823247}, - {2642601, 10822948}, - {2768301, 10807350}, - {3030302, 10414247}, - {3516099, 9677850}, - {3531002, 9555850}, - {3534502, 9445247}, - {3534301, 9334949}, - {3487300, -9353052}, - {3486904, -9463548}, - {3482801, -9574148}, - {3467302, -9695848}, - {2805601, -10684751}, - {2717802, -10814149}, - {2599403, -10832952}, - {2416801, -10836149}, - {-2650199, -10819749}, - {-2772197, -10800451}, - {-2859397, -10670450}, - {-3436401, -9800451}, - {-3515998, -9678350}, - {-3530998, -9556451}, - {-3534500, -9445848}, - {-3533699, -9084051}, + {-5000000, 8954050}, + {5000000, 8954050}, + {5000000, -45949}, + {4972609, -568549}, + {3500000, -8954050}, + {-3500000, -8954050}, + {-4972609, -568549}, + {-5000000, -45949}, + {-5000000, 8954050}, }, { - {-3533798, -9084051}, - {-3487697, 9234249}, - {-3486999, 9462949}, - {-3482997, 9573547}, - {-3467296, 9695350}, - {-3387199, 9816949}, - {-2977798, 10429548}, - {-2714096, 10821249}, - {-2588199, 10836149}, - {-2542594, 10836149}, - {-2054798, 10834949}, - {2223701, 10824150}, - {2459903, 10823547}, - {2555202, 10823247}, - {2642704, 10822948}, - {2768302, 10807350}, - {3030403, 10414247}, - {3516204, 9677850}, - {3531204, 9555850}, - {3534702, 9445247}, - {3487300, -9353052}, - {3486999, -9463548}, - {3482902, -9574148}, - {3467403, -9695848}, - {2805702, -10684751}, - {2717803, -10814149}, - {2599502, -10832952}, - {2416801, -10836149}, - {-2650299, -10819749}, - {-2772296, -10800451}, - {-2859596, -10670450}, - {-3436595, -9800451}, - {-3516197, -9678350}, - {-3531196, -9556451}, - {-3534698, -9445848}, - {-3533798, -9084051}, + {-5000000, 8954050}, + {5000000, 8954050}, + {5000000, -45949}, + {4972609, -568549}, + {3500000, -8954050}, + {-3500000, -8954050}, + {-4972609, -568549}, + {-5000000, -45949}, + {-5000000, 8954050}, }, { - {-49433151, 4289947}, - {-49407352, 4421947}, - {-49355751, 4534446}, - {-29789449, 36223850}, - {-29737350, 36307445}, - {-29512149, 36401447}, - {-29089149, 36511646}, - {-28894351, 36550342}, - {-18984951, 37803447}, - {-18857151, 37815151}, - {-18271148, 37768947}, - {-18146148, 37755146}, - {-17365447, 37643947}, - {-17116649, 37601146}, - {11243545, 29732448}, - {29276451, 24568149}, - {29497543, 24486148}, - {29654548, 24410953}, - {31574546, 23132640}, - {33732849, 21695148}, - {33881950, 21584445}, - {34019454, 21471950}, - {34623153, 20939151}, - {34751945, 20816951}, - {35249244, 20314647}, - {36681549, 18775447}, - {36766548, 18680446}, - {36794250, 18647144}, - {36893951, 18521953}, - {37365951, 17881946}, - {37440948, 17779247}, - {37529243, 17642444}, - {42233245, 10012245}, - {42307250, 9884048}, - {42452949, 9626548}, - {44258949, 4766647}, - {48122245, -5990951}, - {48160751, -6117950}, - {49381546, -17083953}, - {49412246, -17420953}, - {49429450, -18011253}, - {49436141, -18702651}, - {49438949, -20087953}, - {49262947, -24000852}, - {49172546, -24522455}, - {48847549, -25859151}, - {48623847, -26705650}, - {48120246, -28514953}, - {48067146, -28699455}, - {48017845, -28862453}, - {47941543, -29096954}, - {47892547, -29246852}, - {47813545, -29466651}, - {47758453, -29612955}, - {47307548, -30803253}, - {46926544, -31807151}, - {46891448, -31899551}, - {46672546, -32475852}, - {46502449, -32914852}, - {46414451, -33140853}, - {46294250, -33447650}, - {46080146, -33980255}, - {46039245, -34071853}, - {45970542, -34186653}, - {45904243, -34295955}, - {45786247, -34475650}, - {43063247, -37740955}, - {42989547, -37815151}, - {12128349, -36354953}, - {12101844, -36343955}, - {11806152, -36217453}, - {7052848, -34171649}, - {-3234352, -29743150}, - {-15684650, -24381851}, - {-16573852, -23998851}, - {-20328948, -22381254}, - {-20383052, -22357254}, - {-20511447, -22280651}, - {-42221252, -8719951}, - {-42317150, -8653255}, - {-42457851, -8528949}, - {-42600151, -8399852}, - {-47935852, -2722949}, - {-48230651, -2316852}, - {-48500850, -1713150}, - {-48516853, -1676551}, - {-48974651, -519649}, - {-49003852, -412551}, - {-49077850, -129650}, - {-49239753, 735946}, - {-49312652, 1188549}, - {-49349349, 1467647}, - {-49351650, 1513347}, - {-49438949, 4165744}, - {-49433151, 4289947}, - }, -// { -// {6000, 5851}, -// {-6000, -5851}, -// {6000, 5851}, -// }, - { - {-10836097, -2542396}, - {-10834396, -1848999}, - {-10826797, 1172000}, - {-10825000, 1884403}, - {-10823299, 2547401}, - {-10822998, 2642604}, - {-10807395, 2768299}, - {-10414299, 3030300}, - {-9677799, 3516101}, - {-9555896, 3531002}, - {-9445198, 3534500}, - {-9334899, 3534297}, - {9353000, 3487300}, - {9463499, 3486904}, - {9573999, 3482799}, - {9695901, 3467300}, - {10684803, 2805603}, - {10814102, 2717800}, - {10832803, 2599399}, - {10836200, 2416797}, - {10819700, -2650199}, - {10800401, -2772201}, - {10670499, -2859397}, - {9800401, -3436397}, - {9678201, -3515998}, - {9556303, -3530998}, - {9445901, -3534500}, - {9083999, -3533699}, - {-9352500, -3487201}, - {-9462898, -3486797}, - {-9573501, -3482799}, - {-9695396, -3467201}, - {-9816898, -3386997}, - {-10429500, -2977699}, - {-10821197, -2713897}, - {-10836196, -2588001}, - {-10836097, -2542396}, + {-5000000, 8954050}, + {5000000, 8954050}, + {5000000, -45949}, + {4972609, -568549}, + {3500000, -8954050}, + {-3500000, -8954050}, + {-4972609, -568549}, + {-5000000, -45949}, + {-5000000, 8954050}, }, { - {-47073699, 26300853}, - {-47009803, 27392650}, - {-46855804, 28327953}, - {-46829402, 28427051}, - {-46764102, 28657550}, - {-46200401, 30466648}, - {-46066703, 30832347}, - {-45887104, 31247554}, - {-45663700, 31670848}, - {-45414802, 32080554}, - {-45273700, 32308956}, - {-45179702, 32431850}, - {-45057804, 32549350}, - {-34670803, 40990154}, - {-34539802, 41094348}, - {-34393600, 41184452}, - {-34284805, 41229953}, - {-34080402, 41267154}, - {17335296, 48077648}, - {18460296, 48153553}, - {18976600, 48182147}, - {20403999, 48148555}, - {20562301, 48131153}, - {20706001, 48102855}, - {20938796, 48053150}, - {21134101, 48010051}, - {21483192, 47920154}, - {21904701, 47806346}, - {22180099, 47670154}, - {22357795, 47581645}, - {22615295, 47423046}, - {22782295, 47294651}, - {24281791, 45908344}, - {24405296, 45784854}, - {41569297, 21952449}, - {41784301, 21638050}, - {41938491, 21393650}, - {42030899, 21245052}, - {42172996, 21015850}, - {42415298, 20607151}, - {42468299, 20504650}, - {42553100, 20320850}, - {42584594, 20250644}, - {42684997, 20004344}, - {42807098, 19672351}, - {42939002, 19255153}, - {43052299, 18693950}, - {45094100, 7846851}, - {45118400, 7684154}, - {47079101, -16562252}, - {47082000, -16705646}, - {46916297, -22172447}, - {46911598, -22294349}, - {46874893, -22358146}, - {44866996, -25470146}, - {30996795, -46852050}, - {30904998, -46933750}, - {30864791, -46945850}, - {9315696, -48169147}, - {9086494, -48182147}, - {8895500, -48160049}, - {8513496, -48099548}, - {8273696, -48057350}, - {8180198, -48039051}, - {7319801, -47854949}, - {6288299, -47569950}, - {6238498, -47554248}, - {5936199, -47453250}, - {-11930000, -41351551}, - {-28986402, -33654148}, - {-29111103, -33597148}, - {-29201803, -33544147}, - {-29324401, -33467845}, - {-29467000, -33352848}, - {-29606603, -33229351}, - {-31140401, -31849147}, - {-31264303, -31736450}, - {-31385803, -31625452}, - {-31829103, -31216148}, - {-32127403, -30935951}, - {-32253803, -30809648}, - {-32364803, -30672147}, - {-34225402, -28078847}, - {-35819404, -25762451}, - {-36304801, -25035346}, - {-36506103, -24696445}, - {-36574104, -24560146}, - {-36926700, -23768646}, - {-39767402, -17341148}, - {-39904102, -16960147}, - {-41008602, -11799850}, - {-43227401, -704147}, - {-43247303, -577148}, - {-47057403, 24847454}, - {-47077602, 25021648}, - {-47080101, 25128650}, - {-47082000, 25562953}, - {-47073699, 26300853}, + {-5000000, 8954050}, + {5000000, 8954050}, + {5000000, -45949}, + {4972609, -568549}, + {3500000, -8954050}, + {-3500000, -8954050}, + {-4972609, -568549}, + {-5000000, -45949}, + {-5000000, 8954050}, + }, + { + {-5000000, 8954050}, + {5000000, 8954050}, + {5000000, -45949}, + {4972609, -568549}, + {3500000, -8954050}, + {-3500000, -8954050}, + {-4972609, -568549}, + {-5000000, -45949}, + {-5000000, 8954050}, + }, + { + {-9945219, -3065619}, + {-9781479, -2031780}, + {-9510560, -1020730}, + {-9135450, -43529}, + {-2099999, 14110899}, + {2099999, 14110899}, + {9135450, -43529}, + {9510560, -1020730}, + {9781479, -2031780}, + {9945219, -3065619}, + {10000000, -4110899}, + {9945219, -5156179}, + {9781479, -6190020}, + {9510560, -7201069}, + {9135450, -8178270}, + {8660249, -9110899}, + {8090169, -9988750}, + {7431449, -10802200}, + {6691309, -11542300}, + {5877850, -12201100}, + {5000000, -12771100}, + {4067369, -13246399}, + {3090169, -13621500}, + {2079119, -13892399}, + {1045279, -14056099}, + {0, -14110899}, + {-1045279, -14056099}, + {-2079119, -13892399}, + {-3090169, -13621500}, + {-4067369, -13246399}, + {-5000000, -12771100}, + {-5877850, -12201100}, + {-6691309, -11542300}, + {-7431449, -10802200}, + {-8090169, -9988750}, + {-8660249, -9110899}, + {-9135450, -8178270}, + {-9510560, -7201069}, + {-9781479, -6190020}, + {-9945219, -5156179}, + {-10000000, -4110899}, + {-9945219, -3065619}, + }, + { + {-9945219, -3065619}, + {-9781479, -2031780}, + {-9510560, -1020730}, + {-9135450, -43529}, + {-2099999, 14110899}, + {2099999, 14110899}, + {9135450, -43529}, + {9510560, -1020730}, + {9781479, -2031780}, + {9945219, -3065619}, + {10000000, -4110899}, + {9945219, -5156179}, + {9781479, -6190020}, + {9510560, -7201069}, + {9135450, -8178270}, + {8660249, -9110899}, + {8090169, -9988750}, + {7431449, -10802200}, + {6691309, -11542300}, + {5877850, -12201100}, + {5000000, -12771100}, + {4067369, -13246399}, + {3090169, -13621500}, + {2079119, -13892399}, + {1045279, -14056099}, + {0, -14110899}, + {-1045279, -14056099}, + {-2079119, -13892399}, + {-3090169, -13621500}, + {-4067369, -13246399}, + {-5000000, -12771100}, + {-5877850, -12201100}, + {-6691309, -11542300}, + {-7431449, -10802200}, + {-8090169, -9988750}, + {-8660249, -9110899}, + {-9135450, -8178270}, + {-9510560, -7201069}, + {-9781479, -6190020}, + {-9945219, -5156179}, + {-10000000, -4110899}, + {-9945219, -3065619}, + }, + { + {-9945219, -3065619}, + {-9781479, -2031780}, + {-9510560, -1020730}, + {-9135450, -43529}, + {-2099999, 14110899}, + {2099999, 14110899}, + {9135450, -43529}, + {9510560, -1020730}, + {9781479, -2031780}, + {9945219, -3065619}, + {10000000, -4110899}, + {9945219, -5156179}, + {9781479, -6190020}, + {9510560, -7201069}, + {9135450, -8178270}, + {8660249, -9110899}, + {8090169, -9988750}, + {7431449, -10802200}, + {6691309, -11542300}, + {5877850, -12201100}, + {5000000, -12771100}, + {4067369, -13246399}, + {3090169, -13621500}, + {2079119, -13892399}, + {1045279, -14056099}, + {0, -14110899}, + {-1045279, -14056099}, + {-2079119, -13892399}, + {-3090169, -13621500}, + {-4067369, -13246399}, + {-5000000, -12771100}, + {-5877850, -12201100}, + {-6691309, -11542300}, + {-7431449, -10802200}, + {-8090169, -9988750}, + {-8660249, -9110899}, + {-9135450, -8178270}, + {-9510560, -7201069}, + {-9781479, -6190020}, + {-9945219, -5156179}, + {-10000000, -4110899}, + {-9945219, -3065619}, + }, + { + {-9945219, -3065619}, + {-9781479, -2031780}, + {-9510560, -1020730}, + {-9135450, -43529}, + {-2099999, 14110899}, + {2099999, 14110899}, + {9135450, -43529}, + {9510560, -1020730}, + {9781479, -2031780}, + {9945219, -3065619}, + {10000000, -4110899}, + {9945219, -5156179}, + {9781479, -6190020}, + {9510560, -7201069}, + {9135450, -8178270}, + {8660249, -9110899}, + {8090169, -9988750}, + {7431449, -10802200}, + {6691309, -11542300}, + {5877850, -12201100}, + {5000000, -12771100}, + {4067369, -13246399}, + {3090169, -13621500}, + {2079119, -13892399}, + {1045279, -14056099}, + {0, -14110899}, + {-1045279, -14056099}, + {-2079119, -13892399}, + {-3090169, -13621500}, + {-4067369, -13246399}, + {-5000000, -12771100}, + {-5877850, -12201100}, + {-6691309, -11542300}, + {-7431449, -10802200}, + {-8090169, -9988750}, + {-8660249, -9110899}, + {-9135450, -8178270}, + {-9510560, -7201069}, + {-9781479, -6190020}, + {-9945219, -5156179}, + {-10000000, -4110899}, + {-9945219, -3065619}, + }, + { + {-9945219, -3065619}, + {-9781479, -2031780}, + {-9510560, -1020730}, + {-9135450, -43529}, + {-2099999, 14110899}, + {2099999, 14110899}, + {9135450, -43529}, + {9510560, -1020730}, + {9781479, -2031780}, + {9945219, -3065619}, + {10000000, -4110899}, + {9945219, -5156179}, + {9781479, -6190020}, + {9510560, -7201069}, + {9135450, -8178270}, + {8660249, -9110899}, + {8090169, -9988750}, + {7431449, -10802200}, + {6691309, -11542300}, + {5877850, -12201100}, + {5000000, -12771100}, + {4067369, -13246399}, + {3090169, -13621500}, + {2079119, -13892399}, + {1045279, -14056099}, + {0, -14110899}, + {-1045279, -14056099}, + {-2079119, -13892399}, + {-3090169, -13621500}, + {-4067369, -13246399}, + {-5000000, -12771100}, + {-5877850, -12201100}, + {-6691309, -11542300}, + {-7431449, -10802200}, + {-8090169, -9988750}, + {-8660249, -9110899}, + {-9135450, -8178270}, + {-9510560, -7201069}, + {-9781479, -6190020}, + {-9945219, -5156179}, + {-10000000, -4110899}, + {-9945219, -3065619}, + }, + { + {-9945219, -3065619}, + {-9781479, -2031780}, + {-9510560, -1020730}, + {-9135450, -43529}, + {-2099999, 14110899}, + {2099999, 14110899}, + {9135450, -43529}, + {9510560, -1020730}, + {9781479, -2031780}, + {9945219, -3065619}, + {10000000, -4110899}, + {9945219, -5156179}, + {9781479, -6190020}, + {9510560, -7201069}, + {9135450, -8178270}, + {8660249, -9110899}, + {8090169, -9988750}, + {7431449, -10802200}, + {6691309, -11542300}, + {5877850, -12201100}, + {5000000, -12771100}, + {4067369, -13246399}, + {3090169, -13621500}, + {2079119, -13892399}, + {1045279, -14056099}, + {0, -14110899}, + {-1045279, -14056099}, + {-2079119, -13892399}, + {-3090169, -13621500}, + {-4067369, -13246399}, + {-5000000, -12771100}, + {-5877850, -12201100}, + {-6691309, -11542300}, + {-7431449, -10802200}, + {-8090169, -9988750}, + {-8660249, -9110899}, + {-9135450, -8178270}, + {-9510560, -7201069}, + {-9781479, -6190020}, + {-9945219, -5156179}, + {-10000000, -4110899}, + {-9945219, -3065619}, + }, + { + {-9945219, -3065619}, + {-9781479, -2031780}, + {-9510560, -1020730}, + {-9135450, -43529}, + {-2099999, 14110899}, + {2099999, 14110899}, + {9135450, -43529}, + {9510560, -1020730}, + {9781479, -2031780}, + {9945219, -3065619}, + {10000000, -4110899}, + {9945219, -5156179}, + {9781479, -6190020}, + {9510560, -7201069}, + {9135450, -8178270}, + {8660249, -9110899}, + {8090169, -9988750}, + {7431449, -10802200}, + {6691309, -11542300}, + {5877850, -12201100}, + {5000000, -12771100}, + {4067369, -13246399}, + {3090169, -13621500}, + {2079119, -13892399}, + {1045279, -14056099}, + {0, -14110899}, + {-1045279, -14056099}, + {-2079119, -13892399}, + {-3090169, -13621500}, + {-4067369, -13246399}, + {-5000000, -12771100}, + {-5877850, -12201100}, + {-6691309, -11542300}, + {-7431449, -10802200}, + {-8090169, -9988750}, + {-8660249, -9110899}, + {-9135450, -8178270}, + {-9510560, -7201069}, + {-9781479, -6190020}, + {-9945219, -5156179}, + {-10000000, -4110899}, + {-9945219, -3065619}, + }, + { + {-9945219, -3065619}, + {-9781479, -2031780}, + {-9510560, -1020730}, + {-9135450, -43529}, + {-2099999, 14110899}, + {2099999, 14110899}, + {9135450, -43529}, + {9510560, -1020730}, + {9781479, -2031780}, + {9945219, -3065619}, + {10000000, -4110899}, + {9945219, -5156179}, + {9781479, -6190020}, + {9510560, -7201069}, + {9135450, -8178270}, + {8660249, -9110899}, + {8090169, -9988750}, + {7431449, -10802200}, + {6691309, -11542300}, + {5877850, -12201100}, + {5000000, -12771100}, + {4067369, -13246399}, + {3090169, -13621500}, + {2079119, -13892399}, + {1045279, -14056099}, + {0, -14110899}, + {-1045279, -14056099}, + {-2079119, -13892399}, + {-3090169, -13621500}, + {-4067369, -13246399}, + {-5000000, -12771100}, + {-5877850, -12201100}, + {-6691309, -11542300}, + {-7431449, -10802200}, + {-8090169, -9988750}, + {-8660249, -9110899}, + {-9135450, -8178270}, + {-9510560, -7201069}, + {-9781479, -6190020}, + {-9945219, -5156179}, + {-10000000, -4110899}, + {-9945219, -3065619}, + }, + { + {-18000000, -1000000}, + {-15000000, 22000000}, + {-11000000, 26000000}, + {11000000, 26000000}, + {15000000, 22000000}, + {18000000, -1000000}, + {18000000, -26000000}, + {-18000000, -26000000}, + {-18000000, -1000000}, }, }; @@ -445,14 +518,28 @@ void arrangeRectangles() { using Packer = Arranger; + Packer arrange(bin, min_obj_distance); + Packer::PlacementConfig pconf; pconf.alignment = NfpPlacer::Config::Alignment::CENTER; -// pconf.rotations = {0.0, Pi/2.0, Pi, 3*Pi/2}; + pconf.rotations = {0.0/*, Pi/2.0, Pi, 3*Pi/2*/}; + pconf.object_function = [&bin](NfpPlacer::Pile pile, double area, + double norm, double penality) { + + auto bb = ShapeLike::boundingBox(pile); + double score = (2*bb.width() + 2*bb.height()) / norm; + + if(!NfpPlacer::wouldFit(bb, bin)) score = 2*penality - score; + + return score; + }; + Packer::SelectionConfig sconf; sconf.allow_parallel = true; sconf.force_parallel = true; - sconf.try_reverse_order = false; - Packer arrange(bin, min_obj_distance, pconf, sconf); + sconf.try_reverse_order = true; + + arrange.configure(pconf, sconf); arrange.progressIndicator([&](unsigned r){ // svg::SVGWriter::Config conf; @@ -462,7 +549,7 @@ void arrangeRectangles() { // svgw.writePackGroup(arrange.lastResult()); // svgw.save("debout"); std::cout << "Remaining items: " << r << std::endl; - }).useMinimumBoundigBoxRotation(); + })/*.useMinimumBoundigBoxRotation()*/; Benchmark bench; diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 3e4c5daadd..a74c89d16b 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -480,8 +480,8 @@ bool arrange(Model &model, coordf_t dist, const Slic3r::BoundingBoxf* bb, SConf scfg; scfg.try_reverse_order = true; - scfg.allow_parallel = true; - scfg.force_parallel = true; + scfg.allow_parallel = false; + scfg.force_parallel = false; pcfg.alignment = PConf::Alignment::CENTER; @@ -489,6 +489,20 @@ bool arrange(Model &model, coordf_t dist, const Slic3r::BoundingBoxf* bb, // handle different rotations // arranger.useMinimumBoundigBoxRotation(); pcfg.rotations = { 0.0 }; + + pcfg.object_function = [&bin]( + NfpPlacer::Pile pile, double /*area*/, double norm, double penality) + { + auto bb = ShapeLike::boundingBox(pile); + + // We will optimize to the diameter of the circle around the bounding box + double score = PointLike::distance(bb.minCorner(), bb.maxCorner()) / norm; + + if(!NfpPlacer::wouldFit(bb, bin)) score = 2*penality - score; + + return score; + }; + Arranger arranger(bin, min_obj_distance, pcfg, scfg); arranger.progressIndicator(progressind);