From 273d14d8a0f64fcf85444f0915b873a26f8ef533 Mon Sep 17 00:00:00 2001 From: Marco Mattila Date: Sat, 24 Sep 2011 01:40:36 +0300 Subject: [PATCH] Fix drawsegment bounding box and hittest issues in pcbnew. --- pcbnew/class_board.cpp | 2 +- pcbnew/class_drawsegment.cpp | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index b88d30d853..cfb2ec277b 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -856,7 +856,7 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) // Check segments, dimensions, texts, and fiducials for( BOARD_ITEM* item = m_Drawings; item != NULL; item = item->Next() ) { - if( aBoardEdgesOnly && item->Type() != TYPE_DRAWSEGMENT && item->GetLayer() != EDGE_N ) + if( aBoardEdgesOnly && (item->Type() != TYPE_DRAWSEGMENT || item->GetLayer() != EDGE_N ) ) continue; if( !hasItems ) diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index f6237968bf..6cd5318835 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -290,7 +290,7 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx StAngle = (int) ArcTangente( dy - uy0, dx - ux0 ); EndAngle = StAngle + m_Angle; - if ( ! panel->m_PrintIsMirrored) + if( !panel->m_PrintIsMirrored ) { if( StAngle > EndAngle ) EXCHG( StAngle, EndAngle ); @@ -435,7 +435,10 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const case S_ARC: { - bbox.Inflate( GetRadius() + 1 ); + bbox.Merge( m_End ); + wxPoint end = m_End; + RotatePoint( &end, m_Start, -m_Angle ); + bbox.Merge( end ); } break; @@ -463,7 +466,7 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const p_end.y = MAX( p_end.y, pt.y ); } - bbox.SetEnd(p_end); + bbox.SetEnd( p_end ); bbox.Inflate( 1 ); break; } @@ -492,18 +495,18 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aRefPos ) if( m_Shape == S_CIRCLE ) return true; - int mouseAngle = ArcTangente( relPos.y, relPos.x ); - int stAngle = ArcTangente( m_End.y - m_Start.y, m_End.x - m_Start.x ); - int endAngle = stAngle + m_Angle; + wxPoint startVec = wxPoint( m_End.x - m_Start.x, m_End.y - m_Start.y ); + wxPoint endVec = m_End - m_Start; + RotatePoint( &endVec, -m_Angle ); - if( endAngle > 3600 ) - { - stAngle -= 3600; - endAngle -= 3600; - } + // Check dot products + if( (long long)relPos.x*startVec.x + (long long)relPos.y*startVec.y < 0 ) + return false; - if( mouseAngle >= stAngle && mouseAngle <= endAngle ) - return true; + if( (long long)relPos.x*endVec.x + (long long)relPos.y*endVec.y < 0 ) + return false; + + return true; } } break;