diff --git a/src/libslic3r/MTUtils.hpp b/src/libslic3r/MTUtils.hpp index 0afe3563f..f6bff2b1f 100644 --- a/src/libslic3r/MTUtils.hpp +++ b/src/libslic3r/MTUtils.hpp @@ -191,6 +191,15 @@ template bool all_of(const C &container) { }); } +template inline X ceil_i(X x, Y y) +{ + static_assert(std::is_integral::value && + std::is_integral::value && sizeof(X) >= sizeof(Y), + ""); + + return (x % y) ? x / y + 1 : x / y; +} + } #endif // MTUTILS_HPP diff --git a/src/libslic3r/ModelArrange.cpp b/src/libslic3r/ModelArrange.cpp index a440c3999..36f7e3971 100644 --- a/src/libslic3r/ModelArrange.cpp +++ b/src/libslic3r/ModelArrange.cpp @@ -2,6 +2,7 @@ #include "Model.hpp" #include "Geometry.hpp" #include "SVG.hpp" +#include "MTUtils.hpp" #include @@ -820,15 +821,13 @@ bool arrange(Model &model, // The model with the geometries BoundingBox bbb(bed); auto& cfn = stopcondition; + + coord_t md = ceil_i(min_obj_distance, 2) - SCALED_EPSILON; - auto binbb = Box({ - static_cast(bbb.min(0)), - static_cast(bbb.min(1)) - }, - { - static_cast(bbb.max(0)), - static_cast(bbb.max(1)) - }); + auto binbb = Box({libnest2d::Coord{bbb.min(0)} - md, + libnest2d::Coord{bbb.min(1)} - md}, + {libnest2d::Coord{bbb.max(0)} + md, + libnest2d::Coord{bbb.max(1)} + md}); switch(bedhint.type) { case BedShapeType::BOX: { @@ -916,15 +915,13 @@ void find_new_position(const Model &model, BedShapeHint bedhint = bedShape(bed); BoundingBox bbb(bed); - - auto binbb = Box({ - static_cast(bbb.min(0)), - static_cast(bbb.min(1)) - }, - { - static_cast(bbb.max(0)), - static_cast(bbb.max(1)) - }); + + coord_t md = ceil_i(min_obj_distance, 2) - SCALED_EPSILON; + + auto binbb = Box({libnest2d::Coord{bbb.min(0)} - md, + libnest2d::Coord{bbb.min(1)} - md}, + {libnest2d::Coord{bbb.max(0)} + md, + libnest2d::Coord{bbb.max(1)} + md}); for(auto it = shapemap.begin(); it != shapemap.end(); ++it) { if(std::find(toadd.begin(), toadd.end(), it->first) == toadd.end()) {