PNS: use slightly less greedy algo to reset the mouse trail

This commit is contained in:
Jon Evans 2021-06-06 19:47:42 -04:00
parent 0bc0f2265e
commit 99710aba48
1 changed files with 26 additions and 15 deletions

View File

@ -53,16 +53,21 @@ void MOUSE_TRAIL_TRACER::AddTrailPoint( const VECTOR2I& aP )
{ {
SEG s_new( m_trail.CPoint( -1 ), aP ); SEG s_new( m_trail.CPoint( -1 ), aP );
for( int i = 0; i < m_trail.SegmentCount() - 1; i++ ) if( m_trail.SegmentCount() > 2 )
{
SEG::ecoord limit = ( static_cast<SEG::ecoord>( m_tolerance ) * m_tolerance );
for( int i = 0; i < m_trail.SegmentCount() - 2; i++ )
{ {
const SEG& s_trail = m_trail.CSegment( i ); const SEG& s_trail = m_trail.CSegment( i );
if( s_trail.Distance( s_new ) <= m_tolerance ) if( s_trail.SquaredDistance( s_new ) <= limit )
{ {
m_trail = m_trail.Slice( 0, i ); m_trail = m_trail.Slice( 0, i );
break; break;
} }
} }
}
m_trail.Append( aP ); m_trail.Append( aP );
} }
@ -71,7 +76,7 @@ void MOUSE_TRAIL_TRACER::AddTrailPoint( const VECTOR2I& aP )
DEBUG_DECORATOR *dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator(); 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 ) if( !m_disableMouse && newDirection != m_direction )
{ {
PNS_DBG( dbg, Message, wxString::Format( "Posture: direction update %s => %s", m_direction.Format(), PNS_DBG( dbg, Message, wxString::Format( "Posture: direction update %s => %s",
newDirection.Format() ) ); m_direction.Format(), newDirection.Format() ) );
m_direction = newDirection; m_direction = newDirection;
} }
@ -176,14 +181,16 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
// to correct to the least obtuse // to correct to the least obtuse
if( !m_manuallyForced && !m_disableMouse && m_lastSegDirection != DIRECTION_45::UNDEFINED ) if( !m_manuallyForced && !m_disableMouse && m_lastSegDirection != DIRECTION_45::UNDEFINED )
{ {
PNS_DBG( dbg, Message, wxString::Format( "Posture: checking direction %s against last seg %s", PNS_DBG( dbg, Message,
wxString::Format( "Posture: checking direction %s against last seg %s",
m_direction.Format(), m_lastSegDirection.Format() ) ); m_direction.Format(), m_lastSegDirection.Format() ) );
if( straightDirection == m_lastSegDirection ) if( straightDirection == m_lastSegDirection )
{ {
if( m_direction != straightDirection ) 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; m_direction = straightDirection;
@ -192,7 +199,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
{ {
if( m_direction != straightDirection ) 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; m_direction = diagDirection;
@ -204,7 +212,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
case DIRECTION_45::ANG_HALF_FULL: case DIRECTION_45::ANG_HALF_FULL:
// Force a better (acute) connection // Force a better (acute) connection
m_direction = m_direction.IsDiagonal() ? straightDirection : diagDirection; 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; break;
case DIRECTION_45::ANG_ACUTE: 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 ) 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; 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 ) 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; m_direction = candidate;
} }