KiCad PCB EDA Suite
EDA_RECT Class Reference

Class EDA_RECT handles the component boundary box. More...

#include <eda_rect.h>

Inheritance diagram for EDA_RECT:
BLOCK_SELECTOR

Public Member Functions

 EDA_RECT ()
 
 EDA_RECT (const wxPoint &aPos, const wxSize &aSize)
 
virtual ~EDA_RECT ()
 
wxPoint Centre () const
 
void Move (const wxPoint &aMoveVector)
 Function Move moves the rectangle by the aMoveVector. More...
 
void Normalize ()
 Function Normalize ensures that the height ant width are positive. More...
 
bool Contains (const wxPoint &aPoint) const
 Function Contains. More...
 
bool Contains (int x, int y) const
 Function Contains. More...
 
bool Contains (const EDA_RECT &aRect) const
 Function Contains. More...
 
const wxSize GetSize () const
 
int GetSizeMax () const
 GetSizeMax. More...
 
int GetX () const
 
int GetY () const
 
const wxPoint GetOrigin () const
 
const wxPoint GetPosition () const
 
const wxPoint GetEnd () const
 
const wxPoint GetCenter () const
 
int GetWidth () const
 
int GetHeight () const
 
int GetRight () const
 
int GetLeft () const
 
int GetTop () const
 
int GetBottom () const
 
void SetOrigin (const wxPoint &pos)
 
void SetOrigin (int x, int y)
 
void SetSize (const wxSize &size)
 
void SetSize (int w, int h)
 
void Offset (int dx, int dy)
 
void Offset (const wxPoint &offset)
 
void SetX (int val)
 
void SetY (int val)
 
void SetWidth (int val)
 
void SetHeight (int val)
 
void SetEnd (int x, int y)
 
void SetEnd (const wxPoint &pos)
 
void RevertYAxis ()
 Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size) More...
 
bool Intersects (const EDA_RECT &aRect) const
 Function Intersects tests for a common area between rectangles. More...
 
bool Intersects (const EDA_RECT &aRect, double aRot) const
 Tests for a common area between this rectangle, and a rectangle with arbitrary rotation. More...
 
bool Intersects (const wxPoint &aPoint1, const wxPoint &aPoint2) const
 Function Intersects tests for a common area between a segment and this rectangle. More...
 
const wxPoint ClosestPointTo (const wxPoint &aPoint) const
 Return the point in this rect that is closest to the provided point. More...
 
const wxPoint FarthestPointTo (const wxPoint &aPoint) const
 Return the point in this rect that is farthest from the provided point. More...
 
bool IntersectsCircle (const wxPoint &aCenter, const int aRadius) const
 Function IntersectsCircle tests for a common area between a circle and this rectangle. More...
 
bool IntersectsCircleEdge (const wxPoint &aCenter, const int aRadius, const int aWidth) const
 IntersectsCircleEdge Tests for intersection between this rect and the edge (radius) of a circle. More...
 
 operator wxRect () const
 Function operator(wxRect) overloads the cast operator to return a wxRect wxRect does not accept negative values for size, so ensure the wxRect size is always >= 0. More...
 
 operator BOX2I () const
 Function operator(BOX2I) overloads the cast operator to return a BOX2I. More...
 
EDA_RECTInflate (wxCoord dx, wxCoord dy)
 Function Inflate inflates the rectangle horizontally by dx and vertically by dy. More...
 
EDA_RECTInflate (int aDelta)
 Function Inflate inflates the rectangle horizontally and vertically by aDelta. More...
 
void Merge (const EDA_RECT &aRect)
 Function Merge modifies the position and size of the rectangle in order to contain aRect. More...
 
void Merge (const wxPoint &aPoint)
 Function Merge modifies the position and size of the rectangle in order to contain the given point. More...
 
double GetArea () const
 Function GetArea returns the area of the rectangle. More...
 
EDA_RECT Common (const EDA_RECT &aRect) const
 Function Common returns the area that is common with another rectangle. More...
 
const EDA_RECT GetBoundingBoxRotated (wxPoint aRotCenter, double aAngle)
 Function GetBoundingBoxRotated. More...
 

Private Attributes

wxPoint m_Pos
 
wxSize m_Size
 

Detailed Description

Class EDA_RECT handles 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. so I prefer this more suitable class

Definition at line 44 of file eda_rect.h.

Constructor & Destructor Documentation

◆ EDA_RECT() [1/2]

EDA_RECT::EDA_RECT ( )
inline

Definition at line 51 of file eda_rect.h.

51 { };

◆ EDA_RECT() [2/2]

EDA_RECT::EDA_RECT ( const wxPoint &  aPos,
const wxSize &  aSize 
)
inline

Definition at line 53 of file eda_rect.h.

53  :
54  m_Pos( aPos ),
55  m_Size( aSize )
56  { }
wxSize m_Size
Definition: eda_rect.h:48
wxPoint m_Pos
Definition: eda_rect.h:47

◆ ~EDA_RECT()

virtual EDA_RECT::~EDA_RECT ( )
inlinevirtual

Definition at line 58 of file eda_rect.h.

58 { };

Member Function Documentation

◆ Centre()

◆ ClosestPointTo()

const wxPoint EDA_RECT::ClosestPointTo ( const wxPoint &  aPoint) const

Return the point in this rect that is closest to the provided point.

Definition at line 531 of file base_struct.cpp.

532 {
533  EDA_RECT me( *this );
534 
535  me.Normalize(); // ensure size is >= 0
536 
537  // Determine closest point to the circle centre within this rect
538  int nx = std::max( me.GetLeft(), std::min( aPoint.x, me.GetRight() ) );
539  int ny = std::max( me.GetTop(), std::min( aPoint.y, me.GetBottom() ) );
540 
541  return wxPoint( nx, ny );
542 }
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
#define min(a, b)
Definition: auxiliary.h:85

References GetBottom(), GetLeft(), GetRight(), GetTop(), max, min, and Normalize().

Referenced by IntersectsCircle().

◆ Common()

EDA_RECT EDA_RECT::Common ( const EDA_RECT aRect) const

Function Common returns the area that is common with another rectangle.

Parameters
aRectis the rectangle to find the common area with.
Returns
The common area rect or 0-sized rectangle if there is no intersection.

Definition at line 705 of file base_struct.cpp.

706 {
707  EDA_RECT r;
708 
709  if( Intersects( aRect ) )
710  {
711  wxPoint originA( std::min( GetOrigin().x, GetEnd().x ),
712  std::min( GetOrigin().y, GetEnd().y ) );
713  wxPoint originB( std::min( aRect.GetOrigin().x, aRect.GetEnd().x ),
714  std::min( aRect.GetOrigin().y, aRect.GetEnd().y ) );
715  wxPoint endA( std::max( GetOrigin().x, GetEnd().x ),
716  std::max( GetOrigin().y, GetEnd().y ) );
717  wxPoint endB( std::max( aRect.GetOrigin().x, aRect.GetEnd().x ),
718  std::max( aRect.GetOrigin().y, aRect.GetEnd().y ) );
719 
720  r.SetOrigin( wxPoint( std::max( originA.x, originB.x ), std::max( originA.y, originB.y ) ) );
721  r.SetEnd ( wxPoint( std::min( endA.x, endB.x ), std::min( endA.y, endB.y ) ) );
722  }
723 
724  return r;
725 }
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
const wxPoint GetEnd() const
Definition: eda_rect.h:114
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
void SetEnd(int x, int y)
Definition: eda_rect.h:134
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
#define min(a, b)
Definition: auxiliary.h:85

References GetEnd(), GetOrigin(), Intersects(), max, min, SetEnd(), and SetOrigin().

Referenced by calcCommonArea(), LIB_ARC::HitTest(), and DRAWSEGMENT::HitTest().

◆ Contains() [1/3]

bool EDA_RECT::Contains ( const wxPoint &  aPoint) const

Function Contains.

Parameters
aPoint= the wxPoint to test
Returns
true if aPoint is inside the boundary box. A point on a edge is seen as inside

Definition at line 345 of file base_struct.cpp.

346 {
347  wxPoint rel_pos = aPoint - m_Pos;
348  wxSize size = m_Size;
349 
350  if( size.x < 0 )
351  {
352  size.x = -size.x;
353  rel_pos.x += size.x;
354  }
355 
356  if( size.y < 0 )
357  {
358  size.y = -size.y;
359  rel_pos.y += size.y;
360  }
361 
362  return (rel_pos.x >= 0) && (rel_pos.y >= 0) && ( rel_pos.y <= size.y) && ( rel_pos.x <= size.x);
363 }
wxSize m_Size
Definition: eda_rect.h:48
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, and m_Size.

Referenced by AR_AUTOPLACER::AutoplaceModules(), Contains(), GRPutPixel(), LIB_CIRCLE::HitTest(), SCH_PIN::HitTest(), LIB_BEZIER::HitTest(), LIB_POLYLINE::HitTest(), LIB_ARC::HitTest(), PCB_TARGET::HitTest(), SCH_JUNCTION::HitTest(), SCH_NO_CONNECT::HitTest(), SCH_BUS_ENTRY_BASE::HitTest(), LIB_PIN::HitTest(), SCH_BITMAP::HitTest(), SCH_SHEET_PIN::HitTest(), SCH_TEXT::HitTest(), SCH_LINE::HitTest(), SCH_FIELD::HitTest(), DRAWSEGMENT::HitTest(), LIB_ITEM::HitTest(), DIMENSION::HitTest(), TRACK::HitTest(), GERBER_DRAW_ITEM::HitTest(), WS_DRAW_ITEM_BITMAP::HitTest(), ZONE_CONTAINER::HitTest(), VIA::HitTest(), MODULE::HitTest(), SCH_SHEET::HitTest(), SCH_COMPONENT::HitTest(), D_PAD::HitTest(), MARKER_BASE::HitTestMarker(), LIB_RECTANGLE::Inside(), LIB_BEZIER::Inside(), LIB_POLYLINE::Inside(), LIB_ARC::Inside(), LIB_PIN::Inside(), Intersects(), MarkItemsInBloc(), AR_AUTOPLACER::nearestPad(), PCB_EDIT_FRAME::SpreadFootprints(), TEXTE_MODULE::TextHitTest(), and EDA_TEXT::TextHitTest().

◆ Contains() [2/3]

bool EDA_RECT::Contains ( int  x,
int  y 
) const
inline

Function Contains.

Parameters
x= the x coordinate of the point to test
y= the x coordinate of the point to test
Returns
true if point is inside the boundary box. A point on a edge is seen as inside

Definition at line 92 of file eda_rect.h.

92 { return Contains( wxPoint( x, y ) ); }
bool Contains(const wxPoint &aPoint) const
Function Contains.

References Contains().

Referenced by Contains().

◆ Contains() [3/3]

bool EDA_RECT::Contains ( const EDA_RECT aRect) const

Function Contains.

Parameters
aRect= the EDA_RECT to test
Returns
true if aRect is Contained. A common edge is seen as contained

Definition at line 366 of file base_struct.cpp.

367 {
368  return Contains( aRect.GetOrigin() ) && Contains( aRect.GetEnd() );
369 }
bool Contains(const wxPoint &aPoint) const
Function Contains.
const wxPoint GetEnd() const
Definition: eda_rect.h:114
const wxPoint GetOrigin() const
Definition: eda_rect.h:112

References Contains(), GetEnd(), and GetOrigin().

◆ FarthestPointTo()

const wxPoint EDA_RECT::FarthestPointTo ( const wxPoint &  aPoint) const

Return the point in this rect that is farthest from the provided point.

Definition at line 545 of file base_struct.cpp.

546 {
547  EDA_RECT me( *this );
548 
549  me.Normalize(); // ensure size is >= 0
550 
551  int fx = std::max( std::abs( aPoint.x - me.GetLeft() ), std::abs( aPoint.x - me.GetRight() ) );
552  int fy = std::max( std::abs( aPoint.y - me.GetTop() ), std::abs( aPoint.y - me.GetBottom() ) );
553 
554  return wxPoint( fx, fy );
555 }
#define abs(a)
Definition: auxiliary.h:84
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44

References abs, GetBottom(), GetLeft(), GetRight(), GetTop(), max, and Normalize().

Referenced by IntersectsCircleEdge().

◆ GetArea()

double EDA_RECT::GetArea ( ) const

Function GetArea returns the area of the rectangle.

Returns
The area of the rectangle.

Definition at line 699 of file base_struct.cpp.

700 {
701  return (double) GetWidth() * (double) GetHeight();
702 }
int GetWidth() const
Definition: eda_rect.h:117
int GetHeight() const
Definition: eda_rect.h:118

References GetHeight(), and GetWidth().

Referenced by calcArea(), calcCommonArea(), MODULE::CoverageRatio(), and SCH_COMPONENT::operator<().

◆ GetBottom()

◆ GetBoundingBoxRotated()

const EDA_RECT EDA_RECT::GetBoundingBoxRotated ( wxPoint  aRotCenter,
double  aAngle 
)

Function GetBoundingBoxRotated.

Returns
the bounding box of this, after rotation
Parameters
aAngle= the rotation angle in 0.1 deg.
aRotCenter= the rotation point. useful to calculate bounding box of rotated items, when rotation if not k*90 degrees

Definition at line 728 of file base_struct.cpp.

729 {
730  wxPoint corners[4];
731 
732  // Build the corners list
733  corners[0] = GetOrigin();
734  corners[2] = GetEnd();
735  corners[1].x = corners[0].x;
736  corners[1].y = corners[2].y;
737  corners[3].x = corners[2].x;
738  corners[3].y = corners[0].y;
739 
740  // Rotate all corners, to find the bounding box
741  for( int ii = 0; ii < 4; ii ++ )
742  RotatePoint( &corners[ii], aRotCenter, aAngle );
743 
744  // Find the corners bounding box
745  wxPoint start = corners[0];
746  wxPoint end = corners[0];
747 
748  for( int ii = 1; ii < 4; ii ++ )
749  {
750  start.x = std::min( start.x, corners[ii].x);
751  start.y = std::min( start.y, corners[ii].y);
752  end.x = std::max( end.x, corners[ii].x);
753  end.y = std::max( end.y, corners[ii].y);
754  }
755 
756  EDA_RECT bbox;
757  bbox.SetOrigin( start );
758  bbox.SetEnd( end );
759 
760  return bbox;
761 }
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
const wxPoint GetEnd() const
Definition: eda_rect.h:114
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
void SetEnd(int x, int y)
Definition: eda_rect.h:134
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
#define min(a, b)
Definition: auxiliary.h:85

References GetEnd(), GetOrigin(), max, min, RotatePoint(), SetEnd(), and SetOrigin().

Referenced by TEXTE_PCB::GetBoundingBox(), TEXTE_MODULE::GetBoundingBox(), D_PAD::GetBoundingBox(), and TEXTE_MODULE::ViewBBox().

◆ GetCenter()

const wxPoint EDA_RECT::GetCenter ( ) const
inline

Definition at line 115 of file eda_rect.h.

115 { return wxPoint( m_Pos.x + ( m_Size.x / 2 ), m_Pos.y + ( m_Size.y / 2 ) ); }
wxSize m_Size
Definition: eda_rect.h:48
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, and m_Size.

Referenced by DIALOG_EXPORT_STEP::onExportButton().

◆ GetEnd()

◆ GetHeight()

◆ GetLeft()

int EDA_RECT::GetLeft ( ) const
inline

◆ GetOrigin()

◆ GetPosition()

const wxPoint EDA_RECT::GetPosition ( ) const
inline

◆ GetRight()

◆ GetSize()

◆ GetSizeMax()

int EDA_RECT::GetSizeMax ( ) const
inline

GetSizeMax.

Returns
the max size dimension

Definition at line 107 of file eda_rect.h.

107 { return ( m_Size.x > m_Size.y )?m_Size.x:m_Size.y; }
wxSize m_Size
Definition: eda_rect.h:48

References m_Size.

Referenced by CINFO3D_VISU::AddShapeWithClearanceToContainer(), and CINFO3D_VISU::transformGraphicModuleEdgeToPolygonSet().

◆ GetTop()

int EDA_RECT::GetTop ( ) const
inline

◆ GetWidth()

◆ GetX()

◆ GetY()

◆ Inflate() [1/2]

EDA_RECT & EDA_RECT::Inflate ( wxCoord  dx,
wxCoord  dy 
)

Function Inflate inflates the rectangle horizontally by dx and vertically by dy.

If dx and/or dy is negative the rectangle is deflated.

Definition at line 600 of file base_struct.cpp.

601 {
602  if( m_Size.x >= 0 )
603  {
604  if( m_Size.x < -2 * dx )
605  {
606  // Don't allow deflate to eat more width than we have,
607  m_Pos.x += m_Size.x / 2;
608  m_Size.x = 0;
609  }
610  else
611  {
612  // The inflate is valid.
613  m_Pos.x -= dx;
614  m_Size.x += 2 * dx;
615  }
616  }
617  else // size.x < 0:
618  {
619  if( m_Size.x > -2 * dx )
620  {
621  // Don't allow deflate to eat more width than we have,
622  m_Pos.x -= m_Size.x / 2;
623  m_Size.x = 0;
624  }
625  else
626  {
627  // The inflate is valid.
628  m_Pos.x += dx;
629  m_Size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0
630  }
631  }
632 
633  if( m_Size.y >= 0 )
634  {
635  if( m_Size.y < -2 * dy )
636  {
637  // Don't allow deflate to eat more height than we have,
638  m_Pos.y += m_Size.y / 2;
639  m_Size.y = 0;
640  }
641  else
642  {
643  // The inflate is valid.
644  m_Pos.y -= dy;
645  m_Size.y += 2 * dy;
646  }
647  }
648  else // size.y < 0:
649  {
650  if( m_Size.y > 2 * dy )
651  {
652  // Don't allow deflate to eat more height than we have,
653  m_Pos.y -= m_Size.y / 2;
654  m_Size.y = 0;
655  }
656  else
657  {
658  // The inflate is valid.
659  m_Pos.y += dy;
660  m_Size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0
661  }
662  }
663 
664  return *this;
665 }
wxSize m_Size
Definition: eda_rect.h:48
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, and m_Size.

Referenced by AR_AUTOPLACER::addPad(), BuildBoardPolygonOutlines(), AR_AUTOPLACER::buildFpAreas(), ZONE_FILLER::buildZoneFeatureHoleList(), FillNegativeKnockout(), AR_AUTOPLACER::genModuleOnRoutingMatrix(), APERTURE_MACRO::GetApertureMacroShape(), SCH_JUNCTION::GetBoundingBox(), LIB_CIRCLE::GetBoundingBox(), SCH_NO_CONNECT::GetBoundingBox(), LIB_RECTANGLE::GetBoundingBox(), LIB_BEZIER::GetBoundingBox(), LIB_POLYLINE::GetBoundingBox(), LIB_ARC::GetBoundingBox(), SCH_BUS_ENTRY_BASE::GetBoundingBox(), LIB_PIN::GetBoundingBox(), BITMAP_BASE::GetBoundingBox(), DRAWSEGMENT::GetBoundingBox(), GERBER_DRAW_ITEM::GetBoundingBox(), SCH_SHEET::GetBoundingBox(), D_PAD::GetBoundingBox(), MODULE::GetFootprintRect(), GRCSegm(), GRLineArray(), GRSFilledRect(), LIB_CIRCLE::HitTest(), SCH_PIN::HitTest(), LIB_BEZIER::HitTest(), LIB_POLYLINE::HitTest(), LIB_ARC::HitTest(), PCB_TARGET::HitTest(), SCH_JUNCTION::HitTest(), SCH_NO_CONNECT::HitTest(), SCH_BUS_ENTRY_BASE::HitTest(), LIB_PIN::HitTest(), SCH_BITMAP::HitTest(), SCH_SHEET_PIN::HitTest(), SCH_TEXT::HitTest(), SCH_LINE::HitTest(), SCH_FIELD::HitTest(), DRAWSEGMENT::HitTest(), LIB_ITEM::HitTest(), DIMENSION::HitTest(), TRACK::HitTest(), ZONE_CONTAINER::HitTest(), VIA::HitTest(), MODULE::HitTest(), SCH_SHEET::HitTest(), SCH_COMPONENT::HitTest(), D_PAD::HitTest(), MARKER_BASE::HitTestMarker(), Inflate(), CINFO3D_VISU::InitSettings(), Intersects(), PCB_EDIT_FRAME::SpreadFootprints(), AR_AUTOPLACER::testModuleOnBoard(), AR_AUTOPLACER::testRectangle(), TEXTE_MODULE::TextHitTest(), EDA_TEXT::TextHitTest(), EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon(), MODULE::ViewBBox(), and WinClipAndDrawLine().

◆ Inflate() [2/2]

EDA_RECT & EDA_RECT::Inflate ( int  aDelta)

Function Inflate inflates the rectangle horizontally and vertically by aDelta.

If aDelta is negative the rectangle is deflated.

Definition at line 593 of file base_struct.cpp.

594 {
595  Inflate( aDelta, aDelta );
596  return *this;
597 }
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.

References Inflate().

◆ Intersects() [1/3]

bool EDA_RECT::Intersects ( const EDA_RECT aRect) const

Function Intersects tests for a common area between rectangles.

Parameters
aRectA rectangle to test intersection with.
Returns
bool - true if the argument rectangle intersects this rectangle. (i.e. if the 2 rectangles have at least a common point)

Definition at line 398 of file base_struct.cpp.

399 {
400  // this logic taken from wxWidgets' geometry.cpp file:
401  bool rc;
402  EDA_RECT me(*this);
403  EDA_RECT rect(aRect);
404  me.Normalize(); // ensure size is >= 0
405  rect.Normalize(); // ensure size is >= 0
406 
407  // calculate the left common area coordinate:
408  int left = std::max( me.m_Pos.x, rect.m_Pos.x );
409  // calculate the right common area coordinate:
410  int right = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
411  // calculate the upper common area coordinate:
412  int top = std::max( me.m_Pos.y, aRect.m_Pos.y );
413  // calculate the lower common area coordinate:
414  int bottom = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
415 
416  // if a common area exists, it must have a positive (null accepted) size
417  if( left <= right && top <= bottom )
418  rc = true;
419  else
420  rc = false;
421 
422  return rc;
423 }
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_Pos
Definition: eda_rect.h:47
#define min(a, b)
Definition: auxiliary.h:85

References m_Pos, m_Size, max, min, and Normalize().

Referenced by ZONE_FILLER::buildZoneFeatureHoleList(), Common(), AUTOPLACER::filtered_colliders(), LIB_CIRCLE::HitTest(), LIB_POLYLINE::HitTest(), LIB_BEZIER::HitTest(), LIB_ARC::HitTest(), PCB_TARGET::HitTest(), SCH_JUNCTION::HitTest(), SCH_NO_CONNECT::HitTest(), SCH_BUS_ENTRY_BASE::HitTest(), SCH_BITMAP::HitTest(), WS_DRAW_ITEM_LINE::HitTest(), SCH_TEXT::HitTest(), SCH_LINE::HitTest(), SCH_FIELD::HitTest(), DRAWSEGMENT::HitTest(), LIB_ITEM::HitTest(), DIMENSION::HitTest(), WS_DRAW_ITEM_POLYGON::HitTest(), TRACK::HitTest(), WS_DRAW_ITEM_RECT::HitTest(), WS_DRAW_ITEM_BITMAP::HitTest(), ZONE_CONTAINER::HitTest(), MODULE::HitTest(), SCH_SHEET::HitTest(), SCH_COMPONENT::HitTest(), D_PAD::HitTest(), LIB_TEXT::Inside(), LIB_FIELD::Inside(), Intersects(), TEXTE_MODULE::TextHitTest(), and EDA_TEXT::TextHitTest().

◆ Intersects() [2/3]

bool EDA_RECT::Intersects ( const EDA_RECT aRect,
double  aRot 
) const

Tests for a common area between this rectangle, and a rectangle with arbitrary rotation.

Parameters
aRecta rectangle to test intersection with
aRotrectangle rotation (in 1/10 degrees)

Definition at line 426 of file base_struct.cpp.

427 {
428  /* Most rectangles will be axis aligned.
429  * It is quicker to check for this case and pass the rect
430  * to the simpler intersection test
431  */
432 
433  // Prevent floating point comparison errors
434  static const double ROT_EPS = 0.000000001;
435 
436  static const double ROT_PARALLEL[] = { -3600, -1800, 0, 1800, 3600 };
437  static const double ROT_PERPENDICULAR[] = { -2700, -900, 0, 900, 2700 };
438 
439  NORMALIZE_ANGLE_POS<double>( aRot );
440 
441  // Test for non-rotated rectangle
442  for( int ii = 0; ii < 5; ii++ )
443  {
444  if( std::fabs( aRot - ROT_PARALLEL[ii] ) < ROT_EPS )
445  {
446  return Intersects( aRect );
447  }
448  }
449 
450  // Test for rectangle rotated by multiple of 90 degrees
451  for( int jj = 0; jj < 4; jj++ )
452  {
453  if( std::fabs( aRot - ROT_PERPENDICULAR[jj] ) < ROT_EPS )
454  {
455  EDA_RECT rotRect;
456 
457  // Rotate the supplied rect by 90 degrees
458  rotRect.SetOrigin( aRect.Centre() );
459  rotRect.Inflate( aRect.GetHeight(), aRect.GetWidth() );
460  return Intersects( rotRect );
461  }
462  }
463 
464  /* There is some non-orthogonal rotation.
465  * There are three cases to test:
466  * A) One point of this rect is inside the rotated rect
467  * B) One point of the rotated rect is inside this rect
468  * C) One of the sides of the rotated rect intersect this
469  */
470 
471  wxPoint corners[4];
472 
473  /* Test A : Any corners exist in rotated rect? */
474 
475  corners[0] = m_Pos;
476  corners[1] = m_Pos + wxPoint( m_Size.x, 0 );
477  corners[2] = m_Pos + wxPoint( m_Size.x, m_Size.y );
478  corners[3] = m_Pos + wxPoint( 0, m_Size.y );
479 
480  wxPoint rCentre = aRect.Centre();
481 
482  for( int i = 0; i < 4; i++ )
483  {
484  wxPoint delta = corners[i] - rCentre;
485  RotatePoint( &delta, -aRot );
486  delta += rCentre;
487 
488  if( aRect.Contains( delta ) )
489  {
490  return true;
491  }
492  }
493 
494  /* Test B : Any corners of rotated rect exist in this one? */
495  int w = aRect.GetWidth() / 2;
496  int h = aRect.GetHeight() / 2;
497 
498  // Construct corners around center of shape
499  corners[0] = wxPoint( -w, -h );
500  corners[1] = wxPoint( w, -h );
501  corners[2] = wxPoint( w, h );
502  corners[3] = wxPoint( -w, h );
503 
504  // Rotate and test each corner
505  for( int j=0; j<4; j++ )
506  {
507  RotatePoint( &corners[j], aRot );
508  corners[j] += rCentre;
509 
510  if( Contains( corners[j] ) )
511  {
512  return true;
513  }
514  }
515 
516  /* Test C : Any sides of rotated rect intersect this */
517 
518  if( Intersects( corners[0], corners[1] ) ||
519  Intersects( corners[1], corners[2] ) ||
520  Intersects( corners[2], corners[3] ) ||
521  Intersects( corners[3], corners[0] ) )
522  {
523  return true;
524  }
525 
526 
527  return false;
528 }
int GetWidth() const
Definition: eda_rect.h:117
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
bool Contains(const wxPoint &aPoint) const
Function Contains.
static const int delta[8][2]
Definition: solve.cpp:112
wxSize m_Size
Definition: eda_rect.h:48
int GetHeight() const
Definition: eda_rect.h:118
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_Pos
Definition: eda_rect.h:47
wxPoint Centre() const
Definition: eda_rect.h:60
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.

References Centre(), Contains(), delta, GetHeight(), GetWidth(), i, Inflate(), Intersects(), m_Pos, m_Size, RotatePoint(), and SetOrigin().

◆ Intersects() [3/3]

bool EDA_RECT::Intersects ( const wxPoint &  aPoint1,
const wxPoint &  aPoint2 
) const

Function Intersects tests for a common area between a segment and this rectangle.

Parameters
aPoint1First point of the segment to test intersection with.
aPoint2Second point of the segment to test intersection with.
Returns
bool - true if the argument segment intersects this rectangle. (i.e. if the segment and rectangle have at least a common point)

Definition at line 372 of file base_struct.cpp.

373 {
374  wxPoint point2, point4;
375 
376  if( Contains( aPoint1 ) || Contains( aPoint2 ) )
377  return true;
378 
379  point2.x = GetEnd().x;
380  point2.y = GetOrigin().y;
381  point4.x = GetOrigin().x;
382  point4.y = GetEnd().y;
383 
384  //Only need to test 3 sides since a straight line cant enter and exit on same side
385  if( SegmentIntersectsSegment( aPoint1, aPoint2, GetOrigin() , point2 ) )
386  return true;
387 
388  if( SegmentIntersectsSegment( aPoint1, aPoint2, point2 , GetEnd() ) )
389  return true;
390 
391  if( SegmentIntersectsSegment( aPoint1, aPoint2, GetEnd() , point4 ) )
392  return true;
393 
394  return false;
395 }
bool Contains(const wxPoint &aPoint) const
Function Contains.
const wxPoint GetEnd() const
Definition: eda_rect.h:114
bool SegmentIntersectsSegment(const wxPoint &a_p1_l1, const wxPoint &a_p2_l1, const wxPoint &a_p1_l2, const wxPoint &a_p2_l2)
Function SegmentIntersectsSegment.
Definition: trigo.cpp:58
const wxPoint GetOrigin() const
Definition: eda_rect.h:112

References Contains(), GetEnd(), GetOrigin(), and SegmentIntersectsSegment().

◆ IntersectsCircle()

bool EDA_RECT::IntersectsCircle ( const wxPoint &  aCenter,
const int  aRadius 
) const

Function IntersectsCircle tests for a common area between a circle and this rectangle.

Parameters
aCentercenter of the circle
aRadiusradius of the circle

Definition at line 558 of file base_struct.cpp.

559 {
560  wxPoint closest = ClosestPointTo( aCenter );
561 
562  double dx = aCenter.x - closest.x;
563  double dy = aCenter.y - closest.y;
564 
565  double r = (double) aRadius;
566 
567  return ( dx * dx + dy * dy ) <= ( r * r );
568 }
const wxPoint ClosestPointTo(const wxPoint &aPoint) const
Return the point in this rect that is closest to the provided point.

References ClosestPointTo().

Referenced by VIA::HitTest(), D_PAD::HitTest(), LIB_CIRCLE::Inside(), and IntersectsCircleEdge().

◆ IntersectsCircleEdge()

bool EDA_RECT::IntersectsCircleEdge ( const wxPoint &  aCenter,
const int  aRadius,
const int  aWidth 
) const

IntersectsCircleEdge Tests for intersection between this rect and the edge (radius) of a circle.

Parameters
aCentercenter of the circle
aRadiusradius of the circle
aWidthwidth of the circle edge

Definition at line 571 of file base_struct.cpp.

572 {
573  EDA_RECT me( *this );
574  me.Normalize(); // ensure size is >= 0
575 
576  // Test if the circle intersects at all
577  if( !IntersectsCircle( aCenter, aRadius + aWidth / 2 ) )
578  {
579  return false;
580  }
581 
582  wxPoint farpt = FarthestPointTo( aCenter );
583  // Farthest point must be further than the inside of the line
584  double fx = (double) farpt.x;
585  double fy = (double) farpt.y;
586 
587  double r = (double) aRadius - (double) aWidth / 2;
588 
589  return ( fx * fx + fy * fy ) > ( r * r );
590 }
bool IntersectsCircle(const wxPoint &aCenter, const int aRadius) const
Function IntersectsCircle tests for a common area between a circle and this rectangle.
const wxPoint FarthestPointTo(const wxPoint &aPoint) const
Return the point in this rect that is farthest from the provided point.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44

References FarthestPointTo(), IntersectsCircle(), and Normalize().

Referenced by LIB_CIRCLE::HitTest(), LIB_ARC::HitTest(), and DRAWSEGMENT::HitTest().

◆ Merge() [1/2]

void EDA_RECT::Merge ( const EDA_RECT aRect)

Function Merge modifies the position and size of the rectangle in order to contain aRect.

It is mainly used to calculate bounding boxes.

Parameters
aRectThe rectangle to merge with this rectangle.

Definition at line 668 of file base_struct.cpp.

669 {
670  Normalize(); // ensure width and height >= 0
671  EDA_RECT rect = aRect;
672  rect.Normalize(); // ensure width and height >= 0
673  wxPoint end = GetEnd();
674  wxPoint rect_end = rect.GetEnd();
675 
676  // Change origin and size in order to contain the given rect
677  m_Pos.x = std::min( m_Pos.x, rect.m_Pos.x );
678  m_Pos.y = std::min( m_Pos.y, rect.m_Pos.y );
679  end.x = std::max( end.x, rect_end.x );
680  end.y = std::max( end.y, rect_end.y );
681  SetEnd( end );
682 }
const wxPoint GetEnd() const
Definition: eda_rect.h:114
void SetEnd(int x, int y)
Definition: eda_rect.h:134
void Normalize()
Function Normalize ensures that the height ant width are positive.
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_Pos
Definition: eda_rect.h:47
#define min(a, b)
Definition: auxiliary.h:85

References GetEnd(), m_Pos, max, min, Normalize(), and SetEnd().

Referenced by PCB_EDIT_FRAME::AppendBoardFile(), DRAWSEGMENT::computeArcBBox(), GBR_LAYOUT::ComputeBoundingBox(), BOARD::ComputeBoundingBox(), LIB_PART::GetBodyBoundingBox(), SELECTION::GetBoundingBox(), MODULE::GetBoundingBox(), DRAWSEGMENT::GetBoundingBox(), SCH_COMPONENT::GetBoundingBox(), D_PAD::GetBoundingBox(), MODULE::GetFootprintRect(), getSheetBbox(), LIB_PART::GetUnitBoundingBox(), InvokeDialogImportGfxBoard(), InvokeDialogImportGfxModule(), and MODULE::ViewBBox().

◆ Merge() [2/2]

void EDA_RECT::Merge ( const wxPoint &  aPoint)

Function Merge modifies the position and size of the rectangle in order to contain the given point.

Parameters
aPointThe point to merge with the rectangle.

Definition at line 685 of file base_struct.cpp.

686 {
687  Normalize(); // ensure width and height >= 0
688 
689  wxPoint end = GetEnd();
690  // Change origin and size in order to contain the given rect
691  m_Pos.x = std::min( m_Pos.x, aPoint.x );
692  m_Pos.y = std::min( m_Pos.y, aPoint.y );
693  end.x = std::max( end.x, aPoint.x );
694  end.y = std::max( end.y, aPoint.y );
695  SetEnd( end );
696 }
const wxPoint GetEnd() const
Definition: eda_rect.h:114
void SetEnd(int x, int y)
Definition: eda_rect.h:134
void Normalize()
Function Normalize ensures that the height ant width are positive.
#define max(a, b)
Definition: auxiliary.h:86
wxPoint m_Pos
Definition: eda_rect.h:47
#define min(a, b)
Definition: auxiliary.h:85

References GetEnd(), m_Pos, max, min, Normalize(), and SetEnd().

◆ Move()

void EDA_RECT::Move ( const wxPoint &  aMoveVector)

Function Move moves the rectangle by the aMoveVector.

Parameters
aMoveVectorA wxPoint that is the value to move this rectangle

Definition at line 339 of file base_struct.cpp.

340 {
341  m_Pos += aMoveVector;
342 }
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos.

Referenced by APERTURE_MACRO::GetApertureMacroShape(), SCH_BITMAP::GetBoundingBox(), SCH_FIELD::GetBoundingBox(), GERBER_DRAW_ITEM::GetBoundingBox(), AR_AUTOPLACER::getOptimalModulePlacement(), EDA_TEXT::GetTextBox(), WS_DRAW_ITEM_BITMAP::HitTest(), and AR_AUTOPLACER::testModuleOnBoard().

◆ Normalize()

◆ Offset() [1/2]

void EDA_RECT::Offset ( int  dx,
int  dy 
)
inline

Definition at line 128 of file eda_rect.h.

128 { m_Pos.x += dx; m_Pos.y += dy; }
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos.

Referenced by SCH_COMPONENT::GetBodyBoundingBox(), and SCH_PIN::GetBoundingBox().

◆ Offset() [2/2]

void EDA_RECT::Offset ( const wxPoint &  offset)
inline

Definition at line 129 of file eda_rect.h.

129 { m_Pos += offset; }
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos.

◆ operator BOX2I()

EDA_RECT::operator BOX2I ( ) const
inline

Function operator(BOX2I) overloads the cast operator to return a BOX2I.

Returns
BOX2I - this box shaped as a BOX2I object.

Definition at line 228 of file eda_rect.h.

229  {
230  EDA_RECT rect( m_Pos, m_Size );
231  rect.Normalize();
232  return BOX2I( rect.GetOrigin(), rect.GetSize() );
233  }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
wxSize m_Size
Definition: eda_rect.h:48
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_Pos
Definition: eda_rect.h:47

References GetOrigin(), GetSize(), m_Pos, m_Size, and Normalize().

◆ operator wxRect()

EDA_RECT::operator wxRect ( ) const
inline

Function operator(wxRect) overloads the cast operator to return a wxRect wxRect does not accept negative values for size, so ensure the wxRect size is always >= 0.

Definition at line 216 of file eda_rect.h.

217  {
218  EDA_RECT rect( m_Pos, m_Size );
219  rect.Normalize();
220  return wxRect( rect.m_Pos, rect.m_Size );
221  }
wxSize m_Size
Definition: eda_rect.h:48
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, m_Size, and Normalize().

◆ RevertYAxis()

void EDA_RECT::RevertYAxis ( )
inline

Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size)

Definition at line 144 of file eda_rect.h.

145  {
146  m_Pos.y = -m_Pos.y;
147  m_Size.y = -m_Size.y;
148  Normalize();
149  }
wxSize m_Size
Definition: eda_rect.h:48
void Normalize()
Function Normalize ensures that the height ant width are positive.
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, m_Size, and Normalize().

Referenced by KIGFX::SCH_PAINTER::draw(), LIB_TEXT::drawGraphic(), LIB_CIRCLE::GetBoundingBox(), LIB_RECTANGLE::GetBoundingBox(), LIB_BEZIER::GetBoundingBox(), LIB_POLYLINE::GetBoundingBox(), LIB_TEXT::GetBoundingBox(), LIB_PIN::GetBoundingBox(), LIB_FIELD::GetBoundingBox(), LIB_TEXT::Plot(), and LIB_FIELD::Plot().

◆ SetEnd() [1/2]

◆ SetEnd() [2/2]

void EDA_RECT::SetEnd ( const wxPoint &  pos)
inline

Definition at line 135 of file eda_rect.h.

136  {
137  m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
138  }
wxSize m_Size
Definition: eda_rect.h:48
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, and m_Size.

◆ SetHeight()

void EDA_RECT::SetHeight ( int  val)
inline

◆ SetOrigin() [1/2]

◆ SetOrigin() [2/2]

void EDA_RECT::SetOrigin ( int  x,
int  y 
)
inline

Definition at line 125 of file eda_rect.h.

125 { m_Pos.x = x; m_Pos.y = y; }
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos.

◆ SetSize() [1/2]

void EDA_RECT::SetSize ( const wxSize &  size)
inline

◆ SetSize() [2/2]

void EDA_RECT::SetSize ( int  w,
int  h 
)
inline

Definition at line 127 of file eda_rect.h.

127 { m_Size.x = w; m_Size.y = h; }
wxSize m_Size
Definition: eda_rect.h:48

References m_Size.

◆ SetWidth()

void EDA_RECT::SetWidth ( int  val)
inline

◆ SetX()

◆ SetY()

Member Data Documentation

◆ m_Pos

◆ m_Size


The documentation for this class was generated from the following files: