Closed szakeetm closed 5 months ago
[!IMPORTANT] So it's important that library users appropriately scale paths in clipping operations when you would otherwise expect polygons with very small areas. (Alternatively, use the PathsD structure instead of Paths64 when clipping, since the library will perform the required scaling internally.)
Sorry, I don’t understand: my example does use PathsD (and not Paths64). I’ve read your link about robustness and still don’t understand why there’s no solution.
Your paths coordinates are too small and hence define very small polygons. And very small polygons in your solutions will be ignored. You need to scale you paths (eg by 10 or 100).
Your code already does the scaling by pow(10,8) since I set precision to 8 digits. I literally see it being converted to a Path64 with the coordinates... (0,100000000) (100000000,0) etc.
Your code already does the scaling by pow(10,8) since I set precision to 8 digits. I literally see it being converted to a Path64 with the coordinates... (0,100000000) (100000000,0) etc.
Oops, you're right. Sorry! I didn't look at your code properly 😱. I will look at your problem much more carefully and reply again soonish (< 24hrs).
#include <iostream>
#include "clipper2/clipper.h"
#include "clipper2/clipper.rectclip.h"
int main()
{
using namespace std;
using namespace Clipper2Lib;
PathsD subjects = { MakePathD({ 0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0 }) };
RectD rect(0.0, 0.0, 0.1, 0.1);
PathsD solution = RectClip(rect, subjects, 2);
std::cout << solution[0] << "\n";
return 0;
}
Produces ...
0.1,0.1, 0,0.1, 0,0, 0.1,0
Thank you. I’ll be next to a computer on Tuesday, I’ll have a look what is different, and get back to you.
With your Visual Studio solution, both your code and mine work.
If I #define USINGZ
before including clipper.h, I get an unhandled error (last function on the stack is ScalePath), both with your code and mine.
Could you please check if it's the same for you?
Output: 0.1,0.1,0, 0,0.1,0, 0,0,0, 0.1,0,0
After your screenshots I played around: The crash was caused because Visual Studio first compiles clipper.rectclip.cpp, which also includes clipper.h, but doesn't have the #define USINGZ directive. So once it was included with, and once without USINGZ. Setting the solution-wide preprocessor macro (your first screenshot) OR adding #define USINGZ in clipper.rectclip.cpp as well fixes the issue. If possible, please keep this ticket open until I confirm that it works with the CMake and vcpkg-based project as well. Thank you for your work so far.
I have tested with the large solution, and indeed, the problems were caused by manual USINGZ definitions, which are inconsistent (since it's hard to know which file will include clipper.h first).
If someone else contacts you about similar issue, the solution is:
#define USINGZ
manually, use USINGZ preprocessor macro in Visual Studio (like you did)#Clipper2Z
find_package(PkgConfig REQUIRED)
pkg_check_modules(Clipper2Z REQUIRED IMPORTED_TARGET Clipper2Z)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::Clipper2Z)
Thank you again for taking your time to debug this, and good luck for the project!
I try to clip a large square with a smaller square. I made an absolute minimal example to demonstrate. The returned paths vector is empty.
clipperbug.cpp:
CMakeLists.txt:
Output:
(The segfault is expected when trying to access solution[0])
Expected output:
Please note that this issue is part of a larger repository that fails to work after upgrading from 1.2.2 to 1.3.0. Clipper2 is installed with vcpkg.