From 7040b2178d378547659e65d1bc89757e959afece Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 24 Mar 2023 12:30:09 -0700 Subject: [PATCH] Revert "Update for Clipper 1.2" This reverts commit e758391a239e89dedfd4913a5b75ea55a7bdfffd. --- libs/kimath/include/geometry/shape_poly_set.h | 2 +- libs/kimath/src/geometry/shape_poly_set.cpp | 18 ++++++++++----- .../include/clipper2/clipper.core.h | 2 +- .../Clipper2Lib/include/clipper2/clipper.h | 22 +++++++++---------- .../include/clipper2/clipper.offset.h | 4 ++-- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/libs/kimath/include/geometry/shape_poly_set.h b/libs/kimath/include/geometry/shape_poly_set.h index f8a7ce7a63..4ec8d82de8 100644 --- a/libs/kimath/include/geometry/shape_poly_set.h +++ b/libs/kimath/include/geometry/shape_poly_set.h @@ -1397,7 +1397,7 @@ private: void importPaths( Clipper2Lib::Paths64& paths, const std::vector& aZValueBuffer, const std::vector& aArcBuffe ); - void importPolyPath( const std::unique_ptr& aPolyPath, + void importPolyPath( Clipper2Lib::PolyPath64* aPolyPath, const std::vector& aZValueBuffer, const std::vector& aArcBuffer ); diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index 7fbc3474d7..4c129b91c7 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -1070,9 +1070,17 @@ void SHAPE_POLY_SET::inflate2( int aAmount, int aCircleSegCount, CORNER_STRATEGY c.ArcTolerance( std::abs( aAmount ) * coeff ); c.MiterLimit( miterLimit ); + c.MergeGroups( true ); + Paths64 solution = c.Execute( aAmount ); + // We get paths back but we need the tree to assign the holes to the correct + // outlines + Clipper64 c2; PolyTree64 tree; - c.Execute( aAmount, tree ); + c2.PreserveCollinear = false; + c2.ReverseSolution = false; + c2.AddSubject( solution ); + c2.Execute(ClipType::Union, FillRule::Positive, tree); importTree( tree, zValues, arcBuffer ); tree.Clear(); @@ -1112,7 +1120,7 @@ void SHAPE_POLY_SET::importTree( ClipperLib::PolyTree* tree, } -void SHAPE_POLY_SET::importPolyPath( const std::unique_ptr& aPolyPath, +void SHAPE_POLY_SET::importPolyPath( Clipper2Lib::PolyPath64* aPolyPath, const std::vector& aZValueBuffer, const std::vector& aArcBuffer ) { @@ -1122,11 +1130,11 @@ void SHAPE_POLY_SET::importPolyPath( const std::unique_ptrCount() + 1 ); paths.emplace_back( aPolyPath->Polygon(), aZValueBuffer, aArcBuffer ); - for( const std::unique_ptr& child : *aPolyPath ) + for( Clipper2Lib::PolyPath64* child : *aPolyPath ) { paths.emplace_back( child->Polygon(), aZValueBuffer, aArcBuffer ); - for( const std::unique_ptr& grandchild : *child ) + for( Clipper2Lib::PolyPath64* grandchild : *child ) importPolyPath( grandchild, aZValueBuffer, aArcBuffer ); } @@ -1141,7 +1149,7 @@ void SHAPE_POLY_SET::importTree( Clipper2Lib::PolyTree64& tree, { m_polys.clear(); - for( const std::unique_ptr& n : tree ) + for( Clipper2Lib::PolyPath64* n : tree ) importPolyPath( n, aZValueBuffer, aArcBuffer ); } diff --git a/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.core.h b/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.core.h index c8a63840f9..59ca9fd396 100644 --- a/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.core.h +++ b/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.core.h @@ -29,7 +29,7 @@ namespace Clipper2Lib public: explicit Clipper2Exception(const char* description) : m_descr(description) {} - virtual const char* what() const throw() override { return m_descr.c_str(); } + virtual const char* what() const throw() { return m_descr.c_str(); } private: std::string m_descr; }; diff --git a/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.h b/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.h index f66d9c4d51..009653c406 100644 --- a/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.h +++ b/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.h @@ -197,7 +197,7 @@ namespace Clipper2Lib { return result; } - inline Paths64 ClipRect(const Rect64& rect, + inline Paths64 RectClip(const Rect64& rect, const Paths64& paths, bool convex_only = false) { if (rect.IsEmpty() || paths.empty()) return Paths64(); @@ -205,7 +205,7 @@ namespace Clipper2Lib { return rc.Execute(paths, convex_only); } - inline Paths64 ClipRect(const Rect64& rect, + inline Paths64 RectClip(const Rect64& rect, const Path64& path, bool convex_only = false) { if (rect.IsEmpty() || path.empty()) return Paths64(); @@ -213,7 +213,7 @@ namespace Clipper2Lib { return rc.Execute(Paths64{ path }, convex_only); } - inline PathsD ClipRect(const RectD& rect, + inline PathsD RectClip(const RectD& rect, const PathsD& paths, bool convex_only = false, int precision = 2) { if (rect.IsEmpty() || paths.empty()) return PathsD(); @@ -229,30 +229,30 @@ namespace Clipper2Lib { rc.Execute(pp, convex_only), 1 / scale, error_code); } - inline PathsD ClipRect(const RectD& rect, + inline PathsD RectClip(const RectD& rect, const PathD& path, bool convex_only = false, int precision = 2) { - return ClipRect(rect, PathsD{ path }, convex_only, precision); + return RectClip(rect, PathsD{ path }, convex_only, precision); } - inline Paths64 ClipRectLines(const Rect64& rect, const Paths64& lines) + inline Paths64 RectClipLines(const Rect64& rect, const Paths64& lines) { if (rect.IsEmpty() || lines.empty()) return Paths64(); class RectClipLines rcl(rect); return rcl.Execute(lines); } - inline Paths64 ClipRectLines(const Rect64& rect, const Path64& line) + inline Paths64 RectClipLines(const Rect64& rect, const Path64& line) { - return ClipRectLines(rect, Paths64{ line }); + return RectClipLines(rect, Paths64{ line }); } - inline PathsD ClipRectLines(const RectD& rect, const PathD& line, int precision = 2) + inline PathsD RectClipLines(const RectD& rect, const PathD& line, int precision = 2) { - return ClipRect(rect, PathsD{ line }, precision); + return RectClip(rect, PathsD{ line }, precision); } - inline PathsD ClipRectLines(const RectD& rect, const PathsD& lines, int precision = 2) + inline PathsD RectClipLines(const RectD& rect, const PathsD& lines, int precision = 2) { if (rect.IsEmpty() || lines.empty()) return PathsD(); int error_code = 0; diff --git a/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.offset.h b/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.offset.h index b111a8e98f..455ed879d7 100644 --- a/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.offset.h +++ b/thirdparty/clipper2/Clipper2Lib/include/clipper2/clipper.offset.h @@ -36,8 +36,8 @@ private: bool is_reversed = false; JoinType join_type; EndType end_type; - Group(const Paths64& paths, JoinType _join_type, EndType _end_type) : - paths_in(paths), join_type(_join_type), end_type(_end_type) {} + Group(const Paths64& paths, JoinType join_type, EndType end_type) : + paths_in(paths), join_type(join_type), end_type(end_type) {} }; int error_code_ = 0;