So libnest2d is giving a segfault when it's being triggered without any disallowed areas. This is because we then give a single disallowed area for the border around the build plate, and give this disallowed area 0 vertices. Because libnest2d doesn't do defensive coding here, it's going to crash, taking Cura along with it. The crash is in libnest2d's function 'libnest2d::_Item<ClipperLib::Polygon>::rightmostTopVertex()'.
This segfault started happening recently in Cura. However it only happens when there are no disallowed areas. Steps to reproduce the error are:
- Use Custom FFF Printer.
- Set the Adhesion Type setting to 'None'.
- Load any two models.
I tracked the segfault down to this commit: 74ddbaab4b . That commit by itself is slightly mysterious but looks fine to me. It did give the hint that this segfault might be caused by empty polygons though. So for that reason, I figured that filtering out the empty polygons here in the arranger might fix it; and indeed it does. Passing empty polygons as fixed/disallowed areas is useless and invalid anyway. Apparently libnest2d doesn't deal well with it, but we might as well not send those polygons over then.
These were floats. Rounding numpy-floats still results in floats so I'm just using int(). The result is rounded down instead of nearest, but the difference is at most 50 nanometres anyway.
Contributes to issue CURA-7501.
When multiplying objects or inserting objects in the scene that do not fit in the buildplate, those
objects would correctly end up outside the buildplate, but their Z position would be aligned at the
absolute Z=0 of the buildplate.
This commit fixes that by compensating in the z-axis, properly moving the object outside the
buildplate in the correct z-position so that it's bottom is aligned with the original object.
CURA-7440
Also improve the filtering a bit so that it's no longer dependent on the order. Doesn't really matter in this case but it should be more robust.
Contributes to issue CURA-7754.