From e221b11e3bc269e2a10ad2fca9b7fd88d87e1167 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Fri, 12 Feb 2021 00:05:46 +0100 Subject: [PATCH] GRID_HELPER: fixed arithmetic issue in segment snap distance check disguised as 'excessive optimization' by the dragger in the router --- pcbnew/router/pns_mouse_trail_tracer.cpp | 13 +++++++++++++ pcbnew/router/pns_mouse_trail_tracer.h | 1 + pcbnew/tools/pcb_grid_helper.cpp | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pcbnew/router/pns_mouse_trail_tracer.cpp b/pcbnew/router/pns_mouse_trail_tracer.cpp index e88d808962..6f9940a6c0 100644 --- a/pcbnew/router/pns_mouse_trail_tracer.cpp +++ b/pcbnew/router/pns_mouse_trail_tracer.cpp @@ -257,5 +257,18 @@ void MOUSE_TRAIL_TRACER::FlipPosture() m_manuallyForced = true; } + +VECTOR2I MOUSE_TRAIL_TRACER::GetTrailLeadVector() const +{ + if( m_trail.PointCount() < 2 ) + { + return VECTOR2I(0, 0); + } + else + { + return m_trail.CPoint( -1 ) - m_trail.CPoint( 0 ); + } +} + } diff --git a/pcbnew/router/pns_mouse_trail_tracer.h b/pcbnew/router/pns_mouse_trail_tracer.h index a2cb59a581..41a542fcd3 100644 --- a/pcbnew/router/pns_mouse_trail_tracer.h +++ b/pcbnew/router/pns_mouse_trail_tracer.h @@ -59,6 +59,7 @@ public: bool IsManuallyForced() const { return m_manuallyForced; } + VECTOR2I GetTrailLeadVector() const; private: SHAPE_LINE_CHAIN m_trail; int m_tolerance; diff --git a/pcbnew/tools/pcb_grid_helper.cpp b/pcbnew/tools/pcb_grid_helper.cpp index 42c8122109..f6370fae69 100644 --- a/pcbnew/tools/pcb_grid_helper.cpp +++ b/pcbnew/tools/pcb_grid_helper.cpp @@ -79,6 +79,8 @@ VECTOR2I PCB_GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSe { OPT_VECTOR2I pts[6]; + const int c_gridSnapEpsilon = 2; + if( !m_enableSnap ) return aPoint; @@ -97,7 +99,7 @@ VECTOR2I PCB_GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSe for( int i = 0; i < 4; i++ ) { - if( pts[i] && aSeg.Contains( *pts[i] ) ) + if( pts[i] && aSeg.Distance( *pts[i] ) <= c_gridSnapEpsilon ) { int d = (*pts[i] - aPoint).EuclideanNorm();