← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] No more boost::polygon in Kicad

 

Hello Tomasz,

I made some additions to the shape_poly_set library. I appreciate if you can have a look in the additions and if you agree with that to commit it to trunk.
There are no changes related with current used source in the trunk so should be no problem ( I am just using it in my branch at the moment)

I implemented the "HoleCount" function but I had a little difficult to understand it in the beginning so you may want give more attention in that one.

I fix a little error in the Function booleanOp documentation header.
Also I was looking for the propose of the aFastMode ( JP added it related with 3d viewer? to make it faster ), I was thinking that (in my case) it is important the really mean of the result of the "aFastMode" (i.e: weak or strictly polygon) so maybe we should name it by the real propose?

Thanks!
Mario Luzeiro

________________________________________
From: Tomasz Wlostowski [tomasz.wlostowski@xxxxxxx]
Sent: 21 August 2015 23:19
To: Mário Luzeiro; Kicad Developers
Subject: Re: [Kicad-developers] [PATCH] No more boost::polygon in Kicad

On 21.08.2015 23:15, Mário Luzeiro wrote:
> Hi Tomasz, all,
>
> after remove boost, I also noted that you remove ExportTo functions.
> Are there any way (already implemented) that I can export to a ClipperLib::Paths ?

Hi Mario,

SHAPE_POLY_SET internally uses ClipperLib::Paths. Please don't use this
structure directly in Kicad code, if there's any missing functionality,
extend SHAPE_POLY_SET instead. It will save us time in the future if
we'll decide to go for yet another polygon library (or use a bit of one
and a bit of another).

Tom


>
> Mario
> ________________________________________
> From: Kicad-developers [kicad-developers-bounces+mrluzeiro=ua.pt@xxxxxxxxxxxxxxxxxxx] on behalf of Tomasz Wlostowski [tomasz.wlostowski@xxxxxxx]
> Sent: 13 July 2015 23:46
> To: Kicad Developers
> Subject: [Kicad-developers] [PATCH] No more boost::polygon in Kicad
>
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: mrluzeiro@xxxxx-20150823195258-trgn5lic8wz0eefb
# target_branch: lp:kicad
# testament_sha1: b297d900823c6c87dd0b4e5a507c2656cde2c216
# timestamp: 2015-08-23 20:53:33 +0100
# base_revision_id: maciej.suminski@xxxxxxx-20150819160716-\
#   vpk6haakbbg5itfr
# 
# Begin patch
=== modified file 'common/geometry/shape_poly_set.cpp'
--- common/geometry/shape_poly_set.cpp	2015-08-19 16:07:16 +0000
+++ common/geometry/shape_poly_set.cpp	2015-08-23 19:52:58 +0000
@@ -234,6 +234,36 @@
 }
 
 
+void SHAPE_POLY_SET::booleanOp( ClipperLib::ClipType aType,
+                                const SHAPE_POLY_SET& aShape,
+                                const SHAPE_POLY_SET& aOtherShape,
+                                bool aFastMode )
+{
+    Clipper c;
+
+    if( !aFastMode )
+        c.StrictlySimple( true );
+
+    BOOST_FOREACH( const POLYGON& poly, aShape.m_polys )
+    {
+        for( unsigned int i = 0; i < poly.size(); i++ )
+            c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptSubject, true );
+    }
+
+    BOOST_FOREACH( const POLYGON& poly, aOtherShape.m_polys )
+    {
+        for( unsigned int i = 0; i < poly.size(); i++ )
+            c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptClip, true );
+    }
+
+    PolyTree solution;
+
+    c.Execute( aType, solution, pftNonZero, pftNonZero );
+
+    importTree( &solution );
+}
+
+
 void SHAPE_POLY_SET::BooleanAdd( const SHAPE_POLY_SET& b, bool aFastMode )
 {
     booleanOp( ctUnion, b, aFastMode );
@@ -246,6 +276,30 @@
 }
 
 
+void SHAPE_POLY_SET::BooleanIntersection( const SHAPE_POLY_SET& b, bool aFastMode )
+{
+    booleanOp( ctIntersection, b, aFastMode );
+}
+
+
+void SHAPE_POLY_SET::BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, bool aFastMode )
+{
+    booleanOp( ctUnion, a, b, aFastMode );
+}
+
+
+void SHAPE_POLY_SET::BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, bool aFastMode )
+{
+    booleanOp( ctDifference, a, b, aFastMode );
+}
+
+
+void SHAPE_POLY_SET::BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, bool aFastMode )
+{
+    booleanOp( ctIntersection, a, b, aFastMode );
+}
+
+
 void SHAPE_POLY_SET::Inflate( int aFactor, int aCircleSegmentsCount )
 {
     ClipperOffset c;

=== modified file 'include/geometry/shape_poly_set.h'
--- include/geometry/shape_poly_set.h	2015-08-16 12:07:58 +0000
+++ include/geometry/shape_poly_set.h	2015-08-23 19:52:58 +0000
@@ -162,7 +162,12 @@
         int VertexCount( int aOutline = -1, int aHole = -1 ) const;
 
         ///> Returns the number of holes in a given outline
-        int HoleCount( int aOutline ) const;
+        int HoleCount( int aOutline ) const
+        {
+            if( (aOutline > (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
+                return 0;
+            return m_polys[aOutline].size() - 1;
+        }
 
         ///> Returns the reference to aIndex-th outline in the set
         SHAPE_LINE_CHAIN& Outline( int aIndex )
@@ -247,20 +252,35 @@
 
         ///> Performs boolean polyset union
         ///> For aFastMode meaning, see function booleanOp
-
         void BooleanAdd( const SHAPE_POLY_SET& b, bool aFastMode = false );
 
         ///> Performs boolean polyset difference
         ///> For aFastMode meaning, see function booleanOp
         void BooleanSubtract( const SHAPE_POLY_SET& b, bool aFastMode = false );
 
+        ///> Performs boolean polyset intersection
+        ///> For aFastMode meaning, see function booleanOp
+        void BooleanIntersection( const SHAPE_POLY_SET& b, bool aFastMode = false );
+
+        ///> Performs boolean polyset union between a and b, store the result in it self
+        ///> For aFastMode meaning, see function booleanOp
+        void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, bool aFastMode = false );
+
+        ///> Performs boolean polyset difference between a and b, store the result in it self
+        ///> For aFastMode meaning, see function booleanOp
+        void BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, bool aFastMode = false );
+
+        ///> Performs boolean polyset intersection between a and b, store the result in it self
+        ///> For aFastMode meaning, see function booleanOp
+        void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b, bool aFastMode = false );
+
         ///> Performs outline inflation/deflation, using round corners.
         void Inflate( int aFactor, int aCircleSegmentsCount );
 
         ///> Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the outer ring
         ///> to the inner holes
         ///> For aFastMode meaning, see function booleanOp
-        void Fracture( bool aFastMode = false);
+        void Fracture( bool aFastMode = false );
 
         ///> Converts a set of slitted polygons to a set of polygons with holes
         void Unfracture();
@@ -330,13 +350,17 @@
          * @param aOtherShape is the SHAPE_LINE_CHAIN to combine with me.
          * @param aFastMode is an option to choos if the result is a weak polygon
          * or a stricty simple polygon.
-         * if aFastMode is true (default) the result can be a weak polygon
-         * if aFastMode is true (default) the result is (theorically) a strictly
-         *  simple polygon, but calculations can be really significantly time consuming
+         * if aFastMode is true the result can be a weak polygon
+         * if aFastMode is false (default) the result is (theorically) a strictly
+         * simple polygon, but calculations can be really significantly time consuming
          */
         void booleanOp( ClipperLib::ClipType aType,
                         const SHAPE_POLY_SET& aOtherShape, bool aFastMode = false );
 
+        void booleanOp( ClipperLib::ClipType aType,
+                        const SHAPE_POLY_SET& aShape,
+                        const SHAPE_POLY_SET& aOtherShape, bool aFastMode = false );
+
         bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
 
         const ClipperLib::Path convertToClipper( const SHAPE_LINE_CHAIN& aPath, bool aRequiredOrientation );

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWaZe2bQAA/7/gEZUBARxf///
/+feOr//3/5gCF8AAAAAAAAAAA4yZNGgNGmIyNDEMCaNMQYjQYQAGHGTJo0Bo0xGRoYhgTRpiDEa
DCAAw4yZNGgNGmIyNDEMCaNMQYjQYQAGHGTJo0Bo0xGRoYhgTRpiDEaDCAAw4yZNGgNGmIyNDEMC
aNMQYjQYQAGCSQEAJoAmgmACGQJ6TQ9TEE2psCm09UoAiMIBheBwDAzMLbs4iDRj73f92/qzUb8U
f6zAy1FJ+5/bQuYjIf8Qrp+lVVf3qKou4EUhzP5rhWMgqlc7og/ne6Q0YuYe3PSixGoSEEABcS/r
Xb4fZQ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