Move EDA_ITEM hitTest to BOX2I.

This commit is contained in:
Jeff Young 2022-08-31 10:33:46 +01:00
parent 3857e68452
commit f17a865593
69 changed files with 236 additions and 138 deletions

View File

@ -84,9 +84,9 @@ void DS_DRAW_ITEM_BASE::ViewGetLayers( int aLayers[], int& aCount ) const
// A generic HitTest that can be used by some, but not all, sub-classes.
bool DS_DRAW_ITEM_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool DS_DRAW_ITEM_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT sel = aRect;
BOX2I sel = aRect;
if ( aAccuracy )
sel.Inflate( aAccuracy );
@ -181,7 +181,7 @@ bool DS_DRAW_ITEM_TEXT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) cons
}
bool DS_DRAW_ITEM_TEXT::HitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
bool DS_DRAW_ITEM_TEXT::HitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
{
return EDA_TEXT::TextHitTest( aRect, aContains, aAccuracy );
}
@ -243,10 +243,9 @@ bool DS_DRAW_ITEM_POLYPOLYGONS::HitTest( const VECTOR2I& aPosition, int aAccurac
}
bool DS_DRAW_ITEM_POLYPOLYGONS::HitTest( const EDA_RECT& aRect, bool aContained,
int aAccuracy ) const
bool DS_DRAW_ITEM_POLYPOLYGONS::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT sel = aRect;
BOX2I sel = aRect;
if ( aAccuracy )
sel.Inflate( aAccuracy );
@ -341,9 +340,9 @@ bool DS_DRAW_ITEM_RECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) cons
}
bool DS_DRAW_ITEM_RECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool DS_DRAW_ITEM_RECT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT sel = aRect;
BOX2I sel = aRect;
if ( aAccuracy )
sel.Inflate( aAccuracy );
@ -353,7 +352,7 @@ bool DS_DRAW_ITEM_RECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAc
// For greedy we need to check each side of the rect as we're pretty much always inside the
// rect which defines the drawing-sheet frame.
EDA_RECT side = GetBoundingBox();
BOX2I side = GetBoundingBox();
side.SetHeight( 0 );
if( sel.Intersects( side ) )
@ -454,7 +453,7 @@ bool DS_DRAW_ITEM_BITMAP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) co
}
bool DS_DRAW_ITEM_BITMAP::HitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
bool DS_DRAW_ITEM_BITMAP::HitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
{
return DS_DRAW_ITEM_BASE::HitTest( aRect, aContains, aAccuracy );
}

View File

@ -806,13 +806,13 @@ bool EDA_SHAPE::hitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool EDA_SHAPE::hitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool EDA_SHAPE::hitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT arect = aRect;
BOX2I arect = aRect;
arect.Normalize();
arect.Inflate( aAccuracy );
BOX2I bb = getBoundingBox();
BOX2I bbox = getBoundingBox();
switch( m_shape )
{
@ -820,12 +820,12 @@ bool EDA_SHAPE::hitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
// Test if area intersects or contains the circle:
if( aContained )
{
return arect.Contains( bb );
return arect.Contains( bbox );
}
else
{
// If the rectangle does not intersect the bounding box, this is a much quicker test
if( !arect.Intersects( bb ) )
if( !arect.Intersects( bbox ) )
return false;
else
return arect.IntersectsCircleEdge( getCenter(), GetRadius(), GetWidth() );
@ -835,12 +835,12 @@ bool EDA_SHAPE::hitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
// Test for full containment of this arc in the rect
if( aContained )
{
return arect.Contains( bb );
return arect.Contains( bbox );
}
// Test if the rect crosses the arc
else
{
if( !arect.Intersects( bb ) )
if( !arect.Intersects( bbox ) )
return false;
if( IsFilled() )
@ -858,7 +858,7 @@ bool EDA_SHAPE::hitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
case SHAPE_T::RECT:
if( aContained )
{
return arect.Contains( bb );
return arect.Contains( bbox );
}
else
{
@ -887,13 +887,13 @@ bool EDA_SHAPE::hitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
case SHAPE_T::POLY:
if( aContained )
{
return arect.Contains( bb );
return arect.Contains( bbox );
}
else
{
// Fast test: if aRect is outside the polygon bounding box,
// rectangles cannot intersect
if( !arect.Intersects( bb ) )
if( !arect.Intersects( bbox ) )
return false;
// Account for the width of the line
@ -942,13 +942,13 @@ bool EDA_SHAPE::hitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
case SHAPE_T::BEZIER:
if( aContained )
{
return arect.Contains( bb );
return arect.Contains( bbox );
}
else
{
// Fast test: if aRect is outside the polygon bounding box,
// rectangles cannot intersect
if( !arect.Intersects( bb ) )
if( !arect.Intersects( bbox ) )
return false;
// Account for the width of the line

View File

@ -629,9 +629,9 @@ bool EDA_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
}
bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
bool EDA_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -108,12 +108,12 @@ bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
}
bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool LIB_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;
EDA_RECT sel = aRect;
BOX2I sel = aRect;
if ( aAccuracy )
sel.Inflate( aAccuracy );

View File

@ -179,7 +179,7 @@ public:
return EDA_ITEM::HitTest( aPosition, aAccuracy );
}
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
/**
* @return the boundary box for this, in library coordinates

View File

@ -147,12 +147,12 @@ bool LIB_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool LIB_PIN::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool LIB_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;
EDA_RECT sel = aRect;
BOX2I sel = aRect;
if ( aAccuracy )
sel.Inflate( aAccuracy );

View File

@ -173,7 +173,7 @@ public:
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;

View File

@ -51,7 +51,7 @@ bool LIB_SHAPE::HitTest( const VECTOR2I& aPosRef, int aAccuracy ) const
}
bool LIB_SHAPE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool LIB_SHAPE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;

View File

@ -53,7 +53,7 @@ public:
void SetStroke( const STROKE_PARAMS& aStroke ) { m_stroke = aStroke; }
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
int GetPenWidth() const override;

View File

@ -59,12 +59,12 @@ public:
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
{
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -294,9 +294,9 @@ bool LIB_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool LIB_TEXTBOX::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool LIB_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -65,7 +65,7 @@ public:
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
{

View File

@ -170,9 +170,9 @@ bool SCH_BITMAP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_BITMAP::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_BITMAP::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -137,7 +137,7 @@ public:
void SetPosition( const VECTOR2I& aPosition ) override { m_pos = aPosition; }
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -446,9 +446,9 @@ bool SCH_BUS_ENTRY_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) con
}
bool SCH_BUS_ENTRY_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_BUS_ENTRY_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -116,7 +116,7 @@ public:
|| ( GetEnd() == aPos && IsDanglingEnd() );
}
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -888,13 +888,13 @@ bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_FIELD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
// Do not hit test hidden fields.
if( !IsVisible() || IsVoid() )
return false;
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -213,7 +213,7 @@ public:
VECTOR2I GetParentPosition() const;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -206,14 +206,14 @@ bool SCH_JUNCTION::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_JUNCTION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_JUNCTION::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
if( m_flags & STRUCT_DELETED || m_flags & SKIP_STRUCT )
return false;
if( aContained )
{
EDA_RECT selRect( aRect );
BOX2I selRect( aRect );
return selRect.Inflate( aAccuracy ).Contains( GetBoundingBox() );
}

View File

@ -115,7 +115,7 @@ public:
void SetColor( const COLOR4D& aColor );
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -709,9 +709,9 @@ bool SCH_LABEL_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_LABEL_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_LABEL_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -155,7 +155,7 @@ public:
const BOX2I GetBoundingBox() const override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
std::vector<VECTOR2I> GetConnectionPoints() const override;

View File

@ -777,12 +777,12 @@ bool SCH_LINE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_LINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_LINE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;
EDA_RECT rect = aRect;
BOX2I rect = aRect;
if ( aAccuracy )
rect.Inflate( aAccuracy );

View File

@ -262,7 +262,7 @@ public:
}
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -157,9 +157,9 @@ bool SCH_NO_CONNECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_NO_CONNECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_NO_CONNECT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -103,7 +103,7 @@ public:
void SetPosition( const VECTOR2I& aPosition ) override { m_pos = aPosition; }
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -343,9 +343,9 @@ bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_PIN::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT sel = aRect;
BOX2I sel = aRect;
if( aAccuracy )
sel.Inflate( aAccuracy );

View File

@ -94,7 +94,7 @@ public:
bool aIncludeElectricalType ) const;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
EDA_ITEM* Clone() const override;

View File

@ -51,7 +51,7 @@ public:
return hitTest( aPosition, aAccuracy );
}
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
{
return hitTest( aRect, aContained, aAccuracy );
}

View File

@ -1032,9 +1032,9 @@ bool SCH_SHEET::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_SHEET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_SHEET::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -369,7 +369,7 @@ public:
void SetPosition( const VECTOR2I& aPosition ) override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -1893,12 +1893,12 @@ bool SCH_SYMBOL::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_SYMBOL::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_SYMBOL::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
if( m_flags & STRUCT_DELETED || m_flags & SKIP_STRUCT )
return false;
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy / 2 );

View File

@ -674,7 +674,7 @@ public:
void SetPosition( const VECTOR2I& aPosition ) override { Move( aPosition - m_pos ); }
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -413,9 +413,9 @@ bool SCH_TEXT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_TEXT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT bBox = GetBoundingBox();
BOX2I bBox = GetBoundingBox();
bBox.Inflate( aAccuracy );
if( aContained )

View File

@ -209,7 +209,7 @@ public:
void SetPosition( const VECTOR2I& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter, bool aBackground ) const override;

View File

@ -307,9 +307,9 @@ bool SCH_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool SCH_TEXTBOX::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool SCH_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -86,7 +86,7 @@ public:
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
{

View File

@ -891,7 +891,7 @@ bool GERBER_DRAW_ITEM::HitTest( const VECTOR2I& aRefPos, int aAccuracy ) const
}
bool GERBER_DRAW_ITEM::HitTest( const EDA_RECT& aRefArea, bool aContained, int aAccuracy ) const
bool GERBER_DRAW_ITEM::HitTest( const BOX2I& aRefArea, bool aContained, int aAccuracy ) const
{
VECTOR2I pos = GetABPosition( m_Start );

View File

@ -194,7 +194,7 @@ public:
* @param aRefArea a wxPoint to test
* @return true if a hit, else false
*/
bool HitTest( const EDA_RECT& aRefArea, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRefArea, bool aContained, int aAccuracy = 0 ) const override;
/**
* @return the class name string.

View File

@ -95,7 +95,7 @@ public:
return EDA_ITEM::HitTest( aPosition, aAccuracy );
}
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
@ -174,7 +174,7 @@ public:
const BOX2I GetBoundingBox() const override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void PrintWsItem( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
@ -230,7 +230,7 @@ public:
const BOX2I GetBoundingBox() const override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
@ -327,7 +327,7 @@ public:
const BOX2I GetBoundingBox() const override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
@ -359,7 +359,7 @@ public:
void PrintWsItem( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
const BOX2I GetBoundingBox() const override;
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;

View File

@ -247,7 +247,7 @@ public:
* @param aAccuracy Increase \a aRect by this amount.
* @return True if \a aRect contains or intersects the item bounding box.
*/
virtual bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const
virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
{
return false; // derived classes should override this function
}

View File

@ -330,7 +330,7 @@ protected:
void computeArcBBox( BOX2I& aBBox ) const;
bool hitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const;
bool hitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const;
bool hitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const;
const std::vector<VECTOR2I> buildBezierToSegmentsPointsList( int aMinSegLen ) const;

View File

@ -259,7 +259,7 @@ public:
* @param aAccuracy Amount to inflate the bounding box.
* @return true if a hit, else false.
*/
virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const;
virtual bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const;
/**
* Useful in multiline texts to calculate the full text or a line area (for zones filling,

View File

@ -155,7 +155,7 @@ public:
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
///< @copydoc EDA_ITEM::HitTest
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
///< @copydoc EDA_ITEM::GetBoundingBox
const BOX2I GetBoundingBox() const override;

View File

@ -345,6 +345,107 @@ public:
return false;
}
/**
* @return true if this rectangle intersects a rotated rect given by \a aRect and
* \a aRotaiton.
*/
bool Intersects( const BOX2<Vec>& aRect, const EDA_ANGLE& aRotation ) const
{
if( !m_init )
return false;
EDA_ANGLE rotation = aRotation;
rotation.Normalize();
/*
* Most rectangles will be axis aligned. It is quicker to check for this case and pass
* the rect to the simpler intersection test.
*/
// Prevent floating point comparison errors
static const EDA_ANGLE ROT_EPSILON( 0.000000001, DEGREES_T );
static const EDA_ANGLE ROT_PARALLEL[] = { ANGLE_0, ANGLE_180, ANGLE_360 };
static const EDA_ANGLE ROT_PERPENDICULAR[] = { ANGLE_0, ANGLE_90, ANGLE_270 };
// Test for non-rotated rectangle
for( EDA_ANGLE ii : ROT_PARALLEL )
{
if( std::abs( rotation - ii ) < ROT_EPSILON )
return Intersects( aRect );
}
// Test for rectangle rotated by multiple of 90 degrees
for( EDA_ANGLE jj : ROT_PERPENDICULAR )
{
if( std::abs( rotation - jj ) < ROT_EPSILON )
{
BOX2<Vec> rotRect;
// Rotate the supplied rect by 90 degrees
rotRect.SetOrigin( aRect.Centre() );
rotRect.Inflate( aRect.GetHeight(), aRect.GetWidth() );
return Intersects( rotRect );
}
}
/* There is some non-orthogonal rotation.
* There are three cases to test:
* A) One point of this rect is inside the rotated rect
* B) One point of the rotated rect is inside this rect
* C) One of the sides of the rotated rect intersect this
*/
VECTOR2I corners[4];
/* Test A : Any corners exist in rotated rect? */
corners[0] = m_Pos;
corners[1] = m_Pos + VECTOR2I( m_Size.x, 0 );
corners[2] = m_Pos + VECTOR2I( m_Size.x, m_Size.y );
corners[3] = m_Pos + VECTOR2I( 0, m_Size.y );
VECTOR2I rCentre = aRect.Centre();
for( int i = 0; i < 4; i++ )
{
VECTOR2I delta = corners[i] - rCentre;
RotatePoint( delta, -rotation );
delta += rCentre;
if( aRect.Contains( delta ) )
return true;
}
/* Test B : Any corners of rotated rect exist in this one? */
int w = aRect.GetWidth() / 2;
int h = aRect.GetHeight() / 2;
// Construct corners around center of shape
corners[0] = VECTOR2I( -w, -h );
corners[1] = VECTOR2I( w, -h );
corners[2] = VECTOR2I( w, h );
corners[3] = VECTOR2I( -w, h );
// Rotate and test each corner
for( int j = 0; j < 4; j++ )
{
RotatePoint( corners[j], rotation );
corners[j] += rCentre;
if( Contains( corners[j] ) )
return true;
}
/* Test C : Any sides of rotated rect intersect this */
if( Intersects( corners[0], corners[1] ) || Intersects( corners[1], corners[2] )
|| Intersects( corners[2], corners[3] ) || Intersects( corners[3], corners[0] ) )
{
return true;
}
return false;
}
/**
* @return true if this rectangle intersects the circle defined by \a aCenter and \a aRadius.
*/

View File

@ -1070,9 +1070,9 @@ bool FOOTPRINT::HitTestAccurate( const VECTOR2I& aPosition, int aAccuracy ) cons
}
bool FOOTPRINT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool FOOTPRINT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT arect = aRect;
BOX2I arect = aRect;
arect.Inflate( aAccuracy );
if( aContained )

View File

@ -501,7 +501,7 @@ public:
*/
bool HitTestAccurate( const VECTOR2I& aPosition, int aAccuracy = 0 ) const;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
/**
* @return reference designator text.

View File

@ -85,9 +85,9 @@ bool FP_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
}
bool FP_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
bool FP_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -148,14 +148,14 @@ public:
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const override;
bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const override;
bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override
{
return TextHitTest( aPosition, aAccuracy );
}
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
{
return TextHitTest( aRect, aContained, aAccuracy );
}

View File

@ -239,9 +239,9 @@ bool FP_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool FP_TEXTBOX::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool FP_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -110,7 +110,7 @@ public:
bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, PCB_LAYER_ID aLayer,
int aClearance, int aError, ERROR_LOC aErrorLoc,

View File

@ -1044,13 +1044,13 @@ bool PAD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool PAD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PAD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT arect = aRect;
BOX2I arect = aRect;
arect.Normalize();
arect.Inflate( aAccuracy );
EDA_RECT bbox = GetBoundingBox();
BOX2I bbox = GetBoundingBox();
if( aContained )
{

View File

@ -611,7 +611,7 @@ public:
bool FlashLayer( LSET aLayers ) const;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
wxString GetClass() const override
{

View File

@ -186,9 +186,9 @@ bool PCB_BITMAP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool PCB_BITMAP::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PCB_BITMAP::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -120,7 +120,7 @@ public:
void SetPosition( const VECTOR2I& aPosition ) override { m_pos = aPosition; }
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
EDA_ITEM* Clone() const override;

View File

@ -405,12 +405,12 @@ bool PCB_DIMENSION_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) con
}
bool PCB_DIMENSION_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PCB_DIMENSION_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT arect = aRect;
BOX2I arect = aRect;
arect.Inflate( aAccuracy );
EDA_RECT rect = GetBoundingBox();
BOX2I rect = GetBoundingBox();
if( aAccuracy )
rect.Inflate( aAccuracy );

View File

@ -238,7 +238,7 @@ public:
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
const BOX2I GetBoundingBox() const override;

View File

@ -213,7 +213,7 @@ bool PCB_GROUP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool PCB_GROUP::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PCB_GROUP::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
// Groups are selected by promoting a selection of one of their children
return false;

View File

@ -127,7 +127,7 @@ public:
return hitTest( aPosition, aAccuracy );
}
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
{
return hitTest( aRect, aContained, aAccuracy );
}

View File

@ -72,9 +72,9 @@ bool PCB_TARGET::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool PCB_TARGET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PCB_TARGET::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT arect = aRect;
BOX2I arect = aRect;
arect.Inflate( aAccuracy );
if( aContained )

View File

@ -79,13 +79,13 @@ public:
}
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
// Virtual function
const BOX2I GetBoundingBox() const override;
std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer,
FLASHING aFlash = FLASHING::DEFAULT ) const override;
std::shared_ptr<SHAPE>
GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash = FLASHING::DEFAULT ) const override;
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;

View File

@ -188,9 +188,9 @@ bool PCB_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
}
bool PCB_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
bool PCB_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -95,7 +95,7 @@ public:
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const override;
bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const override;
bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override
{
@ -105,7 +105,7 @@ public:
/** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy ) const
*/
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
{
return TextHitTest( aRect, aContained, aAccuracy );
}

View File

@ -387,9 +387,9 @@ bool PCB_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool PCB_TEXTBOX::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PCB_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT rect = aRect;
BOX2I rect = aRect;
rect.Inflate( aAccuracy );

View File

@ -97,7 +97,7 @@ public:
bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
wxString GetClass() const override
{

View File

@ -977,9 +977,9 @@ bool PCB_VIA::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
}
bool PCB_TRACK::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PCB_TRACK::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT arect = aRect;
BOX2I arect = aRect;
arect.Inflate( aAccuracy );
if( aContained )
@ -989,13 +989,12 @@ bool PCB_TRACK::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
}
bool PCB_ARC::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PCB_ARC::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT box;
EDA_RECT arect = aRect;
BOX2I arect = aRect;
arect.Inflate( aAccuracy );
box.SetOrigin( GetStart() );
BOX2I box( GetStart() );
box.Merge( GetMid() );
box.Merge( GetEnd() );
@ -1008,13 +1007,12 @@ bool PCB_ARC::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) c
}
bool PCB_VIA::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool PCB_VIA::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
EDA_RECT box;
EDA_RECT arect = aRect;
arect.Inflate( aAccuracy );
box.SetOrigin( GetStart() );
BOX2I box( GetStart() );
box.Inflate( GetWidth() / 2 );
if( aContained )

View File

@ -177,7 +177,7 @@ public:
const std::vector<KICAD_T>& aScanTypes ) override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool ApproxCollinear( const PCB_TRACK& aTrack );
@ -292,7 +292,7 @@ public:
EDA_ANGLE GetArcAngleEnd() const;
virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
virtual bool HitTest( const BOX2I& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
bool IsCCW() const;
@ -408,7 +408,7 @@ public:
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
wxString GetClass() const override
{

View File

@ -393,13 +393,13 @@ bool ZONE::HitTestForEdge( const VECTOR2I& refPos, int aAccuracy,
}
bool ZONE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
bool ZONE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
// Calculate bounding box for zone
EDA_RECT bbox = GetBoundingBox();
BOX2I bbox = GetBoundingBox();
bbox.Normalize();
EDA_RECT arect = aRect;
BOX2I arect = aRect;
arect.Normalize();
arect.Inflate( aAccuracy );
@ -417,8 +417,8 @@ bool ZONE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) cons
for( int ii = 0; ii < count; ii++ )
{
auto vertex = m_Poly->CVertex( ii );
auto vertexNext = m_Poly->CVertex( ( ii + 1 ) % count );
VECTOR2I vertex = m_Poly->CVertex( ii );
VECTOR2I vertexNext = m_Poly->CVertex( ( ii + 1 ) % count );
// Test if the point is within the rect
if( arect.Contains( vertex ) )

View File

@ -428,7 +428,7 @@ public:
* @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy) const
*/
bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
/**
* Removes the zone filling.