Don't arrange items if the bed has negative area

Also interpret a bounding box with maxCorner lower then minCorner as a negative area box
This commit is contained in:
tamasmeszaros 2022-09-13 16:51:20 +02:00
parent 3e53abf9bd
commit 6197acf576
2 changed files with 13 additions and 6 deletions

View File

@ -198,9 +198,10 @@ public:
inline P center() const BP2D_NOEXCEPT; inline P center() const BP2D_NOEXCEPT;
template<class Unit = TCompute<P>> template<class Unit = TCompute<P>>
inline Unit area() const BP2D_NOEXCEPT { inline Unit area() const BP2D_NOEXCEPT {
return Unit(width())*height(); Unit s = std::signbit(width()) || std::signbit(height()) ? Unit(-1) : Unit(1);
return s * libnest2d::abs(width() * height());
} }
static inline _Box infinite(const P &center = {TCoord<P>(0), TCoord<P>(0)}); static inline _Box infinite(const P &center = {TCoord<P>(0), TCoord<P>(0)});

View File

@ -497,11 +497,11 @@ void _arrange(
mod_params.min_obj_distance = 0; mod_params.min_obj_distance = 0;
AutoArranger<BinT> arranger{corrected_bin, mod_params, progressfn, stopfn}; AutoArranger<BinT> arranger{corrected_bin, mod_params, progressfn, stopfn};
auto infl = coord_t(std::ceil(params.min_obj_distance / 2.0)); auto infl = coord_t(std::ceil(params.min_obj_distance / 2.0));
for (Item& itm : shapes) itm.inflate(infl); for (Item& itm : shapes) itm.inflate(infl);
for (Item& itm : excludes) itm.inflate(infl); for (Item& itm : excludes) itm.inflate(infl);
remove_large_items(excludes, corrected_bin); remove_large_items(excludes, corrected_bin);
// If there is something on the plate // If there is something on the plate
@ -511,7 +511,7 @@ void _arrange(
inp.reserve(shapes.size() + excludes.size()); inp.reserve(shapes.size() + excludes.size());
for (auto &itm : shapes ) inp.emplace_back(itm); for (auto &itm : shapes ) inp.emplace_back(itm);
for (auto &itm : excludes) inp.emplace_back(itm); for (auto &itm : excludes) inp.emplace_back(itm);
// Use the minimum bounding box rotation as a starting point. // Use the minimum bounding box rotation as a starting point.
// TODO: This only works for convex hull. If we ever switch to concave // TODO: This only works for convex hull. If we ever switch to concave
// polygon nesting, a convex hull needs to be calculated. // polygon nesting, a convex hull needs to be calculated.
@ -528,7 +528,13 @@ void _arrange(
} }
} }
arranger(inp.begin(), inp.end()); if (sl::area(corrected_bin) > 0)
arranger(inp.begin(), inp.end());
else {
for (Item &itm : inp)
itm.binId(BIN_ID_UNSET);
}
for (Item &itm : inp) itm.inflate(-infl); for (Item &itm : inp) itm.inflate(-infl);
} }