BoundingBox

This commit is contained in:
dickelbeck 2008-03-05 22:39:33 +00:00
parent 10f1040b42
commit aa51131bdc
2 changed files with 52 additions and 0 deletions

View File

@ -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 )
*/ */
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 )
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;
} }

View File

@ -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();