From d1a05e27a566b43b6f532666ee1e9d0835e813b6 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 3 Jan 2020 05:38:50 -0800 Subject: [PATCH] eeschema: Correct junction test routine New v6 can test multiple points not previously considered. This corrects the test to ensure that junctions are correctly added when lines are present. Fixes #3729 | https://gitlab.com/kicad/code/kicad/issues/3729 --- eeschema/sch_screen.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index fded3b755c..cefc9d9c0b 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -398,13 +398,13 @@ bool SCH_SCREEN::IsJunctionNeeded( const wxPoint& aPosition, bool aNew ) for( int i : { WIRES, BUSSES } ) { bool removed_overlapping = false; - end_count[i] = lines[i].size(); + bool mid_point = false; for( auto line = lines[i].begin(); line < lines[i].end(); line++ ) { - // Consider ending on a line to be equivalent to two endpoints because - // we will want to split the line if anything else connects if( !(*line)->IsEndPoint( aPosition ) ) + mid_point = true; + else end_count[i]++; for( auto second_line = lines[i].end() - 1; second_line > line; second_line-- ) @@ -414,16 +414,21 @@ bool SCH_SCREEN::IsJunctionNeeded( const wxPoint& aPosition, bool aNew ) else if( !removed_overlapping && (*line)->IsSameQuadrant( *second_line, aPosition ) ) { - /** - * Overlapping lines that point in the same direction should not be counted - * as extra end_points. We remove the overlapping lines, being careful to only - * remove them once. - */ removed_overlapping = true; - end_count[i]--; } } } + + /// A line with a midpoint should be counted as two endpoints for this calculation + /// because the junction will split the line into two if there is another item + /// present at the point. + if( mid_point ) + end_count[i] += 2; + + ///Overlapping lines that point in the same direction should not be counted + /// as extra end_points. + if( removed_overlapping ) + end_count[i]--; } // If there are three or more endpoints