diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a5fc8387..c6f295150 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,8 +268,6 @@ set(LIBDIR_BIN ${CMAKE_CURRENT_BINARY_DIR}/src) include_directories(${LIBDIR}) # For generated header files include_directories(${LIBDIR_BIN}/platform) -# For libslic3r.h -include_directories(${LIBDIR}/clipper) if(WIN32) add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) diff --git a/src/clipper/CMakeLists.txt b/src/clipper/CMakeLists.txt index 8a4e92852..0362a4d84 100644 --- a/src/clipper/CMakeLists.txt +++ b/src/clipper/CMakeLists.txt @@ -2,8 +2,9 @@ project(clipper) cmake_minimum_required(VERSION 2.6) add_library(clipper STATIC - clipper.cpp - clipper.hpp +# We are using ClipperLib compiled as part of the libslic3r project using Slic3r::Point as its base type. +# clipper.cpp +# clipper.hpp clipper_z.cpp clipper_z.hpp ) diff --git a/src/clipper/clipper.cpp b/src/clipper/clipper.cpp index 9f1681007..06c91bf3a 100644 --- a/src/clipper/clipper.cpp +++ b/src/clipper/clipper.cpp @@ -61,11 +61,15 @@ #define CLIPPERLIB_PROFILE_BLOCK(name) #endif -#ifdef use_xyz +#ifdef CLIPPERLIB_NAMESPACE_PREFIX +namespace CLIPPERLIB_NAMESPACE_PREFIX { +#endif // CLIPPERLIB_NAMESPACE_PREFIX + +#ifdef CLIPPERLIB_USE_XYZ namespace ClipperLib_Z { -#else /* use_xyz */ +#else /* CLIPPERLIB_USE_XYZ */ namespace ClipperLib { -#endif /* use_xyz */ +#endif /* CLIPPERLIB_USE_XYZ */ static double const pi = 3.141592653589793238; static double const two_pi = pi *2; @@ -335,7 +339,7 @@ inline cInt TopX(TEdge &edge, const cInt currentY) void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip) { -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ ip.z() = 0; #endif @@ -467,7 +471,7 @@ inline void ReverseHorizontal(TEdge &e) //progression of the bounds - ie so their xbots will align with the //adjoining lower edge. [Helpful in the ProcessHorizontal() method.] std::swap(e.Top.x(), e.Bot.x()); -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ std::swap(e.Top.z(), e.Bot.z()); #endif } @@ -1073,7 +1077,7 @@ Clipper::Clipper(int initOptions) : m_StrictSimple = ((initOptions & ioStrictlySimple) != 0); m_PreserveCollinear = ((initOptions & ioPreserveCollinear) != 0); m_HasOpenPaths = false; -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ m_ZFill = 0; #endif } @@ -1637,7 +1641,7 @@ void Clipper::DeleteFromSEL(TEdge *e) } //------------------------------------------------------------------------------ -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ void Clipper::SetZ(IntPoint& pt, TEdge& e1, TEdge& e2) { if (pt.z() != 0 || !m_ZFill) return; @@ -1655,7 +1659,7 @@ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &Pt) bool e1Contributing = ( e1->OutIdx >= 0 ); bool e2Contributing = ( e2->OutIdx >= 0 ); -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ SetZ(Pt, *e1, *e2); #endif @@ -2641,7 +2645,7 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) (ePrev->Curr.x() == e->Curr.x()) && (ePrev->WindDelta != 0)) { IntPoint pt = e->Curr; -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ SetZ(pt, *ePrev, *e); #endif OutPt* op = AddOutPt(ePrev, pt); @@ -4204,3 +4208,7 @@ std::ostream& operator <<(std::ostream &s, const Paths &p) //------------------------------------------------------------------------------ } //ClipperLib namespace + +#ifdef CLIPPERLIB_NAMESPACE_PREFIX +} // namespace CLIPPERLIB_NAMESPACE_PREFIX +#endif // CLIPPERLIB_NAMESPACE_PREFIX diff --git a/src/clipper/clipper.hpp b/src/clipper/clipper.hpp index 31919ce75..c32bcf87b 100644 --- a/src/clipper/clipper.hpp +++ b/src/clipper/clipper.hpp @@ -41,8 +41,8 @@ #define CLIPPER_VERSION "6.2.6" -//use_xyz: adds a Z member to IntPoint. Adds a minor cost to perfomance. -//#define use_xyz +//CLIPPERLIB_USE_XYZ: adds a Z member to IntPoint. Adds a minor cost to perfomance. +//#define CLIPPERLIB_USE_XYZ //use_lines: Enables line clipping. Adds a very minor cost to performance. #define use_lines @@ -59,11 +59,15 @@ #include #include -#ifdef use_xyz -namespace ClipperLib_Z { -#else /* use_xyz */ -namespace ClipperLib { -#endif /* use_xyz */ +#ifdef CLIPPERLIB_NAMESPACE_PREFIX + namespace CLIPPERLIB_NAMESPACE_PREFIX { +#endif // CLIPPERLIB_NAMESPACE_PREFIX + +#ifdef CLIPPERLIB_USE_XYZ + namespace ClipperLib_Z { +#else + namespace ClipperLib { +#endif enum ClipType { ctIntersection, ctUnion, ctDifference, ctXor }; enum PolyType { ptSubject, ptClip }; @@ -90,43 +94,20 @@ enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative }; static constexpr cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL; #endif // CLIPPERLIB_INT32 -#if 1 +#ifdef CLIPPERLIB_INTPOINT_TYPE +using IntPoint = CLIPPERLIB_INTPOINT_TYPE; +#else // CLIPPERLIB_INTPOINT_TYPE using IntPoint = Eigen::Matrix; -using DoublePoint = Eigen::Matrix; -#else -struct IntPoint { - cInt X; - cInt Y; -#ifdef use_xyz - cInt Z; - IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {}; -#else - IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {}; -#endif +#endif // CLIPPERLIB_INTPOINT_TYPE + +using DoublePoint = Eigen::Matrix; - friend inline bool operator== (const IntPoint& a, const IntPoint& b) - { - return a.X == b.X && a.Y == b.Y; - } - friend inline bool operator!= (const IntPoint& a, const IntPoint& b) - { - return a.X != b.X || a.Y != b.Y; - } -}; -struct DoublePoint -{ - double X; - double Y; - DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {} - DoublePoint(IntPoint ip) : X((double)ip.x()), Y((double)ip.y()) {} -}; -#endif //------------------------------------------------------------------------------ typedef std::vector Path; @@ -141,7 +122,7 @@ std::ostream& operator <<(std::ostream &s, const Paths &p); //------------------------------------------------------------------------------ -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ typedef std::function ZFillCallback; #endif @@ -282,11 +263,11 @@ enum EdgeSide { esLeft = 1, esRight = 2}; }; // Point of an output polygon. - // 36B on 64bit system without use_xyz. + // 36B on 64bit system without CLIPPERLIB_USE_XYZ. struct OutPt { // 4B int Idx; - // 16B without use_xyz / 24B with use_xyz + // 16B without CLIPPERLIB_USE_XYZ / 24B with CLIPPERLIB_USE_XYZ IntPoint Pt; // 4B on 32bit system, 8B on 64bit system OutPt *Next; @@ -381,7 +362,7 @@ public: bool StrictlySimple() const {return m_StrictSimple;}; void StrictlySimple(bool value) {m_StrictSimple = value;}; //set the callback function for z value filling on intersections (otherwise Z is 0) -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ void ZFillFunction(ZFillCallback zFillFunc) { m_ZFill = zFillFunc; } #endif protected: @@ -414,7 +395,7 @@ private: // Does the result go to a PolyTree or Paths? bool m_UsingPolyTree; bool m_StrictSimple; -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ ZFillCallback m_ZFill; //custom callback #endif void SetWindingCount(TEdge& edge) const; @@ -467,7 +448,7 @@ private: void DoSimplePolygons(); void FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec) const; void FixupFirstLefts2(OutRec* OldOutRec, OutRec* NewOutRec) const; -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ void SetZ(IntPoint& pt, TEdge& e1, TEdge& e2); #endif }; @@ -519,6 +500,8 @@ class clipperException : public std::exception } //ClipperLib namespace +#ifdef CLIPPERLIB_NAMESPACE_PREFIX +} // namespace CLIPPERLIB_NAMESPACE_PREFIX +#endif // CLIPPERLIB_NAMESPACE_PREFIX + #endif //clipper_hpp - - diff --git a/src/clipper/clipper_z.cpp b/src/clipper/clipper_z.cpp index 4a54ef346..f26be7089 100644 --- a/src/clipper/clipper_z.cpp +++ b/src/clipper/clipper_z.cpp @@ -1,7 +1,7 @@ // Hackish wrapper around the ClipperLib library to compile the Clipper library with the Z support. // Enable the Z coordinate support. -#define use_xyz +#define CLIPPERLIB_USE_XYZ // and let it compile #include "clipper.cpp" diff --git a/src/clipper/clipper_z.hpp b/src/clipper/clipper_z.hpp index e5e7d48ce..20596d8e1 100644 --- a/src/clipper/clipper_z.hpp +++ b/src/clipper/clipper_z.hpp @@ -2,17 +2,17 @@ #ifndef clipper_z_hpp #ifdef clipper_hpp -#error "You should include the clipper_z.hpp first" +#error "You should include clipper_z.hpp before clipper.hpp" #endif #define clipper_z_hpp // Enable the Z coordinate support. -#define use_xyz +#define CLIPPERLIB_USE_XYZ #include "clipper.hpp" #undef clipper_hpp -#undef use_xyz +#undef CLIPPERLIB_USE_XYZ #endif // clipper_z_hpp diff --git a/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp b/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp index 498523180..14b075b19 100644 --- a/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp +++ b/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp @@ -132,14 +132,14 @@ template<> inline void offset(Slic3r::ExPolygon& sh, coord_t distance, const PolygonTag&) { #define DISABLE_BOOST_OFFSET - auto res = Slic3r::offset_ex(sh, distance, ClipperLib::jtSquare); + auto res = Slic3r::offset_ex(sh, distance, Slic3r::ClipperLib::jtSquare); if (!res.empty()) sh = res.front(); } template<> inline void offset(Slic3r::Polygon& sh, coord_t distance, const PathTag&) { - auto res = Slic3r::offset(sh, distance, ClipperLib::jtSquare); + auto res = Slic3r::offset(sh, distance, Slic3r::ClipperLib::jtSquare); if (!res.empty()) sh = res.front(); } diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index d458b03cf..61a32678b 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -54,7 +54,7 @@ namespace Slic3r { template, int...EigenArgs> inline constexpr Eigen::Matrix unscaled( - const ClipperLib::IntPoint &v) noexcept + const Slic3r::ClipperLib::IntPoint &v) noexcept { return Eigen::Matrix{unscaled(v.x()), unscaled(v.y())}; @@ -616,7 +616,7 @@ void arrange(ArrangePolygons & arrangables, const BedT & bed, const ArrangeParams & params) { - namespace clppr = ClipperLib; + namespace clppr = Slic3r::ClipperLib; std::vector items, fixeditems; items.reserve(arrangables.size()); diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 2abe94656..16299f442 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -23,6 +23,8 @@ add_library(libslic3r STATIC BridgeDetector.hpp Brim.cpp Brim.hpp + clipper.cpp + clipper.hpp ClipperUtils.cpp ClipperUtils.hpp Config.cpp diff --git a/src/libslic3r/ClipperUtils.hpp b/src/libslic3r/ClipperUtils.hpp index 6668a9ae9..0a34fc93b 100644 --- a/src/libslic3r/ClipperUtils.hpp +++ b/src/libslic3r/ClipperUtils.hpp @@ -8,9 +8,9 @@ #include "Surface.hpp" // import these wherever we're included -using ClipperLib::jtMiter; -using ClipperLib::jtRound; -using ClipperLib::jtSquare; +using Slic3r::ClipperLib::jtMiter; +using Slic3r::ClipperLib::jtRound; +using Slic3r::ClipperLib::jtSquare; #define CLIPPERUTILS_UNSAFE_OFFSET diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index f6f4f5618..c6af515c8 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -22,12 +22,14 @@ #pragma warning(pop) #endif // _MSC_VER -namespace ClipperLib { -class PolyNode; -using PolyNodes = std::vector; -} +namespace Slic3r { -namespace Slic3r { namespace Geometry { + namespace ClipperLib { + class PolyNode; + using PolyNodes = std::vector; + } + +namespace Geometry { // Generic result of an orientation predicate. enum Orientation @@ -530,6 +532,6 @@ inline bool is_rotation_ninety_degrees(const Vec3d &rotation) return is_rotation_ninety_degrees(rotation.x()) && is_rotation_ninety_degrees(rotation.y()) && is_rotation_ninety_degrees(rotation.z()); } -} } +} } // namespace Slicer::Geometry #endif diff --git a/src/libslic3r/pchheader.hpp b/src/libslic3r/pchheader.hpp index 9386fdf36..b55755b89 100644 --- a/src/libslic3r/pchheader.hpp +++ b/src/libslic3r/pchheader.hpp @@ -114,7 +114,7 @@ #include #include -#include +#include "clipper.hpp" #include "BoundingBox.hpp" #include "ClipperUtils.hpp" #include "Config.hpp" @@ -129,8 +129,6 @@ #include "libslic3r.h" #include "libslic3r_version.h" -#include "clipper.hpp" - #include #include diff --git a/tests/libnest2d/libnest2d_tests_main.cpp b/tests/libnest2d/libnest2d_tests_main.cpp index 181f130e5..97c7ef99d 100644 --- a/tests/libnest2d/libnest2d_tests_main.cpp +++ b/tests/libnest2d/libnest2d_tests_main.cpp @@ -1152,7 +1152,7 @@ template MultiPolygon merged_pile(It from, It to, int bin_id) TEST_CASE("Test for bed center distance optimization", "[Nesting], [NestKernels]") { - static const constexpr ClipperLib::cInt W = 10000000; + static const constexpr Slic3r::ClipperLib::cInt W = 10000000; // Get the input items and define the bin. std::vector input(9, {W, W}); @@ -1187,7 +1187,7 @@ TEST_CASE("Test for bed center distance optimization", "[Nesting], [NestKernels] TEST_CASE("Test for biggest bounding box area", "[Nesting], [NestKernels]") { - static const constexpr ClipperLib::cInt W = 10000000; + static const constexpr Slic3r::ClipperLib::cInt W = 10000000; static const constexpr size_t N = 100; // Get the input items and define the bin. diff --git a/xs/xsp/Clipper.xsp b/xs/xsp/Clipper.xsp index 277b59825..a39db6140 100644 --- a/xs/xsp/Clipper.xsp +++ b/xs/xsp/Clipper.xsp @@ -2,7 +2,6 @@ %{ #include -#include "clipper.hpp" #include "libslic3r/ClipperUtils.hpp" %}