From aa51131bdc80c3f5475aa07c60de1b5f0942088d Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Wed, 5 Mar 2008 22:39:33 +0000 Subject: [PATCH] BoundingBox --- pcbnew/class_track.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++ pcbnew/class_track.h | 7 +++++++ 2 files changed, 52 insertions(+) diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index dcc5d528cd..070ab1be31 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -205,6 +205,26 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) } +EDA_Rect TRACK::GetBoundingBox() const +{ + int radius = m_Width/2; // end of track is round, this is its radius + + int ymax = MAX( m_Start.y, m_End.y ); + int xmax = MAX( m_Start.x, m_End.x ); + + int ymin = MIN( m_Start.y, m_End.y ); + int xmin = MIN( m_Start.x, m_End.x ); + + ymax += radius; + xmax += radius; + + ymin -= radius; + xmin -= radius; + + return EDA_Rect( wxPoint( xmin, ymin ), wxSize( xmax-xmin, ymax-ymin ) ); +} + + // see class_track.h // SEGVIA and SEGZONE inherit this version SEARCH_RESULT TRACK::Visit( INSPECTOR* inspector, const void* testData, @@ -868,6 +888,7 @@ void TRACK::Display_Infos( WinEDA_DrawFrame* frame ) */ bool TRACK::HitTest( const wxPoint& ref_pos ) { +#if 0 int l_piste; /* demi-largeur de la piste */ int dx, dy, spot_cX, spot_cY; int ux0, uy0; @@ -898,6 +919,30 @@ bool TRACK::HitTest( const wxPoint& ref_pos ) if( DistanceTest( l_piste, dx, dy, spot_cX, spot_cY ) ) return true; } +#else + + int radius = m_Width >> 1; + + // (dx, dy) is a vector from m_Start to m_End (an origin of m_Start) + int dx = m_End.x - m_Start.x; + int dy = m_End.y - m_Start.y; + + // (spot_cX, spot_cY) is a vector from m_Start to ref_pos (an origin of m_Start) + int spot_cX = ref_pos.x - m_Start.x; + int spot_cY = ref_pos.y - m_Start.y; + + if( Type() == TYPEVIA ) /* VIA rencontree */ + { + return (double) spot_cX * spot_cX + (double) spot_cY * spot_cY <= + (double) radius * radius; + } + else + { + if( DistanceTest( radius, dx, dy, spot_cX, spot_cY ) ) + return true; + } + +#endif return false; } diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index fe605efd60..da1476f342 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -68,6 +68,13 @@ public: } + /** + * Function GetBoundingBox + * returns the bounding box of this TRACK + */ + EDA_Rect GetBoundingBox() const; + + /* supprime du chainage la structure Struct */ void UnLink();