From 040fd327abc9c7091165a1459da500a9debfe120 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Sat, 29 Jul 2023 10:12:54 +0500 Subject: [PATCH] SHAPE_POLY_SET: add BooleanXor() --- libs/kimath/include/geometry/shape_poly_set.h | 9 +++++++++ libs/kimath/src/geometry/shape_poly_set.cpp | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/libs/kimath/include/geometry/shape_poly_set.h b/libs/kimath/include/geometry/shape_poly_set.h index f8c7ad325a..6d331cf081 100644 --- a/libs/kimath/include/geometry/shape_poly_set.h +++ b/libs/kimath/include/geometry/shape_poly_set.h @@ -978,6 +978,10 @@ public: /// For \a aFastMode meaning, see function booleanOp void BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode ); + /// Perform boolean polyset exclusive or + /// For \a aFastMode meaning, see function booleanOp + void BooleanXor( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode ); + /// Perform boolean polyset union between a and b, store the result in it self /// For \a aFastMode meaning, see function booleanOp void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, @@ -993,6 +997,11 @@ public: void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode ); + /// Perform boolean polyset exclusive or between a and b, store the result in it self + /// For \a aFastMode meaning, see function booleanOp + void BooleanXor( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, + POLYGON_MODE aFastMode ); + /// define how inflate transform build inflated polygon enum CORNER_STRATEGY { diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index e5cb10e136..042cf01ede 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -877,6 +877,15 @@ void SHAPE_POLY_SET::BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE } +void SHAPE_POLY_SET::BooleanXor( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode ) +{ + if( ADVANCED_CFG::GetCfg().m_UseClipper2 ) + booleanOp( Clipper2Lib::ClipType::Xor, b ); + else + booleanOp( ClipperLib::ctXor, b, aFastMode ); +} + + void SHAPE_POLY_SET::BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode ) { @@ -907,6 +916,16 @@ void SHAPE_POLY_SET::BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_P } +void SHAPE_POLY_SET::BooleanXor( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, + POLYGON_MODE aFastMode ) +{ + if( ADVANCED_CFG::GetCfg().m_UseClipper2 ) + booleanOp( Clipper2Lib::ClipType::Xor, a, b ); + else + booleanOp( ClipperLib::ctXor, a, b, aFastMode ); +} + + void SHAPE_POLY_SET::InflateWithLinkedHoles( int aFactor, SHAPE_POLY_SET::CORNER_STRATEGY aCornerStrategy, int aMaxError, POLYGON_MODE aFastMode )