From 99710aba4812ff019b4f16549cc162cecb2236c0 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 6 Jun 2021 19:47:42 -0400 Subject: [PATCH] PNS: use slightly less greedy algo to reset the mouse trail --- pcbnew/router/pns_mouse_trail_tracer.cpp | 41 +++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/pcbnew/router/pns_mouse_trail_tracer.cpp b/pcbnew/router/pns_mouse_trail_tracer.cpp index 98688b1cf0..d5aa80bba8 100644 --- a/pcbnew/router/pns_mouse_trail_tracer.cpp +++ b/pcbnew/router/pns_mouse_trail_tracer.cpp @@ -53,14 +53,19 @@ void MOUSE_TRAIL_TRACER::AddTrailPoint( const VECTOR2I& aP ) { SEG s_new( m_trail.CPoint( -1 ), aP ); - for( int i = 0; i < m_trail.SegmentCount() - 1; i++ ) + if( m_trail.SegmentCount() > 2 ) { - const SEG& s_trail = m_trail.CSegment( i ); + SEG::ecoord limit = ( static_cast( m_tolerance ) * m_tolerance ); - if( s_trail.Distance( s_new ) <= m_tolerance ) + for( int i = 0; i < m_trail.SegmentCount() - 2; i++ ) { - m_trail = m_trail.Slice( 0, i ); - break; + const SEG& s_trail = m_trail.CSegment( i ); + + if( s_trail.SquaredDistance( s_new ) <= limit ) + { + m_trail = m_trail.Slice( 0, i ); + break; + } } } @@ -71,7 +76,7 @@ void MOUSE_TRAIL_TRACER::AddTrailPoint( const VECTOR2I& aP ) DEBUG_DECORATOR *dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator(); - PNS_DBG( dbg, AddLine, m_trail, CYAN, 100000, "mt-trail" ); + PNS_DBG( dbg, AddLine, m_trail, CYAN, 50000, "mt-trail" ); } @@ -167,8 +172,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP ) if( !m_disableMouse && newDirection != m_direction ) { - PNS_DBG( dbg, Message, wxString::Format( "Posture: direction update %s => %s", m_direction.Format(), - newDirection.Format() ) ); + PNS_DBG( dbg, Message, wxString::Format( "Posture: direction update %s => %s", + m_direction.Format(), newDirection.Format() ) ); m_direction = newDirection; } @@ -176,14 +181,16 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP ) // to correct to the least obtuse if( !m_manuallyForced && !m_disableMouse && m_lastSegDirection != DIRECTION_45::UNDEFINED ) { - PNS_DBG( dbg, Message, wxString::Format( "Posture: checking direction %s against last seg %s", - m_direction.Format(), m_lastSegDirection.Format() ) ); + PNS_DBG( dbg, Message, + wxString::Format( "Posture: checking direction %s against last seg %s", + m_direction.Format(), m_lastSegDirection.Format() ) ); if( straightDirection == m_lastSegDirection ) { if( m_direction != straightDirection ) { - PNS_DBG( dbg, Message, wxString::Format( "Posture: forcing straight => %s", straightDirection.Format() ) ); + PNS_DBG( dbg, Message, wxString::Format( "Posture: forcing straight => %s", + straightDirection.Format() ) ); } m_direction = straightDirection; @@ -192,7 +199,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP ) { if( m_direction != straightDirection ) { - PNS_DBG( dbg, Message, wxString::Format( "Posture: forcing diagonal => %s", diagDirection.Format() ) ); + PNS_DBG( dbg, Message, wxString::Format( "Posture: forcing diagonal => %s", + diagDirection.Format() ) ); } m_direction = diagDirection; @@ -204,7 +212,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP ) case DIRECTION_45::ANG_HALF_FULL: // Force a better (acute) connection m_direction = m_direction.IsDiagonal() ? straightDirection : diagDirection; - PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting half full => %s", m_direction.Format() ) ); + PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting half full => %s", + m_direction.Format() ) ); break; case DIRECTION_45::ANG_ACUTE: @@ -215,7 +224,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP ) if( candidate.Angle( m_lastSegDirection ) == DIRECTION_45::ANG_RIGHT ) { - PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting right => %s", candidate.Format() ) ); + PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting right => %s", + candidate.Format() ) ); m_direction = candidate; } @@ -230,7 +240,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP ) if( candidate.Angle( m_lastSegDirection ) == DIRECTION_45::ANG_OBTUSE ) { - PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting obtuse => %s", candidate.Format() ) ); + PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting obtuse => %s", + candidate.Format() ) ); m_direction = candidate; }