diff options
author | tamasmeszaros <meszaros.q@gmail.com> | 2019-07-02 16:24:40 +0300 |
---|---|---|
committer | tamasmeszaros <meszaros.q@gmail.com> | 2019-07-02 16:24:40 +0300 |
commit | 87c5e9bbaa264db564bfd8bd6a2f9238791ee2e8 (patch) | |
tree | 1bb550b5dac23e655623c349f5e9e09371d941d4 /src/libnest2d | |
parent | 914bf632288f036b2b7cb509eb5ba843cdc3b7ed (diff) |
Partial arrange starts to work again.
Diffstat (limited to 'src/libnest2d')
-rw-r--r-- | src/libnest2d/include/libnest2d/geometry_traits.hpp | 26 | ||||
-rw-r--r-- | src/libnest2d/include/libnest2d/libnest2d.hpp | 5 | ||||
-rw-r--r-- | src/libnest2d/include/libnest2d/placers/nfpplacer.hpp | 31 |
3 files changed, 36 insertions, 26 deletions
diff --git a/src/libnest2d/include/libnest2d/geometry_traits.hpp b/src/libnest2d/include/libnest2d/geometry_traits.hpp index 6c55d0e3f..345252f12 100644 --- a/src/libnest2d/include/libnest2d/geometry_traits.hpp +++ b/src/libnest2d/include/libnest2d/geometry_traits.hpp @@ -875,6 +875,28 @@ inline _Box<TPoint<S>> boundingBox(const S& sh) return boundingBox(sh, Tag<S>() ); } +template<class P> _Box<P> boundingBox(const _Box<P>& bb1, const _Box<P>& bb2 ) +{ + auto& pminc = bb1.minCorner(); + auto& pmaxc = bb1.maxCorner(); + auto& iminc = bb2.minCorner(); + auto& imaxc = bb2.maxCorner(); + P minc, maxc; + + setX(minc, std::min(getX(pminc), getX(iminc))); + setY(minc, std::min(getY(pminc), getY(iminc))); + + setX(maxc, std::max(getX(pmaxc), getX(imaxc))); + setY(maxc, std::max(getY(pmaxc), getY(imaxc))); + return _Box<P>(minc, maxc); +} + +template<class S1, class S2> +_Box<TPoint<S1>> boundingBox(const S1 &s1, const S2 &s2) +{ + return boundingBox(boundingBox(s1), boundingBox(s2)); +} + template<class Box> inline double area(const Box& box, const BoxTag& ) { @@ -1060,8 +1082,8 @@ template<class TB, class TC> inline bool isInside(const TB& box, const TC& circ, const BoxTag&, const CircleTag&) { - return isInside(box.minCorner(), circ, BoxTag(), CircleTag()) && - isInside(box.maxCorner(), circ, BoxTag(), CircleTag()); + return isInside(box.minCorner(), circ, PointTag(), CircleTag()) && + isInside(box.maxCorner(), circ, PointTag(), CircleTag()); } template<class TBGuest, class TBHost> diff --git a/src/libnest2d/include/libnest2d/libnest2d.hpp b/src/libnest2d/include/libnest2d/libnest2d.hpp index c7d515d49..ab018f3f8 100644 --- a/src/libnest2d/include/libnest2d/libnest2d.hpp +++ b/src/libnest2d/include/libnest2d/libnest2d.hpp @@ -895,7 +895,10 @@ private: template<class TIter> inline void __execute(TIter from, TIter to) { if(min_obj_distance_ > 0) std::for_each(from, to, [this](Item& item) { - item.addOffset(static_cast<Coord>(std::ceil(min_obj_distance_/2.0))); + auto offs = min_obj_distance_; + if (item.isFixed()) offs *= 0.99; + + item.addOffset(static_cast<Coord>(std::ceil(offs/2.0))); }); selector_.template packItems<PlacementStrategy>( diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp index c1f15fe61..b94443bff 100644 --- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp @@ -801,7 +801,6 @@ private: // optimize config_.object_function = prev_func; } - } struct Optimum { @@ -816,29 +815,14 @@ private: class Optimizer: public opt::TOptimizer<opt::Method::L_SUBPLEX> { public: - Optimizer() { + Optimizer(float accuracy = 1.f) { opt::StopCriteria stopcr; - stopcr.max_iterations = 200; + stopcr.max_iterations = unsigned(std::floor(1000 * accuracy)); stopcr.relative_score_difference = 1e-20; this->stopcr_ = stopcr; } }; - static Box boundingBox(const Box& pilebb, const Box& ibb ) { - auto& pminc = pilebb.minCorner(); - auto& pmaxc = pilebb.maxCorner(); - auto& iminc = ibb.minCorner(); - auto& imaxc = ibb.maxCorner(); - Vertex minc, maxc; - - setX(minc, std::min(getX(pminc), getX(iminc))); - setY(minc, std::min(getY(pminc), getY(iminc))); - - setX(maxc, std::max(getX(pmaxc), getX(imaxc))); - setY(maxc, std::max(getY(pmaxc), getY(imaxc))); - return Box(minc, maxc); - } - using Edges = EdgeCache<RawShape>; template<class Range = ConstItemRange<typename Base::DefaultIter>> @@ -935,7 +919,7 @@ private: _objfunc = [norm, binbb, pbb, ins_check](const Item& item) { auto ibb = item.boundingBox(); - auto fullbb = boundingBox(pbb, ibb); + auto fullbb = sl::boundingBox(pbb, ibb); double score = pl::distance(ibb.center(), binbb.center()); @@ -1005,14 +989,15 @@ private: auto& rofn = rawobjfunc; auto& nfpoint = getNfpPoint; + float accuracy = config_.accuracy; __parallel::enumerate( cache.corners().begin(), cache.corners().end(), - [&results, &item, &rofn, &nfpoint, ch] + [&results, &item, &rofn, &nfpoint, ch, accuracy] (double pos, size_t n) { - Optimizer solver; + Optimizer solver(accuracy); Item itemcpy = item; auto contour_ofn = [&rofn, &nfpoint, ch, &itemcpy] @@ -1059,10 +1044,10 @@ private: __parallel::enumerate(cache.corners(hidx).begin(), cache.corners(hidx).end(), [&results, &item, &nfpoint, - &rofn, ch, hidx] + &rofn, ch, hidx, accuracy] (double pos, size_t n) { - Optimizer solver; + Optimizer solver(accuracy); Item itmcpy = item; auto hole_ofn = |