tamasmeszaros/libnest2d

Latest update

samsonsite1 opened this issue · 11 comments

The October update appears to be broken. The provided examples don't work anymore. The code doesn't fully execute without crashing. Do you plan to address these issues? Thanks.

Hello,
of course I will fix the issues as fast as I can. Could you please specify on which platform did the crash occur?

Windows. I would try to fix the crash myself, but I'm still learning. This code uses advanced c++ syntax. Any help is appreciated.

I assume this is the same issue as in #6 I tried but could not reproduce the issue. The tests and the example runs just fine on all the supported MSVC versions (2015-19).

Your usage of CMake is not the standard but this should not be the issue. Anyway, I recommend you to grab the latest master (as of now) and do configure the project with -DRP_ENABLE_DOWNLOADING=ON and -DLIBNEST2D_BUILD_UNITTESTS=ON then build and run ctest in the build directory to see if everything works. The GeometryException is triggered when an invalid geometry is being processed or generated so if you use your own geometries, check if the following applies to all of them:

  • Polygons are at least triangles (no single point or line segment)
  • The first vertex is exactly the same as the last. (This indicates a closed polygon for boost::geometry)
  • All the polygons are in clockwise order
  • All the polygons are convex. Concave polygons are not supported and I can't even make an estimation of when this is going to happen.

Best regards

Thank you, everything seems to be working again. I don't know what was causing the previous errors.

BTW, before this update, cmake had an entry called LIBNEST2D_BUILD_EXAMPLES. This entry appears to be missing. Is there a reason why you removed it, if not, could you please add it back?

I preferred using LIBNEST2D_BUILD_EXAMPLES instead of unit tests, because it doesn't require the Catch2 package, so it was easier for me to compile and test.

Yes, I removed the examples switch because I wanted it to be an example project that uses libnest2d and not something that is part of libnest2d library. The rationale is that when you create a new clean project and want to use this library, you have to set up the environment so that your dependencies can be found. So if you build and install libnest2d and after that configure the examples subdir, cmake should find libnest with the find_package command and set it up for you. If you install libnest into a non standard directory, you can specify that with -DCMAKE_PREFIX_PATH=<install_dir> when you configure the example subdir.

This might seem more complicated than just switching on the examples switch, but this way I can test if the exported config scripts are correct and libnest (as an installed project) can be found by cmake.

BTW catch2 is gets also downloaded and installed into the build dir if you enable downloading.

I also noticed another change. Polygons have both transformed and untransformed coords, correct?

Before the update, I recall that after the items were nested, the transformed coords returned were all positive. Now, it seems they're all centered at the origin, with some coords negative.

When this item list gets sent to SVGWriter, it also writes out negative coords, so when I try to view the .svg, half of the shape is clipped in negative space.

Is this correct?
How can I fix it so all transformed coords are positive?

Can be. Move the items to the center of the bin with the translate function.

Ok, thanks for your help. I moved my coords to positive space, but it seems my .svg file is still getting clipped. When I open it in a text editor, I do see there are still some negative coords being written. I will have to take a closer look to see what's going on.

Thank you and good luck with it. If you find some issues feel free to report them. Unfortunately, I will not have the cycles in the foreseeable future to improve svg writer. It was only included for debugging in the first place.

I finally figured it out. Apparently, I need to set the bin center, then all points should be positive.
Box() constructor takes a center point too, so easiest way to do it is just add the center here.

// old
//auto result = nest(input, Box(150000000, 150000000));

// better
size_t box_size = 150000000;
size_t bins = nest(input, Box( box_size, box_size, {box_size>>1, box_size>>1} ));