RIP EDA_RECT.

This commit is contained in:
Jeff Young 2022-08-31 23:57:24 +01:00
parent b4492e0bd2
commit 9188838e50
45 changed files with 84 additions and 1143 deletions

View File

@ -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

View File

@ -49,7 +49,6 @@
*/
#include <gr_text.h>
#include <eda_rect.h>
#include <math/util.h> // for KiROUND
#include <view/view.h>
#include <title_block.h>

View File

@ -48,7 +48,6 @@
* describes the drawing sheet (can be the default drawing sheet or a custom file).
*/
#include <eda_rect.h>
#include <eda_draw_frame.h>
#include <drawing_sheet/ds_draw_item.h>
#include <drawing_sheet/ds_data_item.h>
@ -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 );

View File

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

View File

@ -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 <algorithm>
#include <deque>
#include <eda_rect.h>
#include <trigo.h>
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<double>( aCenter.x ) - closest.x;
double dy = static_cast<double>( aCenter.y ) - closest.y;
double r = static_cast<double>( 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;
}

View File

@ -430,7 +430,7 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_pt
{ 0, 0 }, aTextStyle & ~TEXT_STYLE::OVERBAR );
OUTLINE_GLYPH* underscoreGlyph = static_cast<OUTLINE_GLYPH*>( underscoreGlyphs[0].get() );
EDA_RECT underscoreBBox;
BOX2I underscoreBBox;
for( const VECTOR2I& pt : underscoreGlyph->Outline( 0 ).CPoints() )
underscoreBBox.Merge( pt );

View File

@ -87,7 +87,6 @@
*/
#include <base64.h>
#include <eda_rect.h>
#include <eda_shape.h>
#include <string_utils.h>
#include <font/font.h>
@ -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 );

View File

@ -85,7 +85,6 @@ principle should be easily implemented by adapting the current STL containers.
#include <kiid.h>
#include <cstddef>
#include <eda_item.h>
#include <eda_rect.h>
#include <eda_units.h>
#include <common.h>
#include <richio.h>
@ -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

View File

@ -26,7 +26,6 @@
#include <algorithm>
#include <eda_item.h>
#include <eda_rect.h>
#include <tool/selection.h>

View File

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

View File

@ -27,7 +27,6 @@
#define _LIB_ITEM_H_
#include <eda_item.h>
#include <eda_rect.h>
#include <eda_shape.h>
#include <transform.h>
#include <render_settings.h>

View File

@ -27,7 +27,6 @@
#include <class_draw_panel_gal.h>
#include <eda_item.h>
#include <gr_basic.h>
#include <eda_rect.h>
#include <sch_view.h>

View File

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

View File

@ -27,7 +27,6 @@
#include <wx/filefn.h>
#include <eda_item.h>
#include <eda_rect.h>
#include <id.h>
#include <string_utils.h>
#include <kiway.h>
@ -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 );

View File

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

View File

@ -34,7 +34,6 @@
#include <set>
#include <am_param.h>
#include <eda_rect.h>
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.
};

View File

@ -61,7 +61,7 @@ bool GERBVIEW_FRAME::Clear_DrawLayers( bool query )
GetImagesList()->DeleteAllImages();
GetGerberLayout()->SetBoundingBox( EDA_RECT() );
GetGerberLayout()->SetBoundingBox( BOX2I() );
SetActiveLayer( 0 );
ReFillLayerWidget();

View File

@ -29,7 +29,6 @@
*/
#include <trigo.h>
#include <eda_rect.h>
#include <gerbview_frame.h>
#include <gerber_file_image.h>
#include <convert_to_biu.h>

View File

@ -39,7 +39,6 @@ using KIGFX::COLOR4D;
class wxDC;
class GERBER_DRAW_ITEM;
class EDA_RECT;
/**

View File

@ -35,7 +35,7 @@
#include <gerbview.h> // GERBER_DRAWLAYERS_COUNT
#include <title_block.h>
#include <gerber_draw_item.h>
#include <eda_rect.h>
#include <math/box2.h>
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

View File

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

View File

@ -32,7 +32,6 @@
#include <drawing_sheet/ds_draw_item.h>
// Forward declarations:
class EDA_RECT;
class TITLE_BLOCK;
using KIGFX::COLOR4D;

View File

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

View File

@ -64,7 +64,6 @@ enum FIND_REPLACE_FLAGS
class wxFindReplaceData;
class EDA_DRAW_FRAME;
class EDA_RECT;
class MSG_PANEL_ITEM;

View File

@ -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 <wx/gdicmn.h>
#include <math/box2.h>
#include <geometry/eda_angle.h>
/**
* 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<class T>
EDA_RECT( const BOX2<T> 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

View File

@ -39,7 +39,6 @@
#include <gal/gal_display_options.h>
#include <newstroke_font.h>
#include <font/stroke_font.h>
#include <eda_rect.h>
#include <geometry/eda_angle.h>
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() );
}

View File

@ -23,8 +23,8 @@
#define GR_BASIC
#include <gal/color4d.h>
#include <math/box2.h>
#include <vector>
#include <eda_rect.h>
#include <wx/pen.h>
#include <wx/dc.h>

View File

@ -27,7 +27,6 @@
#include <unordered_map>
#include <eda_rect.h>
#include <wx/string.h>
// First some utility classes and functions

View File

@ -35,8 +35,6 @@
#include <math/box2.h>
#include <geometry/eda_angle.h>
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

View File

@ -837,7 +837,5 @@ typedef BOX2<VECTOR2D> BOX2D;
typedef std::optional<BOX2I> OPT_BOX2I;
// FIXME should be removed to avoid multiple typedefs for the same type
typedef BOX2D DBOX;
#endif

View File

@ -30,7 +30,6 @@
#include <cstdint>
#include <algorithm> // for max, min
#include <eda_rect.h>
#include <geometry/geometry_utils.h>
#include <math/util.h> // for KiROUND

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
*
* 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 <eda_rect.h>
#include <layer_ids.h>
#include <math/box2.h>
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;

View File

@ -69,21 +69,21 @@ void fillRectList( CSubRectArray& vecSubRects, std::vector <FOOTPRINT*>& 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 <EDA_RECT>& aRectList )
// Populates a list of rectangles, from a list of BOX2I
void fillRectList( CSubRectArray& vecSubRects, std::vector<BOX2I>& 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 <FOOTPRINT*>& aFootprintList,
EDA_RECT& aFreeArea, bool aFindAreaOnly )
void moveFootprintsInArea( CRectPlacement& aPlacementArea, std::vector<FOOTPRINT*>& aFootprintList,
const BOX2I& aFreeArea, bool aFindAreaOnly )
{
CSubRectArray vecSubRects;
@ -167,10 +167,9 @@ void moveFootprintsInArea( CRectPlacement& aPlacementArea, std::vector <FOOTPRIN
FOOTPRINT* footprint = aFootprintList[vecSubRects[it].n];
EDA_RECT fpBBox = footprint->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<FOOTPRINT*>* aFootprints, VECTOR2I aSpreadAre
sort( footprintList.begin(), footprintList.end(), sortFootprintsbySheetPath );
// Extract and place footprints by sheet
std::vector <FOOTPRINT*> footprintListBySheet;
std::vector <EDA_RECT> placementSheetAreas;
std::vector<FOOTPRINT*> footprintListBySheet;
std::vector<BOX2I> placementSheetAreas;
double subsurface;
double placementsurface = 0.0;
@ -240,7 +239,7 @@ void SpreadFootprints( std::vector<FOOTPRINT*>* 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<FOOTPRINT*>* 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<FOOTPRINT*>* 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:

View File

@ -25,7 +25,6 @@
#ifndef DRC_RTREE_H_
#define DRC_RTREE_H_
#include <eda_rect.h>
#include <board_item.h>
#include <pad.h>
#include <fp_text.h>

View File

@ -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 <layer_ids.h> // PCB_LAYER_ID
#include <pcb_lexer.h>
#include <kiid.h>
#include <math/box2.h>
#include <chrono>
#include <unordered_map>

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
* 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 <wx/string.h>
#include <wx/xml/xml.h>
#include <wx/wxcrt.h>
namespace PCAD2KICAD {

View File

@ -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<double>( aItem->GetBoundingBox().GetWidth() );
double scaleY = screenSize.GetHeight()
/ static_cast<double>( aItem->GetBoundingBox().GetHeight() );
double scaleX = screenSize.x / static_cast<double>( aItem->GetBoundingBox().GetWidth() );
double scaleY = screenSize.y / static_cast<double>( 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 );

View File

@ -37,7 +37,6 @@
#include <teardrop/teardrop_types.h>
class EDA_RECT;
class LINE_READER;
class PCB_EDIT_FRAME;
class BOARD;

View File

@ -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

View File

@ -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 <qa_utils/wx_utils/unit_test_utils.h>
#include <math/util.h>
// Code under test
#include <eda_rect.h>
/**
* 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()

View File

@ -27,7 +27,6 @@
// Code under test
#include <sch_pin.h>
#include <sch_symbol.h>
#include <eda_rect.h>
class TEST_SCH_PIN_FIXTURE

View File

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