From 9188838e5016d1ebbd54b5eed4d8f1446420d23a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 31 Aug 2022 23:57:24 +0100 Subject: [PATCH] RIP EDA_RECT. --- common/CMakeLists.txt | 1 - common/drawing_sheet/ds_data_item.cpp | 1 - common/drawing_sheet/ds_draw_item.cpp | 3 +- common/drawing_sheet/ds_painter.cpp | 2 +- common/eda_rect.cpp | 541 ------------------ common/font/outline_font.cpp | 2 +- common/plotters/SVG_plotter.cpp | 10 +- common/swig/kicad.i | 2 - common/tool/selection.cpp | 1 - eeschema/autoplace_fields.cpp | 6 +- eeschema/lib_item.h | 1 - eeschema/sch_draw_panel.h | 1 - eeschema/sch_rtree.h | 22 +- eeschema/sch_screen.cpp | 3 +- gerbview/am_primitive.cpp | 2 +- gerbview/am_primitive.h | 9 +- gerbview/clear_gbr_drawlayers.cpp | 2 +- gerbview/dcode.cpp | 1 - gerbview/dcode.h | 1 - gerbview/gbr_layout.h | 10 +- gerbview/gerber_draw_item.cpp | 9 +- include/drawing_sheet/ds_painter.h | 1 - include/eda_base_frame.h | 1 - include/eda_item.h | 1 - include/eda_rect.h | 367 ------------ include/gal/graphics_abstraction_layer.h | 3 +- include/gr_basic.h | 2 +- include/hashtables.h | 1 - libs/kimath/include/geometry/geometry_utils.h | 2 - libs/kimath/include/math/box2.h | 2 - libs/kimath/src/geometry/geometry_utils.cpp | 1 - pcbnew/autorouter/ar_autoplacer.cpp | 12 +- pcbnew/autorouter/ar_autoplacer.h | 4 +- pcbnew/autorouter/ar_matrix.cpp | 2 +- pcbnew/autorouter/ar_matrix.h | 18 +- pcbnew/autorouter/spread_footprints.cpp | 29 +- pcbnew/drc/drc_rtree.h | 1 - pcbnew/plugins/kicad/pcb_parser.h | 3 +- pcbnew/plugins/pcad/s_expr_loader.cpp | 3 +- pcbnew/tools/pcb_selection_tool.cpp | 18 +- pcbnew/zone.h | 1 - qa/unittests/common/CMakeLists.txt | 1 - qa/unittests/common/test_eda_rect.cpp | 121 ---- qa/unittests/eeschema/test_sch_pin.cpp | 1 - qa/unittests/eeschema/test_sch_rtree.cpp | 2 +- 45 files changed, 84 insertions(+), 1143 deletions(-) delete mode 100644 common/eda_rect.cpp delete mode 100644 include/eda_rect.h delete mode 100644 qa/unittests/common/test_eda_rect.cpp diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 9afdee5a67..aec846f10a 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -306,7 +306,6 @@ set( COMMON_SRCS eda_draw_frame.cpp eda_item.cpp eda_pattern_match.cpp - eda_rect.cpp eda_shape.cpp eda_text.cpp eda_units.cpp diff --git a/common/drawing_sheet/ds_data_item.cpp b/common/drawing_sheet/ds_data_item.cpp index 411999f686..c04fec2758 100644 --- a/common/drawing_sheet/ds_data_item.cpp +++ b/common/drawing_sheet/ds_data_item.cpp @@ -49,7 +49,6 @@ */ #include -#include #include // for KiROUND #include #include diff --git a/common/drawing_sheet/ds_draw_item.cpp b/common/drawing_sheet/ds_draw_item.cpp index dc097d1945..d0695ef5f9 100644 --- a/common/drawing_sheet/ds_draw_item.cpp +++ b/common/drawing_sheet/ds_draw_item.cpp @@ -48,7 +48,6 @@ * describes the drawing sheet (can be the default drawing sheet or a custom file). */ -#include #include #include #include @@ -446,7 +445,7 @@ const BOX2I DS_DRAW_ITEM_BITMAP::GetBoundingBox() const bool DS_DRAW_ITEM_BITMAP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const { - EDA_RECT bbox = GetBoundingBox(); + BOX2I bbox = GetBoundingBox(); bbox.Inflate( aAccuracy ); return bbox.Contains( aPosition ); diff --git a/common/drawing_sheet/ds_painter.cpp b/common/drawing_sheet/ds_painter.cpp index 5ef516ec1d..49bcd77566 100644 --- a/common/drawing_sheet/ds_painter.cpp +++ b/common/drawing_sheet/ds_painter.cpp @@ -279,7 +279,7 @@ void KIGFX::DS_PAINTER::draw( const DS_DRAW_ITEM_BITMAP* aItem, int aLayer ) con m_gal->DrawBitmap( *bitmap->m_ImageBitmap ); #if 0 // For bounding box debug purpose only - EDA_RECT bbox = aItem->GetBoundingBox(); + BOX2I bbox = aItem->GetBoundingBox(); m_gal->SetIsFill( true ); m_gal->SetIsStroke( true ); m_gal->SetFillColor( COLOR4D( 1, 1, 1, 0.4 ) ); diff --git a/common/eda_rect.cpp b/common/eda_rect.cpp deleted file mode 100644 index f64520412f..0000000000 --- a/common/eda_rect.cpp +++ /dev/null @@ -1,541 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * @brief Implementation of EDA_RECT base class for KiCad. - */ - -#include -#include - -#include -#include - -void EDA_RECT::Normalize() -{ - if( m_size.y < 0 ) - { - m_size.y = -m_size.y; - m_pos.y -= m_size.y; - } - - if( m_size.x < 0 ) - { - m_size.x = -m_size.x; - m_pos.x -= m_size.x; - } -} - - -void EDA_RECT::Move( const VECTOR2I& aMoveVector ) -{ - m_pos += aMoveVector; -} - - -bool EDA_RECT::Contains( const VECTOR2I& aPoint ) const -{ - VECTOR2I rel_pos = aPoint - m_pos; - VECTOR2I size = m_size; - - if( size.x < 0 ) - { - size.x = -size.x; - rel_pos.x += size.x; - } - - if( size.y < 0 ) - { - size.y = -size.y; - rel_pos.y += size.y; - } - - return ( rel_pos.x >= 0 ) && ( rel_pos.y >= 0 ) && ( rel_pos.y <= size.y ) - && ( rel_pos.x <= size.x ); -} - - -bool EDA_RECT::Contains( const EDA_RECT& aRect ) const -{ - return Contains( aRect.GetOrigin() ) && Contains( aRect.GetEnd() ); -} - - -bool EDA_RECT::Intersects( const VECTOR2I& aPoint1, const VECTOR2I& aPoint2 ) const -{ - VECTOR2I point2, point4; - - if( Contains( aPoint1 ) || Contains( aPoint2 ) ) - return true; - - point2.x = GetEnd().x; - point2.y = GetOrigin().y; - point4.x = GetOrigin().x; - point4.y = GetEnd().y; - - //Only need to test 3 sides since a straight line can't enter and exit on same side - if( SegmentIntersectsSegment( aPoint1, aPoint2, GetOrigin(), point2 ) ) - return true; - - if( SegmentIntersectsSegment( aPoint1, aPoint2, point2, GetEnd() ) ) - return true; - - if( SegmentIntersectsSegment( aPoint1, aPoint2, GetEnd(), point4 ) ) - return true; - - return false; -} - - -bool EDA_RECT::Intersects( const VECTOR2I& aPoint1, const VECTOR2I& aPoint2, - VECTOR2I* aIntersection1, VECTOR2I* aIntersection2 ) const -{ - VECTOR2I point2, point4; - - point2.x = GetEnd().x; - point2.y = GetOrigin().y; - point4.x = GetOrigin().x; - point4.y = GetEnd().y; - - bool intersects = false; - - VECTOR2I* aPointToFill = aIntersection1; - - if( SegmentIntersectsSegment( aPoint1, aPoint2, GetOrigin(), point2, aPointToFill ) ) - intersects = true; - - if( intersects ) - aPointToFill = aIntersection2; - - if( SegmentIntersectsSegment( aPoint1, aPoint2, point2, GetEnd(), aPointToFill ) ) - intersects = true; - - if( intersects ) - aPointToFill = aIntersection2; - - if( SegmentIntersectsSegment( aPoint1, aPoint2, GetEnd(), point4, aPointToFill ) ) - intersects = true; - - if( intersects ) - aPointToFill = aIntersection2; - - if( SegmentIntersectsSegment( aPoint1, aPoint2, point4, GetOrigin(), aPointToFill ) ) - intersects = true; - - return intersects; -} - - -bool EDA_RECT::Intersects( const EDA_RECT& aRect ) const -{ - if( !m_init ) - return false; - - // this logic taken from wxWidgets' geometry.cpp file: - bool rc; - EDA_RECT me( *this ); - EDA_RECT rect( aRect ); - me.Normalize(); // ensure size is >= 0 - rect.Normalize(); // ensure size is >= 0 - - // calculate the left common area coordinate: - int left = std::max( me.m_pos.x, rect.m_pos.x ); - - // calculate the right common area coordinate: - int right = std::min( me.m_pos.x + me.m_size.x, rect.m_pos.x + rect.m_size.x ); - - // calculate the upper common area coordinate: - int top = std::max( me.m_pos.y, rect.m_pos.y ); - - // calculate the lower common area coordinate: - int bottom = std::min( me.m_pos.y + me.m_size.y, rect.m_pos.y + rect.m_size.y ); - - // if a common area exists, it must have a positive (null accepted) size - if( left <= right && top <= bottom ) - rc = true; - else - rc = false; - - return rc; -} - - -bool EDA_RECT::Intersects( const EDA_RECT& 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 ) - { - EDA_RECT 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; -} - - -const VECTOR2I EDA_RECT::ClosestPointTo( const VECTOR2I& aPoint ) const -{ - EDA_RECT me( *this ); - - me.Normalize(); // ensure size is >= 0 - - // Determine closest point to the circle centre within this rect - int nx = std::max( me.GetLeft(), std::min( aPoint.x, me.GetRight() ) ); - int ny = std::max( me.GetTop(), std::min( aPoint.y, me.GetBottom() ) ); - - return VECTOR2I( nx, ny ); -} - - -const VECTOR2I EDA_RECT::FarthestPointTo( const VECTOR2I& aPoint ) const -{ - EDA_RECT me( *this ); - - me.Normalize(); // ensure size is >= 0 - - int fx = std::max( std::abs( aPoint.x - me.GetLeft() ), std::abs( aPoint.x - me.GetRight() ) ); - int fy = std::max( std::abs( aPoint.y - me.GetTop() ), std::abs( aPoint.y - me.GetBottom() ) ); - - return VECTOR2I( fx, fy ); -} - - -bool EDA_RECT::IntersectsCircle( const VECTOR2I& aCenter, const int aRadius ) const -{ - if( !m_init ) - return false; - - VECTOR2I closest = ClosestPointTo( aCenter ); - - double dx = static_cast( aCenter.x ) - closest.x; - double dy = static_cast( aCenter.y ) - closest.y; - - double r = static_cast( aRadius ); - - return ( dx * dx + dy * dy ) <= ( r * r ); -} - - -bool EDA_RECT::IntersectsCircleEdge( const VECTOR2I& aCenter, const int aRadius, - const int aWidth ) const -{ - if( !m_init ) - return false; - - EDA_RECT me( *this ); - me.Normalize(); // ensure size is >= 0 - - // Test if the circle intersects at all - if( !IntersectsCircle( aCenter, aRadius + aWidth / 2 ) ) - { - return false; - } - - VECTOR2I farpt = FarthestPointTo( aCenter ); - // Farthest point must be further than the inside of the line - double fx = (double) farpt.x; - double fy = (double) farpt.y; - - double r = (double) aRadius - (double) aWidth / 2; - - return ( fx * fx + fy * fy ) > ( r * r ); -} - - -EDA_RECT& EDA_RECT::Inflate( int aDelta ) -{ - Inflate( aDelta, aDelta ); - return *this; -} - - -EDA_RECT& EDA_RECT::Inflate( wxCoord dx, wxCoord dy ) -{ - if( m_size.x >= 0 ) - { - if( m_size.x < -2 * dx ) - { - // Don't allow deflate to eat more width than we have, - m_pos.x += m_size.x / 2; - m_size.x = 0; - } - else - { - // The inflate is valid. - m_pos.x -= dx; - m_size.x += 2 * dx; - } - } - else // size.x < 0: - { - if( m_size.x > 2 * dx ) - { - // Don't allow deflate to eat more width than we have, - m_pos.x -= m_size.x / 2; - m_size.x = 0; - } - else - { - // The inflate is valid. - m_pos.x += dx; - m_size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0 - } - } - - if( m_size.y >= 0 ) - { - if( m_size.y < -2 * dy ) - { - // Don't allow deflate to eat more height than we have, - m_pos.y += m_size.y / 2; - m_size.y = 0; - } - else - { - // The inflate is valid. - m_pos.y -= dy; - m_size.y += 2 * dy; - } - } - else // size.y < 0: - { - if( m_size.y > 2 * dy ) - { - // Don't allow deflate to eat more height than we have, - m_pos.y -= m_size.y / 2; - m_size.y = 0; - } - else - { - // The inflate is valid. - m_pos.y += dy; - m_size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0 - } - } - - return *this; -} - - -void EDA_RECT::Merge( const EDA_RECT& aRect ) -{ - if( !m_init ) - { - if( aRect.IsValid() ) - { - m_pos = aRect.GetPosition(); - m_size = aRect.GetSize(); - m_init = true; - } - return; - } - - Normalize(); // ensure width and height >= 0 - EDA_RECT rect = aRect; - rect.Normalize(); // ensure width and height >= 0 - VECTOR2I end = GetEnd(); - VECTOR2I rect_end = rect.GetEnd(); - - // Change origin and size in order to contain the given rect - m_pos.x = std::min( m_pos.x, rect.m_pos.x ); - m_pos.y = std::min( m_pos.y, rect.m_pos.y ); - end.x = std::max( end.x, rect_end.x ); - end.y = std::max( end.y, rect_end.y ); - SetEnd( end ); -} - - -void EDA_RECT::Merge( const VECTOR2I& aPoint ) -{ - if( !m_init ) - { - m_pos = aPoint; - m_size = VECTOR2I( 0, 0 ); - m_init = true; - return; - } - - Normalize(); // ensure width and height >= 0 - - VECTOR2I end = GetEnd(); - - // Change origin and size in order to contain the given rect - m_pos.x = std::min( m_pos.x, aPoint.x ); - m_pos.y = std::min( m_pos.y, aPoint.y ); - end.x = std::max( end.x, aPoint.x ); - end.y = std::max( end.y, aPoint.y ); - SetEnd( end ); -} - - -double EDA_RECT::GetArea() const -{ - return (double) GetWidth() * (double) GetHeight(); -} - - -EDA_RECT EDA_RECT::Common( const EDA_RECT& aRect ) const -{ - EDA_RECT r; - - if( Intersects( aRect ) ) - { - VECTOR2I originA( std::min( GetOrigin().x, GetEnd().x ), - std::min( GetOrigin().y, GetEnd().y ) ); - VECTOR2I originB( std::min( aRect.GetOrigin().x, aRect.GetEnd().x ), - std::min( aRect.GetOrigin().y, aRect.GetEnd().y ) ); - VECTOR2I endA( std::max( GetOrigin().x, GetEnd().x ), - std::max( GetOrigin().y, GetEnd().y ) ); - VECTOR2I endB( std::max( aRect.GetOrigin().x, aRect.GetEnd().x ), - std::max( aRect.GetOrigin().y, aRect.GetEnd().y ) ); - - r.SetOrigin( - VECTOR2I( std::max( originA.x, originB.x ), std::max( originA.y, originB.y ) ) ); - r.SetEnd( VECTOR2I( std::min( endA.x, endB.x ), std::min( endA.y, endB.y ) ) ); - } - - return r; -} - - -const EDA_RECT EDA_RECT::GetBoundingBoxRotated( const VECTOR2I& aRotCenter, - const EDA_ANGLE& aAngle ) const -{ - VECTOR2I corners[4]; - - // Build the corners list - corners[0] = GetOrigin(); - corners[2] = GetEnd(); - corners[1].x = corners[0].x; - corners[1].y = corners[2].y; - corners[3].x = corners[2].x; - corners[3].y = corners[0].y; - - // Rotate all corners, to find the bounding box - for( int ii = 0; ii < 4; ii++ ) - RotatePoint( corners[ii], aRotCenter, aAngle ); - - // Find the corners bounding box - VECTOR2I start = corners[0]; - VECTOR2I end = corners[0]; - - for( int ii = 1; ii < 4; ii++ ) - { - start.x = std::min( start.x, corners[ii].x ); - start.y = std::min( start.y, corners[ii].y ); - end.x = std::max( end.x, corners[ii].x ); - end.y = std::max( end.y, corners[ii].y ); - } - - EDA_RECT bbox; - bbox.SetOrigin( start ); - bbox.SetEnd( end ); - - return bbox; -} diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index bab64cda1b..8c407b87be 100644 --- a/common/font/outline_font.cpp +++ b/common/font/outline_font.cpp @@ -430,7 +430,7 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector( underscoreGlyphs[0].get() ); - EDA_RECT underscoreBBox; + BOX2I underscoreBBox; for( const VECTOR2I& pt : underscoreGlyph->Outline( 0 ).CPoints() ) underscoreBBox.Merge( pt ); diff --git a/common/plotters/SVG_plotter.cpp b/common/plotters/SVG_plotter.cpp index 437304ff53..6ded555136 100644 --- a/common/plotters/SVG_plotter.cpp +++ b/common/plotters/SVG_plotter.cpp @@ -87,7 +87,6 @@ */ #include -#include #include #include #include @@ -385,8 +384,9 @@ void SVG_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) void SVG_PLOTTER::Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill, int width ) { - EDA_RECT rect( p1, VECTOR2I( p2.x - p1.x, p2.y - p1.y ) ); + BOX2I rect( p1, VECTOR2I( p2.x - p1.x, p2.y - p1.y ) ); rect.Normalize(); + VECTOR2D org_dev = userToDeviceCoordinates( rect.GetOrigin() ); VECTOR2D end_dev = userToDeviceCoordinates( rect.GetEnd() ); VECTOR2D size_dev = end_dev - org_dev; @@ -394,7 +394,7 @@ void SVG_PLOTTER::Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill, int // Ensure size of rect in device coordinates is > 0 // I don't know if this is a SVG issue or a Inkscape issue, but // Inkscape has problems with negative or null values for width and/or height, so avoid them - DBOX rect_dev( org_dev, size_dev); + BOX2D rect_dev( org_dev, size_dev ); rect_dev.Normalize(); setFillMode( fill ); @@ -422,8 +422,8 @@ void SVG_PLOTTER::Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill, int void SVG_PLOTTER::Circle( const VECTOR2I& pos, int diametre, FILL_T fill, int width ) { - VECTOR2D pos_dev = userToDeviceCoordinates( pos ); - double radius = userToDeviceSize( diametre / 2.0 ); + VECTOR2D pos_dev = userToDeviceCoordinates( pos ); + double radius = userToDeviceSize( diametre / 2.0 ); setFillMode( fill ); SetCurrentLineWidth( width ); diff --git a/common/swig/kicad.i b/common/swig/kicad.i index d9557638af..fba9d0f334 100644 --- a/common/swig/kicad.i +++ b/common/swig/kicad.i @@ -85,7 +85,6 @@ principle should be easily implemented by adapting the current STL containers. #include #include #include - #include #include #include #include @@ -116,7 +115,6 @@ principle should be easily implemented by adapting the current STL containers. %include kiid.h %include core/typeinfo.h %include eda_item.h -%include eda_rect.h %include eda_units.h %include common.h %include richio.h diff --git a/common/tool/selection.cpp b/common/tool/selection.cpp index a11574090c..d9155358f1 100644 --- a/common/tool/selection.cpp +++ b/common/tool/selection.cpp @@ -26,7 +26,6 @@ #include #include -#include #include diff --git a/eeschema/autoplace_fields.cpp b/eeschema/autoplace_fields.cpp index c0ae74bc1a..2bdd29ce03 100644 --- a/eeschema/autoplace_fields.cpp +++ b/eeschema/autoplace_fields.cpp @@ -573,7 +573,7 @@ protected: if( aFieldSideAndPins.pins > 0 ) { - EDA_RECT pinsBox = getPinsBox( aFieldSideAndPins.side ); + BOX2I pinsBox = getPinsBox( aFieldSideAndPins.side ); if( aFieldSideAndPins.side == SIDE_TOP || aFieldSideAndPins.side == SIDE_BOTTOM ) { @@ -645,7 +645,7 @@ protected: * * @return Correct field horizontal position */ - int fieldHPlacement( SCH_FIELD *aField, const EDA_RECT &aFieldBox ) + int fieldHPlacement( SCH_FIELD* aField, const BOX2I& aFieldBox ) { int field_hjust; int field_xcoord; @@ -685,7 +685,7 @@ protected: * * @return Correct field vertical position */ - int fieldVPlacement( SCH_FIELD *aField, const EDA_RECT &aFieldBox, int *aAccumulatedPosition, + int fieldVPlacement( SCH_FIELD* aField, const BOX2I& aFieldBox, int* aAccumulatedPosition, bool aDynamic ) { int field_height; diff --git a/eeschema/lib_item.h b/eeschema/lib_item.h index 99aa61670f..93aa06977a 100644 --- a/eeschema/lib_item.h +++ b/eeschema/lib_item.h @@ -27,7 +27,6 @@ #define _LIB_ITEM_H_ #include -#include #include #include #include diff --git a/eeschema/sch_draw_panel.h b/eeschema/sch_draw_panel.h index 70c76ca8f5..74453faef2 100644 --- a/eeschema/sch_draw_panel.h +++ b/eeschema/sch_draw_panel.h @@ -27,7 +27,6 @@ #include #include #include -#include #include diff --git a/eeschema/sch_rtree.h b/eeschema/sch_rtree.h index a63697e17b..a899755aaa 100644 --- a/eeschema/sch_rtree.h +++ b/eeschema/sch_rtree.h @@ -200,16 +200,20 @@ public: m_rect = { { type, INT_MIN, INT_MIN }, { type, INT_MAX, INT_MAX } }; }; - EE_TYPE( ee_rtree* aTree, KICAD_T aType, const EDA_RECT aRect ) : type_tree( aTree ) + EE_TYPE( ee_rtree* aTree, KICAD_T aType, const BOX2I& aRect ) : type_tree( aTree ) { KICAD_T type = BaseType( aType ); if( type == SCH_LOCATE_ANY_T ) - m_rect = { { INT_MIN, aRect.GetX(), aRect.GetY() }, - { INT_MAX, aRect.GetRight(), aRect.GetBottom() } }; + { + m_rect = { { INT_MIN, aRect.GetX(), aRect.GetY() }, + { INT_MAX, aRect.GetRight(), aRect.GetBottom() } }; + } else - m_rect = { { type, aRect.GetX(), aRect.GetY() }, - { type, aRect.GetRight(), aRect.GetBottom() } }; + { + m_rect = { { type, aRect.GetX(), aRect.GetY() }, + { type, aRect.GetRight(), aRect.GetBottom() } }; + } }; ee_rtree::Rect m_rect; @@ -236,26 +240,26 @@ public: return EE_TYPE( m_tree, aType ); } - EE_TYPE Overlapping( const EDA_RECT& aRect ) const + EE_TYPE Overlapping( const BOX2I& aRect ) const { return EE_TYPE( m_tree, SCH_LOCATE_ANY_T, aRect ); } EE_TYPE Overlapping( const VECTOR2I& aPoint, int aAccuracy = 0 ) const { - EDA_RECT rect( aPoint, wxSize( 0, 0 ) ); + BOX2I rect( aPoint, VECTOR2I( 0, 0 ) ); rect.Inflate( aAccuracy ); return EE_TYPE( m_tree, SCH_LOCATE_ANY_T, rect ); } EE_TYPE Overlapping( KICAD_T aType, const VECTOR2I& aPoint, int aAccuracy = 0 ) const { - EDA_RECT rect( aPoint, wxSize( 0, 0 ) ); + BOX2I rect( aPoint, VECTOR2I( 0, 0 ) ); rect.Inflate( aAccuracy ); return EE_TYPE( m_tree, aType, rect ); } - EE_TYPE Overlapping( KICAD_T aType, const EDA_RECT& aRect ) const + EE_TYPE Overlapping( KICAD_T aType, const BOX2I& aRect ) const { return EE_TYPE( m_tree, aType, aRect ); } diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 79ba857c8e..84f9e6d7d3 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -335,7 +334,7 @@ bool SCH_SCREEN::CheckIfOnDrawList( const SCH_ITEM* aItem ) const SCH_ITEM* SCH_SCREEN::GetItem( const VECTOR2I& aPosition, int aAccuracy, KICAD_T aType ) const { - EDA_RECT bbox; + BOX2I bbox; bbox.SetOrigin( aPosition ); bbox.Inflate( aAccuracy ); diff --git a/gerbview/am_primitive.cpp b/gerbview/am_primitive.cpp index 969afb77bc..fdc9918951 100644 --- a/gerbview/am_primitive.cpp +++ b/gerbview/am_primitive.cpp @@ -850,7 +850,7 @@ SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* a // (i.e link holes by overlapping edges) m_shape.Fracture( SHAPE_POLY_SET::PM_FAST ); - m_boundingBox = EDA_RECT( VECTOR2I( 0, 0 ), VECTOR2I( 1, 1 ) ); + m_boundingBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( 1, 1 ) ); auto bb = m_shape.BBox(); VECTOR2I center( bb.Centre().x, bb.Centre().y ); diff --git a/gerbview/am_primitive.h b/gerbview/am_primitive.h index 5faeebaaed..b27fe8065a 100644 --- a/gerbview/am_primitive.h +++ b/gerbview/am_primitive.h @@ -34,7 +34,6 @@ #include #include -#include class SHAPE_POLY_SET; @@ -223,7 +222,7 @@ struct APERTURE_MACRO int GetShapeDim( GERBER_DRAW_ITEM* aParent ); /// Return the bounding box of the shape. - EDA_RECT GetBoundingBox() const + BOX2I GetBoundingBox() const { return m_boundingBox; } @@ -239,9 +238,9 @@ struct APERTURE_MACRO */ AM_PARAMS m_localparamStack; - SHAPE_POLY_SET m_shape; ///< The shape of the item, calculated by GetApertureMacroShape - EDA_RECT m_boundingBox; ///< The bounding box of the item, calculated by - ///< GetApertureMacroShape. + SHAPE_POLY_SET m_shape; ///< The shape of the item, calculated by GetApertureMacroShape + BOX2I m_boundingBox; ///< The bounding box of the item, calculated by + ///< GetApertureMacroShape. }; diff --git a/gerbview/clear_gbr_drawlayers.cpp b/gerbview/clear_gbr_drawlayers.cpp index bf4fe66805..b186ddc7cd 100644 --- a/gerbview/clear_gbr_drawlayers.cpp +++ b/gerbview/clear_gbr_drawlayers.cpp @@ -61,7 +61,7 @@ bool GERBVIEW_FRAME::Clear_DrawLayers( bool query ) GetImagesList()->DeleteAllImages(); - GetGerberLayout()->SetBoundingBox( EDA_RECT() ); + GetGerberLayout()->SetBoundingBox( BOX2I() ); SetActiveLayer( 0 ); ReFillLayerWidget(); diff --git a/gerbview/dcode.cpp b/gerbview/dcode.cpp index da93a7ed04..2af2cc5a90 100644 --- a/gerbview/dcode.cpp +++ b/gerbview/dcode.cpp @@ -29,7 +29,6 @@ */ #include -#include #include #include #include diff --git a/gerbview/dcode.h b/gerbview/dcode.h index 17f75bab99..14002a4980 100644 --- a/gerbview/dcode.h +++ b/gerbview/dcode.h @@ -39,7 +39,6 @@ using KIGFX::COLOR4D; class wxDC; class GERBER_DRAW_ITEM; -class EDA_RECT; /** diff --git a/gerbview/gbr_layout.h b/gerbview/gbr_layout.h index aa8da5c872..c385f2a931 100644 --- a/gerbview/gbr_layout.h +++ b/gerbview/gbr_layout.h @@ -35,7 +35,7 @@ #include // GERBER_DRAWLAYERS_COUNT #include #include -#include +#include class GERBER_FILE_IMAGE_LIST; @@ -75,7 +75,7 @@ public: return ComputeBoundingBox(); } - void SetBoundingBox( const EDA_RECT& aBox ) { m_BoundingBox = aBox; } + void SetBoundingBox( const BOX2I& aBox ) { m_BoundingBox = aBox; } ///< @copydoc EDA_ITEM::Visit() INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, @@ -86,9 +86,9 @@ public: #endif private: - mutable EDA_RECT m_BoundingBox; - TITLE_BLOCK m_titles; - VECTOR2I m_originAxisPosition; + mutable BOX2I m_BoundingBox; + TITLE_BLOCK m_titles; + VECTOR2I m_originAxisPosition; }; #endif // #ifndef GBR_LAYOUT_H diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index 52bc9f2826..dbde150579 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -800,10 +800,10 @@ bool GERBER_DRAW_ITEM::HitTest( const VECTOR2I& aRefPos, int aAccuracy ) const case GBR_SPOT_OVAL: { - EDA_RECT bbox = GetBoundingBox(); + BOX2I bbox = GetBoundingBox(); - if( ! bbox.Contains( aRefPos ) ) - return false; + if( ! bbox.Contains( aRefPos ) ) + return false; // This is similar to a segment with thickness = min( m_Size.x, m_Size.y ) int radius = std::min( m_Size.x, m_Size.y )/2; @@ -938,8 +938,7 @@ void GERBER_DRAW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const const BOX2I GERBER_DRAW_ITEM::ViewBBox() const { - EDA_RECT bbox = GetBoundingBox(); - return BOX2I( VECTOR2I( bbox.GetOrigin() ), VECTOR2I( bbox.GetSize() ) ); + return GetBoundingBox(); } diff --git a/include/drawing_sheet/ds_painter.h b/include/drawing_sheet/ds_painter.h index 59aaeea3da..f54fd6ea01 100644 --- a/include/drawing_sheet/ds_painter.h +++ b/include/drawing_sheet/ds_painter.h @@ -32,7 +32,6 @@ #include // Forward declarations: -class EDA_RECT; class TITLE_BLOCK; using KIGFX::COLOR4D; diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 5b671ad8d6..b42d9ad345 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -61,7 +61,6 @@ class wxChoice; class wxEvent; class wxFileName; class EDA_ITEM; -class EDA_RECT; class EDA_DRAW_PANEL_GAL; class EDA_MSG_PANEL; class BASE_SCREEN; diff --git a/include/eda_item.h b/include/eda_item.h index 117c0d7b11..88ba0c1e65 100644 --- a/include/eda_item.h +++ b/include/eda_item.h @@ -64,7 +64,6 @@ enum FIND_REPLACE_FLAGS class wxFindReplaceData; class EDA_DRAW_FRAME; -class EDA_RECT; class MSG_PANEL_ITEM; diff --git a/include/eda_rect.h b/include/eda_rect.h deleted file mode 100644 index d9033927d8..0000000000 --- a/include/eda_rect.h +++ /dev/null @@ -1,367 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * @file eda_rect.h - */ - -#ifndef EDA_RECT_H -#define EDA_RECT_H - -#include -#include -#include - -/** - * Handle the component boundary box. - * - * This class is similar to wxRect, but some wxRect functions are very curious, and are - * working only if dimensions are >= 0 (not always the case in KiCad) and also KiCad needs - * some specific method which makes this a more suitable class. - */ -class EDA_RECT -{ -public: - EDA_RECT() : m_init( false ) { }; - - EDA_RECT( const VECTOR2I& aPos, const VECTOR2I& aSize ) : - m_pos( aPos ), - m_size( aSize ), - m_init( true ) - { } - - EDA_RECT( const wxPoint& aPos, const wxSize& aSize ) : - EDA_RECT( VECTOR2I( aPos.x, aPos.y ), VECTOR2I( aSize.x, aSize.y ) ) - { } - - template - EDA_RECT( const BOX2 aBox ) - { - m_pos = aBox.GetPosition(); - m_size.x = aBox.GetWidth(); - m_size.y = aBox.GetHeight(); - m_init = true; - } - - virtual ~EDA_RECT() { }; - - VECTOR2I Centre() const - { - return VECTOR2I( m_pos.x + ( m_size.x >> 1 ), m_pos.y + ( m_size.y >> 1 ) ); - } - - /** - * Move the rectangle by the \a aMoveVector. - * - * @param aMoveVector A wxPoint that is the value to move this rectangle. - */ - void Move( const VECTOR2I& aMoveVector ); - - /** - * Ensures that the height ant width are positive. - */ - void Normalize(); - - /** - * @param aPoint the wxPoint to test. - * @return true if aPoint is inside the boundary box. A point on a edge is seen as inside. - */ - bool Contains( const VECTOR2I& aPoint ) const; - - /** - * @param x the x coordinate of the point to test. - * @param y the x coordinate of the point to test. - * @return true if point is inside the boundary box. A point on a edge is seen as inside - */ - bool Contains( int x, int y ) const { return Contains( VECTOR2I( x, y ) ); } - - /** - * @param aRect the EDA_RECT to test. - * @return true if aRect is Contained. A common edge is seen as contained. - */ - bool Contains( const EDA_RECT& aRect ) const; - - const VECTOR2I GetSize() const { return m_size; } - - /** - * @return the max size dimension. - */ - int GetSizeMax() const { return ( m_size.x > m_size.y ) ? m_size.x : m_size.y; } - - int GetX() const { return m_pos.x; } - int GetY() const { return m_pos.y; } - - const VECTOR2I GetOrigin() const { return m_pos; } - const VECTOR2I GetPosition() const { return m_pos; } - const VECTOR2I GetEnd() const { return VECTOR2I( m_pos.x + m_size.x, m_pos.y + m_size.y ); } - const VECTOR2I GetCenter() const - { - return VECTOR2I( m_pos.x + ( m_size.x / 2 ), m_pos.y + ( m_size.y / 2 ) ); - } - - int GetWidth() const { return m_size.x; } - int GetHeight() const { return m_size.y; } - int GetRight() const { return m_pos.x + m_size.x; } - int GetLeft() const { return m_pos.x; } - int GetTop() const { return m_pos.y; } - int GetBottom() const { return m_pos.y + m_size.y; } // Y axis from top to bottom - - bool IsValid() const - { - return m_init; - } - - void SetOrigin( const VECTOR2I& pos ) - { - m_pos = pos; - m_init = true; - } - - void SetOrigin( int x, int y ) - { - m_pos.x = x; - m_pos.y = y; - m_init = true; - } - - void SetSize( const VECTOR2I& size ) - { - m_size = size; - m_init = true; - } - - void SetSize( int w, int h ) - { - m_size.x = w; - m_size.y = h; - m_init = true; - } - - void Offset( int dx, int dy ) - { - m_pos.x += dx; - m_pos.y += dy; - } - - void Offset( const VECTOR2I& offset ) - { - m_pos += offset; - } - - void SetX( int val ) - { - m_pos.x = val; - m_init = true; - } - - void SetY( int val ) - { - m_pos.y = val; - m_init = true; - } - - void SetWidth( int val ) - { - m_size.x = val; - m_init = true; - } - - void SetHeight( int val ) - { - m_size.y = val; - m_init = true; - } - - void SetEnd( int x, int y ) - { - SetEnd( VECTOR2I( x, y ) ); - m_init = true; - } - - void SetEnd( const VECTOR2I& pos ) - { - m_size.x = pos.x - m_pos.x; - m_size.y = pos.y - m_pos.y; - m_init = true; - } - - /** - * Mirror the rectangle from the X axis (negate Y pos and size). - */ - void RevertYAxis() - { - m_pos.y = -m_pos.y; - m_size.y = -m_size.y; - Normalize(); - } - - /** - * Test for a common area between rectangles. - * - * @param aRect A rectangle to test intersection with. - * @return true if the argument rectangle intersects this rectangle. - * (i.e. if the 2 rectangles have at least a common point) - */ - bool Intersects( const EDA_RECT& aRect ) const; - - /** - * Tests for a common area between this rectangle, and a rectangle with arbitrary rotation - * - * @param aRect a rectangle to test intersection with. - * @param aRot rectangle rotation. - */ - bool Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) const; - - /** - * Test for a common area between a segment and this rectangle. - * - * @param aPoint1 First point of the segment to test intersection with. - * @param aPoint2 Second point of the segment to test intersection with. - * @return true if the argument segment intersects this rectangle. - * (i.e. if the segment and rectangle have at least a common point) - */ - bool Intersects( const VECTOR2I& aPoint1, const VECTOR2I& aPoint2 ) const; - - /** - * Test for intersection between a segment and this rectangle, returning the intersections. - * - * @param aPoint1 is the first point of the segment to test intersection with. - * @param aPoint2 is the second point of the segment to test intersection with. - * @param aIntersection1 will be filled with the first intersection point, if any. - * @param aIntersection2 will be filled with the second intersection point, if any. - * @return true if the segment intersects the rect. - */ - bool Intersects( const VECTOR2I& aPoint1, const VECTOR2I& aPoint2, VECTOR2I* aIntersection1, - VECTOR2I* aIntersection2 ) const; - - /** - * Return the point in this rect that is closest to the provided point - */ - const VECTOR2I ClosestPointTo( const VECTOR2I& aPoint ) const; - - /** - * Return the point in this rect that is farthest from the provided point - */ - const VECTOR2I FarthestPointTo( const VECTOR2I& aPoint ) const; - - /** - * Test for a common area between a circle and this rectangle. - * - * @param aCenter center of the circle. - * @param aRadius radius of the circle. - */ - bool IntersectsCircle( const VECTOR2I& aCenter, const int aRadius ) const; - - /** - * Test for intersection between this rect and the edge (radius) of a circle. - * - * @param aCenter center of the circle. - * @param aRadius radius of the circle. - * @param aWidth width of the circle edge. - */ - bool IntersectsCircleEdge( const VECTOR2I& aCenter, const int aRadius, const int aWidth ) const; - - /** - * Overload the cast operator to return a wxRect. - * - * wxRect does not accept negative values for size, so ensure the wxRect size is always >= 0. - */ - operator wxRect() const - { - EDA_RECT rect( m_pos, m_size ); - rect.Normalize(); - return wxRect( (wxPoint)rect.m_pos, (wxSize)rect.m_size ); - } - - /** - * Overload the cast operator to return a BOX2I. - * - * @return this box shaped as a BOX2I object. - */ - operator BOX2I() const - { - EDA_RECT rect( m_pos, m_size ); - rect.Normalize(); - return BOX2I( rect.GetOrigin(), rect.GetSize() ); - } - - /** - * Inflate the rectangle horizontally by \a dx and vertically by \a dy. If \a dx - * and/or \a dy is negative the rectangle is deflated. - */ - EDA_RECT& Inflate( wxCoord dx, wxCoord dy ); - - /** - * Inflate the rectangle horizontally and vertically by \a aDelta. If \a aDelta - * is negative the rectangle is deflated. - */ - EDA_RECT& Inflate( int aDelta ); - - /** - * Modify the position and size of the rectangle in order to contain \a aRect. - * - * It is mainly used to calculate bounding boxes. - * - * @param aRect The rectangle to merge with this rectangle. - */ - void Merge( const EDA_RECT& aRect ); - - /** - * Modify the position and size of the rectangle in order to contain the given point. - * - * @param aPoint The point to merge with the rectangle. - */ - void Merge( const VECTOR2I& aPoint ); - - /** - * Return the area of the rectangle. - * - * @return The area of the rectangle. - */ - double GetArea() const; - - /** - * Return the area that is common with another rectangle. - * - * @param aRect is the rectangle to find the common area with. - * @return The common area rect or 0-sized rectangle if there is no intersection. - */ - EDA_RECT Common( const EDA_RECT& aRect ) const; - - /** - * Useful to calculate bounding box of rotated items, when rotation is not k*90 degrees. - * - * @return the bounding box of this, after rotation. - */ - const EDA_RECT GetBoundingBoxRotated( const VECTOR2I& aRotCenter, - const EDA_ANGLE& aAngle ) const; - -private: - VECTOR2I m_pos; // Rectangle Origin - VECTOR2I m_size; // Rectangle Size - bool m_init; // Is the rectangle initialized -}; - - -#endif // EDA_RECT_H diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 7d0bcb61c3..398845bbba 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -39,7 +39,6 @@ #include #include #include -#include #include class SHAPE_LINE_CHAIN; @@ -168,7 +167,7 @@ public: */ virtual void DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {}; - void DrawRectangle( const EDA_RECT& aRect ) + void DrawRectangle( const BOX2I& aRect ) { DrawRectangle( aRect.GetOrigin(), aRect.GetEnd() ); } diff --git a/include/gr_basic.h b/include/gr_basic.h index 3a6bf3f0d0..c68367d833 100644 --- a/include/gr_basic.h +++ b/include/gr_basic.h @@ -23,8 +23,8 @@ #define GR_BASIC #include +#include #include -#include #include #include diff --git a/include/hashtables.h b/include/hashtables.h index 0b3fac4117..b8a5b99d41 100644 --- a/include/hashtables.h +++ b/include/hashtables.h @@ -27,7 +27,6 @@ #include -#include #include // First some utility classes and functions diff --git a/libs/kimath/include/geometry/geometry_utils.h b/libs/kimath/include/geometry/geometry_utils.h index b80d1e9bf7..db036eead2 100644 --- a/libs/kimath/include/geometry/geometry_utils.h +++ b/libs/kimath/include/geometry/geometry_utils.h @@ -35,8 +35,6 @@ #include #include -class EDA_RECT; - /** * When approximating an arc or circle, should the error be placed on the outside * or inside of the curve? (Generally speaking filled shape errors go on the inside diff --git a/libs/kimath/include/math/box2.h b/libs/kimath/include/math/box2.h index b089dfdad9..4a7ceca3da 100644 --- a/libs/kimath/include/math/box2.h +++ b/libs/kimath/include/math/box2.h @@ -837,7 +837,5 @@ typedef BOX2 BOX2D; typedef std::optional OPT_BOX2I; -// FIXME should be removed to avoid multiple typedefs for the same type -typedef BOX2D DBOX; #endif diff --git a/libs/kimath/src/geometry/geometry_utils.cpp b/libs/kimath/src/geometry/geometry_utils.cpp index adb2888ae8..d2e3cd6b02 100644 --- a/libs/kimath/src/geometry/geometry_utils.cpp +++ b/libs/kimath/src/geometry/geometry_utils.cpp @@ -30,7 +30,6 @@ #include #include // for max, min -#include #include #include // for KiROUND diff --git a/pcbnew/autorouter/ar_autoplacer.cpp b/pcbnew/autorouter/ar_autoplacer.cpp index abcd6283b3..1e099622a2 100644 --- a/pcbnew/autorouter/ar_autoplacer.cpp +++ b/pcbnew/autorouter/ar_autoplacer.cpp @@ -87,7 +87,7 @@ int AR_AUTOPLACER::genPlacementRoutingMatrix() { m_matrix.UnInitRoutingMatrix(); - EDA_RECT bbox = m_board->GetBoardEdgesBoundingBox(); + BOX2I bbox = m_board->GetBoardEdgesBoundingBox(); if( bbox.GetWidth() == 0 || bbox.GetHeight() == 0 ) return 0; @@ -398,9 +398,9 @@ void AR_AUTOPLACER::genModuleOnRoutingMatrix( FOOTPRINT* Module ) } -int AR_AUTOPLACER::testRectangle( const EDA_RECT& aRect, int side ) +int AR_AUTOPLACER::testRectangle( const BOX2I& aRect, int side ) { - EDA_RECT rect = aRect; + BOX2I rect = aRect; rect.Inflate( m_matrix.m_GridRouting / 2 ); @@ -451,7 +451,7 @@ int AR_AUTOPLACER::testRectangle( const EDA_RECT& aRect, int side ) } -unsigned int AR_AUTOPLACER::calculateKeepOutArea( const EDA_RECT& aRect, int side ) +unsigned int AR_AUTOPLACER::calculateKeepOutArea( const BOX2I& aRect, int side ) { VECTOR2I start = aRect.GetOrigin(); VECTOR2I end = aRect.GetEnd(); @@ -511,7 +511,7 @@ int AR_AUTOPLACER::testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSid side = AR_SIDE_BOTTOM; otherside = AR_SIDE_TOP; } - EDA_RECT fpBBox = aFootprint->GetBoundingBox( false, false ); + BOX2I fpBBox = aFootprint->GetBoundingBox( false, false ); fpBBox.Move( -1*aOffset ); buildFpAreas( aFootprint, 0 ); @@ -548,7 +548,7 @@ int AR_AUTOPLACER::getOptimalFPPlacement( FOOTPRINT* aFootprint ) lastPosOK = m_matrix.m_BrdBox.GetOrigin(); VECTOR2I fpPos = aFootprint->GetPosition(); - EDA_RECT fpBBox = aFootprint->GetBoundingBox( false, false ); + BOX2I fpBBox = aFootprint->GetBoundingBox( false, false ); // Move fpBBox to have the footprint position at (0,0) fpBBox.Move( -fpPos ); diff --git a/pcbnew/autorouter/ar_autoplacer.h b/pcbnew/autorouter/ar_autoplacer.h index eace01dc3a..4fbe81d81b 100644 --- a/pcbnew/autorouter/ar_autoplacer.h +++ b/pcbnew/autorouter/ar_autoplacer.h @@ -95,8 +95,8 @@ private: bool fillMatrix(); void genModuleOnRoutingMatrix( FOOTPRINT* aFootprint ); - int testRectangle( const EDA_RECT& aRect, int side ); - unsigned int calculateKeepOutArea( const EDA_RECT& aRect, int side ); + int testRectangle( const BOX2I& aRect, int side ); + unsigned int calculateKeepOutArea( const BOX2I& aRect, int side ); int testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSide, const VECTOR2I& aOffset ); int getOptimalFPPlacement( FOOTPRINT* aFootprint ); double computePlacementRatsnestCost( FOOTPRINT* aFootprint, const VECTOR2I& aOffset ); diff --git a/pcbnew/autorouter/ar_matrix.cpp b/pcbnew/autorouter/ar_matrix.cpp index 0118ca4b2c..35cf8a9c07 100644 --- a/pcbnew/autorouter/ar_matrix.cpp +++ b/pcbnew/autorouter/ar_matrix.cpp @@ -59,7 +59,7 @@ AR_MATRIX::~AR_MATRIX() // was: bool AR_MATRIX::ComputeMatrixSize( BOARD* aPcb, bool aUseBoardEdgesOnly ) // aUseBoardEdgesOnly ? aPcb->GetBoardEdgesBoundingBox() : aPcb->GetBoundingBox(); -bool AR_MATRIX::ComputeMatrixSize( const EDA_RECT& aBoundingBox ) +bool AR_MATRIX::ComputeMatrixSize( const BOX2I& aBoundingBox ) { // The boundary box must have its start point on routing grid: m_BrdBox = aBoundingBox; diff --git a/pcbnew/autorouter/ar_matrix.h b/pcbnew/autorouter/ar_matrix.h index 84a75d7df0..342077b455 100644 --- a/pcbnew/autorouter/ar_matrix.h +++ b/pcbnew/autorouter/ar_matrix.h @@ -5,7 +5,7 @@ * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2011 Wayne Stambaugh * - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,8 +29,8 @@ #ifndef __AR_MATRIX_H #define __AR_MATRIX_H -#include #include +#include class PCB_SHAPE; class PAD; @@ -84,7 +84,7 @@ public: * @param aUseBoardEdgesOnly set to true to use board edges only or false to use the full * board bounding box (default). */ - bool ComputeMatrixSize( const EDA_RECT& aBoundingBox ); + bool ComputeMatrixSize( const BOX2I& aBoundingBox ); /** * Initialize the data structures. @@ -138,12 +138,12 @@ public: MATRIX_CELL* m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides DIST_CELL* m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides: // distance to cells - int m_RoutingLayersCount; // Number of layers for autorouting (0 or 1) - int m_GridRouting; // Size of grid for autoplace/autoroute - EDA_RECT m_BrdBox; // Actual board bounding box - int m_Nrows, m_Ncols; // Matrix size - int m_MemSize; // Memory requirement, just for statistics - int m_RouteCount; // Number of routes + int m_RoutingLayersCount; // Number of layers for autorouting (0 or 1) + int m_GridRouting; // Size of grid for autoplace/autoroute + BOX2I m_BrdBox; // Actual board bounding box + int m_Nrows, m_Ncols; // Matrix size + int m_MemSize; // Memory requirement, just for statistics + int m_RouteCount; // Number of routes PCB_LAYER_ID m_routeLayerTop; PCB_LAYER_ID m_routeLayerBottom; diff --git a/pcbnew/autorouter/spread_footprints.cpp b/pcbnew/autorouter/spread_footprints.cpp index e4366db8eb..19150a2f1a 100644 --- a/pcbnew/autorouter/spread_footprints.cpp +++ b/pcbnew/autorouter/spread_footprints.cpp @@ -69,21 +69,21 @@ void fillRectList( CSubRectArray& vecSubRects, std::vector & aFootpr for( unsigned ii = 0; ii < aFootprintList.size(); ii++ ) { - EDA_RECT fpBox = aFootprintList[ii]->GetBoundingBox( false, false ); + BOX2I fpBox = aFootprintList[ii]->GetBoundingBox( false, false ); TSubRect fpRect( ( fpBox.GetWidth() + PADDING ) / scale, ( fpBox.GetHeight() + PADDING ) / scale, ii ); vecSubRects.push_back( fpRect ); } } -// Populates a list of rectangles, from a list of EDA_RECT -void fillRectList( CSubRectArray& vecSubRects, std::vector & aRectList ) +// Populates a list of rectangles, from a list of BOX2I +void fillRectList( CSubRectArray& vecSubRects, std::vector& aRectList ) { vecSubRects.clear(); for( unsigned ii = 0; ii < aRectList.size(); ii++ ) { - EDA_RECT& rect = aRectList[ii]; + BOX2I& rect = aRectList[ii]; TSubRect fpRect( rect.GetWidth()/scale, rect.GetHeight()/scale, ii ); vecSubRects.push_back( fpRect ); } @@ -148,8 +148,8 @@ void spreadRectangles( CRectPlacement& aPlacementArea, } -void moveFootprintsInArea( CRectPlacement& aPlacementArea, std::vector & aFootprintList, - EDA_RECT& aFreeArea, bool aFindAreaOnly ) +void moveFootprintsInArea( CRectPlacement& aPlacementArea, std::vector& aFootprintList, + const BOX2I& aFreeArea, bool aFindAreaOnly ) { CSubRectArray vecSubRects; @@ -167,10 +167,9 @@ void moveFootprintsInArea( CRectPlacement& aPlacementArea, std::vector GetBoundingBox( false, false ); - VECTOR2I mod_pos = - pos + ( footprint->GetPosition() - fpBBox.GetOrigin() ) - + aFreeArea.GetOrigin(); + BOX2I fpBBox = footprint->GetBoundingBox( false, false ); + VECTOR2I mod_pos = pos + ( footprint->GetPosition() - fpBBox.GetOrigin() ) + + aFreeArea.GetOrigin(); footprint->Move( mod_pos - footprint->GetPosition() ); } @@ -208,8 +207,8 @@ void SpreadFootprints( std::vector* aFootprints, VECTOR2I aSpreadAre sort( footprintList.begin(), footprintList.end(), sortFootprintsbySheetPath ); // Extract and place footprints by sheet - std::vector footprintListBySheet; - std::vector placementSheetAreas; + std::vector footprintListBySheet; + std::vector placementSheetAreas; double subsurface; double placementsurface = 0.0; @@ -240,7 +239,7 @@ void SpreadFootprints( std::vector* aFootprints, VECTOR2I aSpreadAre subsurface += footprint->GetArea( PADDING ); // Calculate min size of placement area: - EDA_RECT bbox = footprint->GetBoundingBox( false, false ); + BOX2I bbox = footprint->GetBoundingBox( false, false ); fp_max_width = std::max( fp_max_width, bbox.GetWidth() ); fp_max_height = std::max( fp_max_height, bbox.GetHeight() ); @@ -248,7 +247,7 @@ void SpreadFootprints( std::vector* aFootprints, VECTOR2I aSpreadAre { // end of the footprint sublist relative to the same sheet path // calculate placement of the current sublist - EDA_RECT freeArea; + BOX2I freeArea; int Xsize_allowed = (int) ( sqrt( subsurface ) * 4.0 / 3.0 ); Xsize_allowed = std::max( fp_max_width, Xsize_allowed ); @@ -273,7 +272,7 @@ void SpreadFootprints( std::vector* aFootprints, VECTOR2I aSpreadAre if( pass == 0 ) { // Populate sheet placement areas list - EDA_RECT sub_area; + BOX2I sub_area; sub_area.SetWidth( placementArea.GetW()*scale ); sub_area.SetHeight( placementArea.GetH()*scale ); // Add a margin around the sheet placement area: diff --git a/pcbnew/drc/drc_rtree.h b/pcbnew/drc/drc_rtree.h index 3d171282ab..6a2cdc07bb 100644 --- a/pcbnew/drc/drc_rtree.h +++ b/pcbnew/drc/drc_rtree.h @@ -25,7 +25,6 @@ #ifndef DRC_RTREE_H_ #define DRC_RTREE_H_ -#include #include #include #include diff --git a/pcbnew/plugins/kicad/pcb_parser.h b/pcbnew/plugins/kicad/pcb_parser.h index 382bb600d5..e933da4e25 100644 --- a/pcbnew/plugins/kicad/pcb_parser.h +++ b/pcbnew/plugins/kicad/pcb_parser.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 CERN - * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -36,6 +36,7 @@ #include // PCB_LAYER_ID #include #include +#include #include #include diff --git a/pcbnew/plugins/pcad/s_expr_loader.cpp b/pcbnew/plugins/pcad/s_expr_loader.cpp index 99c7c58f0d..c0aa0a9c8d 100644 --- a/pcbnew/plugins/pcad/s_expr_loader.cpp +++ b/pcbnew/plugins/pcad/s_expr_loader.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-2013 Alexander Lunev - * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,6 +30,7 @@ #include #include +#include namespace PCAD2KICAD { diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 5fcdf0f63a..55a36db375 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -1807,19 +1807,13 @@ void PCB_SELECTION_TOOL::FindItem( BOARD_ITEM* aItem ) KIGFX::PCB_VIEW* pcbView = canvas()->GetView(); BOX2D screenBox = pcbView->GetViewport(); - wxSize screenSize = wxSize( screenBox.GetWidth(), screenBox.GetHeight() ); - screenSize /= marginFactor; + VECTOR2I screenSize = screenBox.GetSize(); + BOX2I screenRect( screenBox.GetOrigin(), screenSize / marginFactor ); - wxPoint screenPos = wxPoint( screenBox.GetOrigin() ); - EDA_RECT* screenRect = new EDA_RECT( screenPos, screenSize ); - - if( !screenRect->Contains( aItem->GetBoundingBox() ) ) + if( !screenRect.Contains( aItem->GetBoundingBox() ) ) { - double scaleX = screenSize.GetWidth() - / static_cast( aItem->GetBoundingBox().GetWidth() ); - double scaleY = screenSize.GetHeight() - / static_cast( aItem->GetBoundingBox().GetHeight() ); - + double scaleX = screenSize.x / static_cast( aItem->GetBoundingBox().GetWidth() ); + double scaleY = screenSize.y / static_cast( aItem->GetBoundingBox().GetHeight() ); scaleX /= marginFactor; scaleY /= marginFactor; @@ -1834,8 +1828,6 @@ void PCB_SELECTION_TOOL::FindItem( BOARD_ITEM* aItem ) m_frame->FocusOnLocation( aItem->GetCenter() ); } } - - delete screenRect; } // Inform other potentially interested tools m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); diff --git a/pcbnew/zone.h b/pcbnew/zone.h index 8840db2ac5..4183557bd3 100644 --- a/pcbnew/zone.h +++ b/pcbnew/zone.h @@ -37,7 +37,6 @@ #include -class EDA_RECT; class LINE_READER; class PCB_EDIT_FRAME; class BOARD; diff --git a/qa/unittests/common/CMakeLists.txt b/qa/unittests/common/CMakeLists.txt index 467a371f07..25b3839f1d 100644 --- a/qa/unittests/common/CMakeLists.txt +++ b/qa/unittests/common/CMakeLists.txt @@ -34,7 +34,6 @@ set( QA_COMMON_SRCS test_bitmap_base.cpp test_color4d.cpp test_coroutine.cpp - test_eda_rect.cpp test_lib_table.cpp test_kicad_string.cpp test_kiid.cpp diff --git a/qa/unittests/common/test_eda_rect.cpp b/qa/unittests/common/test_eda_rect.cpp deleted file mode 100644 index b5931930b9..0000000000 --- a/qa/unittests/common/test_eda_rect.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2021 KiCad Developers, see AUTHORS.TXT for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include - -// Code under test -#include - - -/** - * Declare the test suite - */ -BOOST_AUTO_TEST_SUITE( EdaRect ) - -/** - * Check inflation and deflation - */ -BOOST_AUTO_TEST_CASE( Inflate ) -{ - int width = 20; - int height = 30; - wxSize sizes[] = { wxSize( width, height ), wxSize( width, -height ), wxSize( -width, height ), - wxSize( -width, -height ) }; - - // We need also to check what happens when deflation exceeds the size. - int deltas[] = { width, width / 2, width / 4 }; - - for( int delta : deltas ) - { - for( wxSize size : sizes ) - { - wxPoint origin = wxPoint( 100, 100 ); - EDA_RECT rect( origin, size ); - - // The four corners of the rectangle. - wxPoint corners[] = { origin + wxSize( 0, 0 ), origin + wxSize( 0, size.y ), - origin + wxSize( size.x, 0 ), origin + wxSize( size.x, size.y ) }; - - // Inflation - - wxPoint inflation_corners[] = { - corners[0] + wxSize( -delta * sign( size.x ), -delta * sign( size.y ) ), - corners[1] + wxSize( -delta * sign( size.x ), delta * sign( size.y ) ), - corners[2] + wxSize( delta * sign( size.x ), -delta * sign( size.y ) ), - corners[3] + wxSize( delta * sign( size.x ), delta * sign( size.y ) ) - }; - - for( wxPoint corner : inflation_corners ) - { - EDA_RECT inflated_rect = rect; - inflated_rect.Inflate( delta ); - - BOOST_CHECK( !rect.Contains( corner ) ); - BOOST_CHECK( inflated_rect.Contains( corner ) ); - } - - // Deflation - - wxPoint deflation_corners[] = { - corners[0] - + wxSize( ( delta - 1 ) * sign( size.x ), ( delta - 1 ) * sign( size.y ) ), - corners[1] - + wxSize( ( delta - 1 ) * sign( size.x ), -( delta - 1 ) * sign( size.y ) ), - corners[2] - + wxSize( -( delta - 1 ) * sign( size.x ), ( delta - 1 ) * sign( size.y ) ), - corners[3] - + wxSize( -( delta - 1 ) * sign( size.x ), -( delta - 1 ) * sign( size.y ) ) - }; - - for( wxPoint corner : deflation_corners ) - { - EDA_RECT deflated_rect = rect; - deflated_rect.Inflate( -delta ); - - // If true, deflation exceeds the size. - bool zeroed = false; - - if( abs( rect.GetSize().x ) < 2 * delta ) - { - BOOST_CHECK_EQUAL( deflated_rect.GetSize().x, 0 ); - zeroed = true; - } - - if( abs( rect.GetSize().y ) < 2 * delta ) - { - BOOST_CHECK_EQUAL( deflated_rect.GetSize().y, 0 ); - zeroed = true; - } - - if( !zeroed ) - { - BOOST_CHECK( rect.Contains( corner ) ); - BOOST_CHECK( !deflated_rect.Contains( corner ) ); - } - } - } - } -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/qa/unittests/eeschema/test_sch_pin.cpp b/qa/unittests/eeschema/test_sch_pin.cpp index 04abc58e27..acf2489b9c 100644 --- a/qa/unittests/eeschema/test_sch_pin.cpp +++ b/qa/unittests/eeschema/test_sch_pin.cpp @@ -27,7 +27,6 @@ // Code under test #include #include -#include class TEST_SCH_PIN_FIXTURE diff --git a/qa/unittests/eeschema/test_sch_rtree.cpp b/qa/unittests/eeschema/test_sch_rtree.cpp index e435465be5..52efc9924f 100644 --- a/qa/unittests/eeschema/test_sch_rtree.cpp +++ b/qa/unittests/eeschema/test_sch_rtree.cpp @@ -222,7 +222,7 @@ BOOST_AUTO_TEST_CASE( MixedElements ) BOOST_CHECK_EQUAL( count, 100 ); - EDA_RECT small_bbox( VECTOR2I( -1, -1 ), VECTOR2I( Mils2iu( 2 ), Mils2iu( 2 ) ) ); + BOX2I small_bbox( VECTOR2I( -1, -1 ), VECTOR2I( Mils2iu( 2 ), Mils2iu( 2 ) ) ); count = 0;