← Back to team overview

kicad-developers team mailing list archive

[PATCH] Don't create an extra segment at the end of closed SHAPE_LINE_CHAIN

 

Hi all (but especially Orson),

I wanted to fix the issue Bernhard raised here:
https://bugs.launchpad.net/kicad/+bug/1751654/comments/7

I dug in to it a bit and found out
that SHAPE_LINE_CHAIN::SelfIntersecting() doesn't work right when polygons
are actually closed (i.e. the last point is the same as the first) and when
m_closed is set to true.

The attached patch fixes this by only generating a closing segment when the
last point isn't the same as the first point.  It fixes the issue with the
self-intersection warning showing up even when you aren't yet intersecting
(i.e. when the last point is the same as the first), and I didn't notice
any obvious other issues, but maybe you can double-check that changing the
behavior of SegmentCount() won't have any strange side-effects.

Thanks,
-Jon
From e9e6303a1174e9cf72d7bc2f90ef723f412f1f32 Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Sat, 24 Mar 2018 22:01:11 -0400
Subject: [PATCH] Don't create an extra segment at the end of closed
 SHAPE_LINE_CHAINs

---
 include/geometry/shape_line_chain.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/geometry/shape_line_chain.h b/include/geometry/shape_line_chain.h
index 6631356db..135ea8b18 100644
--- a/include/geometry/shape_line_chain.h
+++ b/include/geometry/shape_line_chain.h
@@ -171,7 +171,7 @@ public:
     int SegmentCount() const
     {
         int c = m_points.size() - 1;
-        if( m_closed )
+        if( m_closed && ( m_points[0] != m_points[c] ) )
             c++;
 
         return std::max( 0, c );
-- 
2.14.1


Follow ups