From f17a865593626086ab95c9644031096ce6a364b5 Mon Sep 17 00:00:00 2001 From: Jeff Young <jeff@rokeby.ie> Date: Wed, 31 Aug 2022 10:33:46 +0100 Subject: [PATCH] Move EDA_ITEM hitTest to BOX2I. --- common/drawing_sheet/ds_draw_item.cpp | 19 +++-- common/eda_shape.cpp | 24 +++--- common/eda_text.cpp | 4 +- eeschema/lib_item.cpp | 4 +- eeschema/lib_item.h | 2 +- eeschema/lib_pin.cpp | 4 +- eeschema/lib_pin.h | 2 +- eeschema/lib_shape.cpp | 2 +- eeschema/lib_shape.h | 2 +- eeschema/lib_text.h | 4 +- eeschema/lib_textbox.cpp | 4 +- eeschema/lib_textbox.h | 2 +- eeschema/sch_bitmap.cpp | 4 +- eeschema/sch_bitmap.h | 2 +- eeschema/sch_bus_entry.cpp | 4 +- eeschema/sch_bus_entry.h | 2 +- eeschema/sch_field.cpp | 4 +- eeschema/sch_field.h | 2 +- eeschema/sch_junction.cpp | 4 +- eeschema/sch_junction.h | 2 +- eeschema/sch_label.cpp | 4 +- eeschema/sch_label.h | 2 +- eeschema/sch_line.cpp | 4 +- eeschema/sch_line.h | 2 +- eeschema/sch_no_connect.cpp | 4 +- eeschema/sch_no_connect.h | 2 +- eeschema/sch_pin.cpp | 4 +- eeschema/sch_pin.h | 2 +- eeschema/sch_shape.h | 2 +- eeschema/sch_sheet.cpp | 4 +- eeschema/sch_sheet.h | 2 +- eeschema/sch_symbol.cpp | 4 +- eeschema/sch_symbol.h | 2 +- eeschema/sch_text.cpp | 4 +- eeschema/sch_text.h | 2 +- eeschema/sch_textbox.cpp | 4 +- eeschema/sch_textbox.h | 2 +- gerbview/gerber_draw_item.cpp | 2 +- gerbview/gerber_draw_item.h | 2 +- include/drawing_sheet/ds_draw_item.h | 10 +-- include/eda_item.h | 2 +- include/eda_shape.h | 2 +- include/eda_text.h | 2 +- include/pcb_group.h | 2 +- libs/kimath/include/math/box2.h | 101 ++++++++++++++++++++++++++ pcbnew/footprint.cpp | 4 +- pcbnew/footprint.h | 2 +- pcbnew/fp_text.cpp | 4 +- pcbnew/fp_text.h | 4 +- pcbnew/fp_textbox.cpp | 4 +- pcbnew/fp_textbox.h | 2 +- pcbnew/pad.cpp | 6 +- pcbnew/pad.h | 2 +- pcbnew/pcb_bitmap.cpp | 4 +- pcbnew/pcb_bitmap.h | 2 +- pcbnew/pcb_dimension.cpp | 6 +- pcbnew/pcb_dimension.h | 2 +- pcbnew/pcb_group.cpp | 2 +- pcbnew/pcb_shape.h | 2 +- pcbnew/pcb_target.cpp | 4 +- pcbnew/pcb_target.h | 6 +- pcbnew/pcb_text.cpp | 4 +- pcbnew/pcb_text.h | 4 +- pcbnew/pcb_textbox.cpp | 4 +- pcbnew/pcb_textbox.h | 2 +- pcbnew/pcb_track.cpp | 16 ++-- pcbnew/pcb_track.h | 6 +- pcbnew/zone.cpp | 10 +-- pcbnew/zone.h | 2 +- 69 files changed, 236 insertions(+), 138 deletions(-) diff --git a/common/drawing_sheet/ds_draw_item.cpp b/common/drawing_sheet/ds_draw_item.cpp index 9244f2bc97..dc097d1945 100644 --- a/common/drawing_sheet/ds_draw_item.cpp +++ b/common/drawing_sheet/ds_draw_item.cpp @@ -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 ); } diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index f71f39159a..6d886c045e 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -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 diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 3d3b7ca5ce..05ea226d8c 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -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 ); diff --git a/eeschema/lib_item.cpp b/eeschema/lib_item.cpp index 7fd5fa973c..88929b6f04 100644 --- a/eeschema/lib_item.cpp +++ b/eeschema/lib_item.cpp @@ -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 ); diff --git a/eeschema/lib_item.h b/eeschema/lib_item.h index 018dacc8b3..99aa61670f 100644 --- a/eeschema/lib_item.h +++ b/eeschema/lib_item.h @@ -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 diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 742ad413f6..7255c96d6b 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -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 ); diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index eeb7f1e65b..50ec134b06 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -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; diff --git a/eeschema/lib_shape.cpp b/eeschema/lib_shape.cpp index ab2ef3227e..9e57d8bdce 100644 --- a/eeschema/lib_shape.cpp +++ b/eeschema/lib_shape.cpp @@ -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; diff --git a/eeschema/lib_shape.h b/eeschema/lib_shape.h index 50bd94f25f..9cb759b722 100644 --- a/eeschema/lib_shape.h +++ b/eeschema/lib_shape.h @@ -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; diff --git a/eeschema/lib_text.h b/eeschema/lib_text.h index 497b393ae6..fda5469b3e 100644 --- a/eeschema/lib_text.h +++ b/eeschema/lib_text.h @@ -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 ); diff --git a/eeschema/lib_textbox.cpp b/eeschema/lib_textbox.cpp index 76dc8d7453..4b0b01d556 100644 --- a/eeschema/lib_textbox.cpp +++ b/eeschema/lib_textbox.cpp @@ -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 ); diff --git a/eeschema/lib_textbox.h b/eeschema/lib_textbox.h index 998d718eb9..9c5088af7a 100644 --- a/eeschema/lib_textbox.h +++ b/eeschema/lib_textbox.h @@ -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 { diff --git a/eeschema/sch_bitmap.cpp b/eeschema/sch_bitmap.cpp index 775a300c28..35afd266a8 100644 --- a/eeschema/sch_bitmap.cpp +++ b/eeschema/sch_bitmap.cpp @@ -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 ); diff --git a/eeschema/sch_bitmap.h b/eeschema/sch_bitmap.h index 5f17527fe6..6f4d02fc61 100644 --- a/eeschema/sch_bitmap.h +++ b/eeschema/sch_bitmap.h @@ -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; diff --git a/eeschema/sch_bus_entry.cpp b/eeschema/sch_bus_entry.cpp index de59f6b9c2..60ef2cb358 100644 --- a/eeschema/sch_bus_entry.cpp +++ b/eeschema/sch_bus_entry.cpp @@ -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 ); diff --git a/eeschema/sch_bus_entry.h b/eeschema/sch_bus_entry.h index 3269a3e518..36d094111a 100644 --- a/eeschema/sch_bus_entry.h +++ b/eeschema/sch_bus_entry.h @@ -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; diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index a9fb575735..0ec78ab12f 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -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 ); diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 9e9a0554f6..3ce0e0b5bb 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -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; diff --git a/eeschema/sch_junction.cpp b/eeschema/sch_junction.cpp index 9d33b2a47e..bc3bf1ffc2 100644 --- a/eeschema/sch_junction.cpp +++ b/eeschema/sch_junction.cpp @@ -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() ); } diff --git a/eeschema/sch_junction.h b/eeschema/sch_junction.h index 742251caed..524f7cac3a 100644 --- a/eeschema/sch_junction.h +++ b/eeschema/sch_junction.h @@ -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; diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index bb44ebccc9..f8418ba8d9 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -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 ); diff --git a/eeschema/sch_label.h b/eeschema/sch_label.h index 3de3ac7ed8..184dc76542 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -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; diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index f4582ebf82..47b440df8f 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -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 ); diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index 39fef48062..085019c379 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -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; diff --git a/eeschema/sch_no_connect.cpp b/eeschema/sch_no_connect.cpp index 0fa908fdb8..63972b3b6d 100644 --- a/eeschema/sch_no_connect.cpp +++ b/eeschema/sch_no_connect.cpp @@ -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 ); diff --git a/eeschema/sch_no_connect.h b/eeschema/sch_no_connect.h index e823b1a7fd..2a0c520625 100644 --- a/eeschema/sch_no_connect.h +++ b/eeschema/sch_no_connect.h @@ -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; diff --git a/eeschema/sch_pin.cpp b/eeschema/sch_pin.cpp index 9433f0310c..aecb95f82f 100644 --- a/eeschema/sch_pin.cpp +++ b/eeschema/sch_pin.cpp @@ -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 ); diff --git a/eeschema/sch_pin.h b/eeschema/sch_pin.h index de2e8ae922..b63e0e4c2f 100644 --- a/eeschema/sch_pin.h +++ b/eeschema/sch_pin.h @@ -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; diff --git a/eeschema/sch_shape.h b/eeschema/sch_shape.h index 2fc0a3a414..70ab078759 100644 --- a/eeschema/sch_shape.h +++ b/eeschema/sch_shape.h @@ -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 ); } diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 88115758cd..cdc2013362 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -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 ); diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index e3900aefb8..8516ecfdb5 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -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; diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 24f302b7a1..17bb6534c0 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -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 ); diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index 7aead19a66..1680ed2fa2 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -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; diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 52f3969909..7edb97bacf 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -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 ) diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index c9e40a344e..97c0ae54b8 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -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; diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index 30ee7d2323..ab8ee61612 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -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 ); diff --git a/eeschema/sch_textbox.h b/eeschema/sch_textbox.h index 44a510e20e..4df2bb4ab7 100644 --- a/eeschema/sch_textbox.h +++ b/eeschema/sch_textbox.h @@ -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 { diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index 70831d947a..52bc9f2826 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -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 ); diff --git a/gerbview/gerber_draw_item.h b/gerbview/gerber_draw_item.h index 6565bfde9d..f74761ccc3 100644 --- a/gerbview/gerber_draw_item.h +++ b/gerbview/gerber_draw_item.h @@ -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. diff --git a/include/drawing_sheet/ds_draw_item.h b/include/drawing_sheet/ds_draw_item.h index 8e9700bc16..ea577962cf 100644 --- a/include/drawing_sheet/ds_draw_item.h +++ b/include/drawing_sheet/ds_draw_item.h @@ -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; diff --git a/include/eda_item.h b/include/eda_item.h index 11f7556407..3b711323f8 100644 --- a/include/eda_item.h +++ b/include/eda_item.h @@ -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 } diff --git a/include/eda_shape.h b/include/eda_shape.h index 1bf301555f..cab0ca8185 100644 --- a/include/eda_shape.h +++ b/include/eda_shape.h @@ -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; diff --git a/include/eda_text.h b/include/eda_text.h index e73011fb9d..ee9ef525b8 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -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, diff --git a/include/pcb_group.h b/include/pcb_group.h index d581c155fb..a8b655e894 100644 --- a/include/pcb_group.h +++ b/include/pcb_group.h @@ -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; diff --git a/libs/kimath/include/math/box2.h b/libs/kimath/include/math/box2.h index dc4655cf7a..b089dfdad9 100644 --- a/libs/kimath/include/math/box2.h +++ b/libs/kimath/include/math/box2.h @@ -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. */ diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 8f95f19e92..d5552fb4c0 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -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 ) diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index f4d8a15817..ee091e1e06 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -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. diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index f358b7765b..3cedc6e8de 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -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 ); diff --git a/pcbnew/fp_text.h b/pcbnew/fp_text.h index d4d2cc8e12..4fa9d68683 100644 --- a/pcbnew/fp_text.h +++ b/pcbnew/fp_text.h @@ -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 ); } diff --git a/pcbnew/fp_textbox.cpp b/pcbnew/fp_textbox.cpp index 033e080e36..40e1f32032 100644 --- a/pcbnew/fp_textbox.cpp +++ b/pcbnew/fp_textbox.cpp @@ -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 ); diff --git a/pcbnew/fp_textbox.h b/pcbnew/fp_textbox.h index 6e9688a981..1e9a977613 100644 --- a/pcbnew/fp_textbox.h +++ b/pcbnew/fp_textbox.h @@ -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, diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index 71dc4f0f70..c0861b7add 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -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 ) { diff --git a/pcbnew/pad.h b/pcbnew/pad.h index 907b6b6c8b..d10d6656de 100644 --- a/pcbnew/pad.h +++ b/pcbnew/pad.h @@ -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 { diff --git a/pcbnew/pcb_bitmap.cpp b/pcbnew/pcb_bitmap.cpp index 9501139901..d4a82ae68a 100644 --- a/pcbnew/pcb_bitmap.cpp +++ b/pcbnew/pcb_bitmap.cpp @@ -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 ); diff --git a/pcbnew/pcb_bitmap.h b/pcbnew/pcb_bitmap.h index a3cf8728cd..97d06ea5a5 100644 --- a/pcbnew/pcb_bitmap.h +++ b/pcbnew/pcb_bitmap.h @@ -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; diff --git a/pcbnew/pcb_dimension.cpp b/pcbnew/pcb_dimension.cpp index 94e34def5d..58e879fafe 100644 --- a/pcbnew/pcb_dimension.cpp +++ b/pcbnew/pcb_dimension.cpp @@ -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 ); diff --git a/pcbnew/pcb_dimension.h b/pcbnew/pcb_dimension.h index 199aef5253..e15b06423f 100644 --- a/pcbnew/pcb_dimension.h +++ b/pcbnew/pcb_dimension.h @@ -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; diff --git a/pcbnew/pcb_group.cpp b/pcbnew/pcb_group.cpp index 1cb2a117d5..bdf4a12f59 100644 --- a/pcbnew/pcb_group.cpp +++ b/pcbnew/pcb_group.cpp @@ -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; diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h index a06d47dc56..3470b7a4b0 100644 --- a/pcbnew/pcb_shape.h +++ b/pcbnew/pcb_shape.h @@ -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 ); } diff --git a/pcbnew/pcb_target.cpp b/pcbnew/pcb_target.cpp index 9605537f0a..c2e2c5f905 100644 --- a/pcbnew/pcb_target.cpp +++ b/pcbnew/pcb_target.cpp @@ -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 ) diff --git a/pcbnew/pcb_target.h b/pcbnew/pcb_target.h index ac27a5e964..9c5ec92d22 100644 --- a/pcbnew/pcb_target.h +++ b/pcbnew/pcb_target.h @@ -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; diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index f6c4628ddc..a0f6e77211 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -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 ); diff --git a/pcbnew/pcb_text.h b/pcbnew/pcb_text.h index 6ad608076a..1b8cea0763 100644 --- a/pcbnew/pcb_text.h +++ b/pcbnew/pcb_text.h @@ -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 ); } diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index 883d2f775d..d3c2156904 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -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 ); diff --git a/pcbnew/pcb_textbox.h b/pcbnew/pcb_textbox.h index 3752e53ff7..ee0a28b331 100644 --- a/pcbnew/pcb_textbox.h +++ b/pcbnew/pcb_textbox.h @@ -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 { diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp index 686dfc9798..76642b4cd1 100644 --- a/pcbnew/pcb_track.cpp +++ b/pcbnew/pcb_track.cpp @@ -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 ) diff --git a/pcbnew/pcb_track.h b/pcbnew/pcb_track.h index 3a8fce47f0..0d0686e64e 100644 --- a/pcbnew/pcb_track.h +++ b/pcbnew/pcb_track.h @@ -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 { diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index 742b9d02ec..bee80a35a7 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -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 ) ) diff --git a/pcbnew/zone.h b/pcbnew/zone.h index 126e85ef36..5542238bbb 100644 --- a/pcbnew/zone.h +++ b/pcbnew/zone.h @@ -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.