Commit aa51131b authored by dickelbeck's avatar dickelbeck

BoundingBox

parent 10f1040b
...@@ -205,6 +205,26 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) ...@@ -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 // see class_track.h
// SEGVIA and SEGZONE inherit this version // SEGVIA and SEGZONE inherit this version
SEARCH_RESULT TRACK::Visit( INSPECTOR* inspector, const void* testData, SEARCH_RESULT TRACK::Visit( INSPECTOR* inspector, const void* testData,
...@@ -868,6 +888,7 @@ void TRACK::Display_Infos( WinEDA_DrawFrame* frame ) ...@@ -868,6 +888,7 @@ void TRACK::Display_Infos( WinEDA_DrawFrame* frame )
*/ */
bool TRACK::HitTest( const wxPoint& ref_pos ) bool TRACK::HitTest( const wxPoint& ref_pos )
{ {
#if 0
int l_piste; /* demi-largeur de la piste */ int l_piste; /* demi-largeur de la piste */
int dx, dy, spot_cX, spot_cY; int dx, dy, spot_cX, spot_cY;
int ux0, uy0; int ux0, uy0;
...@@ -898,6 +919,30 @@ bool TRACK::HitTest( const wxPoint& ref_pos ) ...@@ -898,6 +919,30 @@ bool TRACK::HitTest( const wxPoint& ref_pos )
if( DistanceTest( l_piste, dx, dy, spot_cX, spot_cY ) ) if( DistanceTest( l_piste, dx, dy, spot_cX, spot_cY ) )
return true; 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; return false;
} }
......
...@@ -68,6 +68,13 @@ public: ...@@ -68,6 +68,13 @@ public:
} }
/**
* Function GetBoundingBox
* returns the bounding box of this TRACK
*/
EDA_Rect GetBoundingBox() const;
/* supprime du chainage la structure Struct */ /* supprime du chainage la structure Struct */
void UnLink(); void UnLink();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment