KiCad PCB EDA Suite
EDA_RECT Class Reference

EDA_RECT handles the component boundary box. More...

#include <eda_rect.h>

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
 
bool IsValid () 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
 
bool m_init
 

Detailed Description

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 52 of file eda_rect.h.

52 : m_init( false ) { };
bool m_init
Definition: eda_rect.h:49

◆ EDA_RECT() [2/2]

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

Definition at line 54 of file eda_rect.h.

54  :
55  m_Pos( aPos ),
56  m_Size( aSize ),
57  m_init( true )
58  { }
wxSize m_Size
Definition: eda_rect.h:48
bool m_init
Definition: eda_rect.h:49
wxPoint m_Pos
Definition: eda_rect.h:47

◆ ~EDA_RECT()

virtual EDA_RECT::~EDA_RECT ( )
inlinevirtual

Definition at line 60 of file eda_rect.h.

60 { };

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 482 of file base_struct.cpp.

483 {
484  EDA_RECT me( *this );
485 
486  me.Normalize(); // ensure size is >= 0
487 
488  // Determine closest point to the circle centre within this rect
489  int nx = std::max( me.GetLeft(), std::min( aPoint.x, me.GetRight() ) );
490  int ny = std::max( me.GetTop(), std::min( aPoint.y, me.GetBottom() ) );
491 
492  return wxPoint( nx, ny );
493 }
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44

References GetBottom(), GetLeft(), GetRight(), GetTop(), Normalize(), wxPoint::x, and wxPoint::y.

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 681 of file base_struct.cpp.

682 {
683  EDA_RECT r;
684 
685  if( Intersects( aRect ) )
686  {
687  wxPoint originA( std::min( GetOrigin().x, GetEnd().x ),
688  std::min( GetOrigin().y, GetEnd().y ) );
689  wxPoint originB( std::min( aRect.GetOrigin().x, aRect.GetEnd().x ),
690  std::min( aRect.GetOrigin().y, aRect.GetEnd().y ) );
691  wxPoint endA( std::max( GetOrigin().x, GetEnd().x ),
692  std::max( GetOrigin().y, GetEnd().y ) );
693  wxPoint endB( std::max( aRect.GetOrigin().x, aRect.GetEnd().x ),
694  std::max( aRect.GetOrigin().y, aRect.GetEnd().y ) );
695 
696  r.SetOrigin( wxPoint( std::max( originA.x, originB.x ), std::max( originA.y, originB.y ) ) );
697  r.SetEnd ( wxPoint( std::min( endA.x, endB.x ), std::min( endA.y, endB.y ) ) );
698  }
699 
700  return r;
701 }
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
const wxPoint GetEnd() const
Definition: eda_rect.h:116
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
void SetEnd(int x, int y)
Definition: eda_rect.h:192
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.

References GetEnd(), GetOrigin(), Intersects(), SetEnd(), SetOrigin(), wxPoint::x, and wxPoint::y.

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 290 of file base_struct.cpp.

291 {
292  wxPoint rel_pos = aPoint - m_Pos;
293  wxSize size = m_Size;
294 
295  if( size.x < 0 )
296  {
297  size.x = -size.x;
298  rel_pos.x += size.x;
299  }
300 
301  if( size.y < 0 )
302  {
303  size.y = -size.y;
304  rel_pos.y += size.y;
305  }
306 
307  return (rel_pos.x >= 0) && (rel_pos.y >= 0) && ( rel_pos.y <= size.y) && ( rel_pos.x <= size.x);
308 }
wxSize m_Size
Definition: eda_rect.h:48
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, m_Size, wxPoint::x, and wxPoint::y.

Referenced by AR_AUTOPLACER::AutoplaceModules(), Contains(), DRC::doTrackDrc(), GRPutPixel(), LIB_CIRCLE::HitTest(), LIB_BEZIER::HitTest(), LIB_ARC::HitTest(), LIB_POLYLINE::HitTest(), SCH_PIN::HitTest(), PCB_TARGET::HitTest(), WS_DRAW_ITEM_BASE::HitTest(), SCH_JUNCTION::HitTest(), SCH_NO_CONNECT::HitTest(), LIB_PIN::HitTest(), SCH_BUS_ENTRY_BASE::HitTest(), SCH_BITMAP::HitTest(), WS_DRAW_ITEM_POLYPOLYGONS::HitTest(), TRACK::HitTest(), SCH_FIELD::HitTest(), LIB_ITEM::HitTest(), SCH_SHEET_PIN::HitTest(), SCH_LINE::HitTest(), DIMENSION::HitTest(), DRAWSEGMENT::HitTest(), GERBER_DRAW_ITEM::HitTest(), ARC::HitTest(), SCH_TEXT::HitTest(), WS_DRAW_ITEM_BITMAP::HitTest(), ZONE_CONTAINER::HitTest(), VIA::HitTest(), MODULE::HitTest(), D_PAD::HitTest(), SCH_SHEET::HitTest(), SCH_COMPONENT::HitTest(), MARKER_BASE::HitTestMarker(), Intersects(), EE_SELECTION_TOOL::Main(), SELECTION_TOOL::Main(), AR_AUTOPLACER::nearestPad(), ALTIUM_PCB::ParsePolygons6Data(), 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 94 of file eda_rect.h.

94 { 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 311 of file base_struct.cpp.

312 {
313  return Contains( aRect.GetOrigin() ) && Contains( aRect.GetEnd() );
314 }
bool Contains(const wxPoint &aPoint) const
Function Contains.
const wxPoint GetEnd() const
Definition: eda_rect.h:116
const wxPoint GetOrigin() const
Definition: eda_rect.h:114

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 496 of file base_struct.cpp.

497 {
498  EDA_RECT me( *this );
499 
500  me.Normalize(); // ensure size is >= 0
501 
502  int fx = std::max( std::abs( aPoint.x - me.GetLeft() ), std::abs( aPoint.x - me.GetRight() ) );
503  int fy = std::max( std::abs( aPoint.y - me.GetTop() ), std::abs( aPoint.y - me.GetBottom() ) );
504 
505  return wxPoint( fx, fy );
506 }
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44

References GetBottom(), GetLeft(), GetRight(), GetTop(), Normalize(), wxPoint::x, and wxPoint::y.

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 675 of file base_struct.cpp.

676 {
677  return (double) GetWidth() * (double) GetHeight();
678 }
int GetWidth() const
Definition: eda_rect.h:119
int GetHeight() const
Definition: eda_rect.h:120

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 704 of file base_struct.cpp.

705 {
706  wxPoint corners[4];
707 
708  // Build the corners list
709  corners[0] = GetOrigin();
710  corners[2] = GetEnd();
711  corners[1].x = corners[0].x;
712  corners[1].y = corners[2].y;
713  corners[3].x = corners[2].x;
714  corners[3].y = corners[0].y;
715 
716  // Rotate all corners, to find the bounding box
717  for( int ii = 0; ii < 4; ii ++ )
718  RotatePoint( &corners[ii], aRotCenter, aAngle );
719 
720  // Find the corners bounding box
721  wxPoint start = corners[0];
722  wxPoint end = corners[0];
723 
724  for( int ii = 1; ii < 4; ii ++ )
725  {
726  start.x = std::min( start.x, corners[ii].x);
727  start.y = std::min( start.y, corners[ii].y);
728  end.x = std::max( end.x, corners[ii].x);
729  end.y = std::max( end.y, corners[ii].y);
730  }
731 
732  EDA_RECT bbox;
733  bbox.SetOrigin( start );
734  bbox.SetEnd( end );
735 
736  return bbox;
737 }
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
const wxPoint GetEnd() const
Definition: eda_rect.h:116
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
void SetEnd(int x, int y)
Definition: eda_rect.h:192
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44

References GetEnd(), GetOrigin(), RotatePoint(), SetEnd(), SetOrigin(), wxPoint::x, and wxPoint::y.

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

◆ GetCenter()

const wxPoint EDA_RECT::GetCenter ( ) const
inline

◆ GetEnd()

◆ GetHeight()

◆ GetLeft()

◆ GetOrigin()

◆ GetPosition()

◆ GetRight()

◆ GetSize()

◆ GetSizeMax()

int EDA_RECT::GetSizeMax ( ) const
inline

GetSizeMax.

Returns
the max size dimension

Definition at line 109 of file eda_rect.h.

109 { 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 BOARD_ADAPTER::AddShapeWithClearanceToContainer().

◆ GetTop()

◆ 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 557 of file base_struct.cpp.

558 {
559  if( m_Size.x >= 0 )
560  {
561  if( m_Size.x < -2 * dx )
562  {
563  // Don't allow deflate to eat more width than we have,
564  m_Pos.x += m_Size.x / 2;
565  m_Size.x = 0;
566  }
567  else
568  {
569  // The inflate is valid.
570  m_Pos.x -= dx;
571  m_Size.x += 2 * dx;
572  }
573  }
574  else // size.x < 0:
575  {
576  if( m_Size.x > -2 * dx )
577  {
578  // Don't allow deflate to eat more width than we have,
579  m_Pos.x -= m_Size.x / 2;
580  m_Size.x = 0;
581  }
582  else
583  {
584  // The inflate is valid.
585  m_Pos.x += dx;
586  m_Size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0
587  }
588  }
589 
590  if( m_Size.y >= 0 )
591  {
592  if( m_Size.y < -2 * dy )
593  {
594  // Don't allow deflate to eat more height than we have,
595  m_Pos.y += m_Size.y / 2;
596  m_Size.y = 0;
597  }
598  else
599  {
600  // The inflate is valid.
601  m_Pos.y -= dy;
602  m_Size.y += 2 * dy;
603  }
604  }
605  else // size.y < 0:
606  {
607  if( m_Size.y > 2 * dy )
608  {
609  // Don't allow deflate to eat more height than we have,
610  m_Pos.y -= m_Size.y / 2;
611  m_Size.y = 0;
612  }
613  else
614  {
615  // The inflate is valid.
616  m_Pos.y += dy;
617  m_Size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0
618  }
619  }
620 
621  return *this;
622 }
wxSize m_Size
Definition: eda_rect.h:48
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, m_Size, wxPoint::x, and wxPoint::y.

Referenced by AR_AUTOPLACER::addPad(), BuildBoardPolygonOutlines(), ZONE_FILLER::buildCopperItemClearances(), AR_AUTOPLACER::buildFpAreas(), DRC::checkClearanceSegmToPad(), DRC_KEEPOUT_TESTER::checkPads(), DRC::doTrackDrc(), FillNegativeKnockout(), SCH_EDITOR_CONTROL::FindComponentAndItem(), AR_AUTOPLACER::genModuleOnRoutingMatrix(), APERTURE_MACRO::GetApertureMacroShape(), SCH_SHEET::GetBodyBoundingBox(), LIB_CIRCLE::GetBoundingBox(), SCH_JUNCTION::GetBoundingBox(), LIB_RECTANGLE::GetBoundingBox(), LIB_BEZIER::GetBoundingBox(), LIB_ARC::GetBoundingBox(), SCH_NO_CONNECT::GetBoundingBox(), LIB_POLYLINE::GetBoundingBox(), SCH_BUS_ENTRY_BASE::GetBoundingBox(), LIB_PIN::GetBoundingBox(), BITMAP_BASE::GetBoundingBox(), GERBER_DRAW_ITEM::GetBoundingBox(), DRAWSEGMENT::GetBoundingBox(), SCH_LABEL::GetBoundingBox(), MODULE::GetFootprintRect(), SCH_SCREEN::GetItem(), GRCSegm(), GRLineArray(), GRSFilledRect(), hasThermalConnection(), LIB_CIRCLE::HitTest(), LIB_BEZIER::HitTest(), LIB_ARC::HitTest(), LIB_POLYLINE::HitTest(), SCH_PIN::HitTest(), PCB_TARGET::HitTest(), WS_DRAW_ITEM_BASE::HitTest(), SCH_JUNCTION::HitTest(), SCH_NO_CONNECT::HitTest(), LIB_PIN::HitTest(), SCH_BUS_ENTRY_BASE::HitTest(), SCH_BITMAP::HitTest(), WS_DRAW_ITEM_POLYPOLYGONS::HitTest(), TRACK::HitTest(), SCH_FIELD::HitTest(), LIB_ITEM::HitTest(), SCH_SHEET_PIN::HitTest(), SCH_LINE::HitTest(), DIMENSION::HitTest(), DRAWSEGMENT::HitTest(), ARC::HitTest(), SCH_TEXT::HitTest(), WS_DRAW_ITEM_BITMAP::HitTest(), ZONE_CONTAINER::HitTest(), VIA::HitTest(), MODULE::HitTest(), D_PAD::HitTest(), SCH_SHEET::HitTest(), SCH_COMPONENT::HitTest(), MARKER_BASE::HitTestMarker(), Inflate(), BOARD_ADAPTER::InitSettings(), Intersects(), EE_RTREE::Overlapping(), 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 550 of file base_struct.cpp.

551 {
552  Inflate( aDelta, aDelta );
553  return *this;
554 }
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 343 of file base_struct.cpp.

344 {
345  if( !m_init )
346  return false;
347 
348  // this logic taken from wxWidgets' geometry.cpp file:
349  bool rc;
350  EDA_RECT me(*this);
351  EDA_RECT rect(aRect);
352  me.Normalize(); // ensure size is >= 0
353  rect.Normalize(); // ensure size is >= 0
354 
355  // calculate the left common area coordinate:
356  int left = std::max( me.m_Pos.x, rect.m_Pos.x );
357  // calculate the right common area coordinate:
358  int right = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
359  // calculate the upper common area coordinate:
360  int top = std::max( me.m_Pos.y, aRect.m_Pos.y );
361  // calculate the lower common area coordinate:
362  int bottom = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
363 
364  // if a common area exists, it must have a positive (null accepted) size
365  if( left <= right && top <= bottom )
366  rc = true;
367  else
368  rc = false;
369 
370  return rc;
371 }
bool m_init
Definition: eda_rect.h:49
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_Pos
Definition: eda_rect.h:47

References m_init, m_Pos, m_Size, Normalize(), wxPoint::x, and wxPoint::y.

Referenced by BOOST_AUTO_TEST_CASE(), ZONE_FILLER::buildCopperItemClearances(), DRC_KEEPOUT_TESTER::checkDrawings(), DRC_KEEPOUT_TESTER::checkFootprints(), DRC_KEEPOUT_TESTER::checkPads(), DRC_KEEPOUT_TESTER::checkTracksAndVias(), Common(), DRC::doTrackDrc(), AUTOPLACER::filtered_colliders(), hasThermalConnection(), LIB_CIRCLE::HitTest(), LIB_BEZIER::HitTest(), LIB_ARC::HitTest(), LIB_POLYLINE::HitTest(), PCB_TARGET::HitTest(), WS_DRAW_ITEM_BASE::HitTest(), SCH_JUNCTION::HitTest(), SCH_NO_CONNECT::HitTest(), SCH_BUS_ENTRY_BASE::HitTest(), SCH_BITMAP::HitTest(), WS_DRAW_ITEM_POLYPOLYGONS::HitTest(), TRACK::HitTest(), LIB_ITEM::HitTest(), SCH_FIELD::HitTest(), SCH_LINE::HitTest(), DIMENSION::HitTest(), DRAWSEGMENT::HitTest(), ARC::HitTest(), SCH_TEXT::HitTest(), ZONE_CONTAINER::HitTest(), MODULE::HitTest(), D_PAD::HitTest(), SCH_SHEET::HitTest(), SCH_COMPONENT::HitTest(), 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 374 of file base_struct.cpp.

375 {
376  if( !m_init )
377  return false;
378 
379  /* Most rectangles will be axis aligned.
380  * It is quicker to check for this case and pass the rect
381  * to the simpler intersection test
382  */
383 
384  // Prevent floating point comparison errors
385  static const double ROT_EPS = 0.000000001;
386 
387  static const double ROT_PARALLEL[] = { -3600, -1800, 0, 1800, 3600 };
388  static const double ROT_PERPENDICULAR[] = { -2700, -900, 0, 900, 2700 };
389 
390  NORMALIZE_ANGLE_POS<double>( aRot );
391 
392  // Test for non-rotated rectangle
393  for( int ii = 0; ii < 5; ii++ )
394  {
395  if( std::fabs( aRot - ROT_PARALLEL[ii] ) < ROT_EPS )
396  {
397  return Intersects( aRect );
398  }
399  }
400 
401  // Test for rectangle rotated by multiple of 90 degrees
402  for( int jj = 0; jj < 4; jj++ )
403  {
404  if( std::fabs( aRot - ROT_PERPENDICULAR[jj] ) < ROT_EPS )
405  {
406  EDA_RECT rotRect;
407 
408  // Rotate the supplied rect by 90 degrees
409  rotRect.SetOrigin( aRect.Centre() );
410  rotRect.Inflate( aRect.GetHeight(), aRect.GetWidth() );
411  return Intersects( rotRect );
412  }
413  }
414 
415  /* There is some non-orthogonal rotation.
416  * There are three cases to test:
417  * A) One point of this rect is inside the rotated rect
418  * B) One point of the rotated rect is inside this rect
419  * C) One of the sides of the rotated rect intersect this
420  */
421 
422  wxPoint corners[4];
423 
424  /* Test A : Any corners exist in rotated rect? */
425 
426  corners[0] = m_Pos;
427  corners[1] = m_Pos + wxPoint( m_Size.x, 0 );
428  corners[2] = m_Pos + wxPoint( m_Size.x, m_Size.y );
429  corners[3] = m_Pos + wxPoint( 0, m_Size.y );
430 
431  wxPoint rCentre = aRect.Centre();
432 
433  for( int i = 0; i < 4; i++ )
434  {
435  wxPoint delta = corners[i] - rCentre;
436  RotatePoint( &delta, -aRot );
437  delta += rCentre;
438 
439  if( aRect.Contains( delta ) )
440  {
441  return true;
442  }
443  }
444 
445  /* Test B : Any corners of rotated rect exist in this one? */
446  int w = aRect.GetWidth() / 2;
447  int h = aRect.GetHeight() / 2;
448 
449  // Construct corners around center of shape
450  corners[0] = wxPoint( -w, -h );
451  corners[1] = wxPoint( w, -h );
452  corners[2] = wxPoint( w, h );
453  corners[3] = wxPoint( -w, h );
454 
455  // Rotate and test each corner
456  for( int j=0; j<4; j++ )
457  {
458  RotatePoint( &corners[j], aRot );
459  corners[j] += rCentre;
460 
461  if( Contains( corners[j] ) )
462  {
463  return true;
464  }
465  }
466 
467  /* Test C : Any sides of rotated rect intersect this */
468 
469  if( Intersects( corners[0], corners[1] ) ||
470  Intersects( corners[1], corners[2] ) ||
471  Intersects( corners[2], corners[3] ) ||
472  Intersects( corners[3], corners[0] ) )
473  {
474  return true;
475  }
476 
477 
478  return false;
479 }
int GetWidth() const
Definition: eda_rect.h:119
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
bool Contains(const wxPoint &aPoint) const
Function Contains.
wxSize m_Size
Definition: eda_rect.h:48
int GetHeight() const
Definition: eda_rect.h:120
bool m_init
Definition: eda_rect.h:49
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:62
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(), GetHeight(), GetWidth(), Inflate(), Intersects(), m_init, 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 317 of file base_struct.cpp.

318 {
319  wxPoint point2, point4;
320 
321  if( Contains( aPoint1 ) || Contains( aPoint2 ) )
322  return true;
323 
324  point2.x = GetEnd().x;
325  point2.y = GetOrigin().y;
326  point4.x = GetOrigin().x;
327  point4.y = GetEnd().y;
328 
329  //Only need to test 3 sides since a straight line cant enter and exit on same side
330  if( SegmentIntersectsSegment( aPoint1, aPoint2, GetOrigin() , point2 ) )
331  return true;
332 
333  if( SegmentIntersectsSegment( aPoint1, aPoint2, point2 , GetEnd() ) )
334  return true;
335 
336  if( SegmentIntersectsSegment( aPoint1, aPoint2, GetEnd() , point4 ) )
337  return true;
338 
339  return false;
340 }
bool Contains(const wxPoint &aPoint) const
Function Contains.
bool SegmentIntersectsSegment(const wxPoint &a_p1_l1, const wxPoint &a_p2_l1, const wxPoint &a_p1_l2, const wxPoint &a_p2_l2, wxPoint *aIntersectionPoint=nullptr)
Test if two lines intersect.
Definition: trigo.cpp:61
const wxPoint GetEnd() const
Definition: eda_rect.h:116
const wxPoint GetOrigin() const
Definition: eda_rect.h:114

References Contains(), GetEnd(), GetOrigin(), SegmentIntersectsSegment(), wxPoint::x, and wxPoint::y.

◆ 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 509 of file base_struct.cpp.

510 {
511  if( !m_init )
512  return false;
513 
514  wxPoint closest = ClosestPointTo( aCenter );
515 
516  double dx = aCenter.x - closest.x;
517  double dy = aCenter.y - closest.y;
518 
519  double r = (double) aRadius;
520 
521  return ( dx * dx + dy * dy ) <= ( r * r );
522 }
bool m_init
Definition: eda_rect.h:49
const wxPoint ClosestPointTo(const wxPoint &aPoint) const
Return the point in this rect that is closest to the provided point.

References ClosestPointTo(), m_init, wxPoint::x, and wxPoint::y.

Referenced by VIA::HitTest(), 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 525 of file base_struct.cpp.

526 {
527  if( !m_init )
528  return false;
529 
530  EDA_RECT me( *this );
531  me.Normalize(); // ensure size is >= 0
532 
533  // Test if the circle intersects at all
534  if( !IntersectsCircle( aCenter, aRadius + aWidth / 2 ) )
535  {
536  return false;
537  }
538 
539  wxPoint farpt = FarthestPointTo( aCenter );
540  // Farthest point must be further than the inside of the line
541  double fx = (double) farpt.x;
542  double fy = (double) farpt.y;
543 
544  double r = (double) aRadius - (double) aWidth / 2;
545 
546  return ( fx * fx + fy * fy ) > ( r * r );
547 }
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.
bool m_init
Definition: eda_rect.h:49
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44

References FarthestPointTo(), IntersectsCircle(), m_init, Normalize(), wxPoint::x, and wxPoint::y.

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

◆ IsValid()

bool EDA_RECT::IsValid ( ) const
inline

Definition at line 126 of file eda_rect.h.

127  {
128  return m_init;
129  }
bool m_init
Definition: eda_rect.h:49

References m_init.

Referenced by Merge().

◆ 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 625 of file base_struct.cpp.

626 {
627  if( !m_init )
628  {
629  if( aRect.IsValid() )
630  {
631  m_Pos = aRect.GetPosition();
632  m_Size = aRect.GetSize();
633  m_init = true;
634  }
635  return;
636  }
637 
638  Normalize(); // ensure width and height >= 0
639  EDA_RECT rect = aRect;
640  rect.Normalize(); // ensure width and height >= 0
641  wxPoint end = GetEnd();
642  wxPoint rect_end = rect.GetEnd();
643 
644  // Change origin and size in order to contain the given rect
645  m_Pos.x = std::min( m_Pos.x, rect.m_Pos.x );
646  m_Pos.y = std::min( m_Pos.y, rect.m_Pos.y );
647  end.x = std::max( end.x, rect_end.x );
648  end.y = std::max( end.y, rect_end.y );
649  SetEnd( end );
650 }
const wxPoint GetEnd() const
Definition: eda_rect.h:116
wxSize m_Size
Definition: eda_rect.h:48
void SetEnd(int x, int y)
Definition: eda_rect.h:192
const wxPoint GetPosition() const
Definition: eda_rect.h:115
void Normalize()
Function Normalize ensures that the height ant width are positive.
bool m_init
Definition: eda_rect.h:49
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_Pos
Definition: eda_rect.h:47
bool IsValid() const
Definition: eda_rect.h:126
const wxSize GetSize() const
Definition: eda_rect.h:103

References GetEnd(), GetPosition(), GetSize(), IsValid(), m_init, m_Pos, m_Size, Normalize(), SetEnd(), wxPoint::x, and wxPoint::y.

Referenced by D_PAD::BuildEffectiveShapes(), DRAWSEGMENT::computeArcBBox(), GBR_LAYOUT::ComputeBoundingBox(), BOARD::ComputeBoundingBox(), LIB_PART::GetBodyBoundingBox(), SELECTION::GetBoundingBox(), MODULE::GetBoundingBox(), DRAWSEGMENT::GetBoundingBox(), SCH_COMPONENT::GetBoundingBox(), SCH_SHEET::GetBoundingBox(), GERBVIEW_SELECTION::GetCenter(), MODULE::GetFootprintRect(), MODULE::GetFpPadsLocalBbox(), getSheetBbox(), LIB_PART::GetUnitBoundingBox(), ARC::HitTest(), GERBVIEW_SELECTION::ViewBBox(), 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 653 of file base_struct.cpp.

654 {
655  if( !m_init )
656  {
657  m_Pos = aPoint;
658  m_Size = wxSize( 0, 0 );
659  m_init = true;
660  return;
661  }
662 
663  Normalize(); // ensure width and height >= 0
664 
665  wxPoint end = GetEnd();
666  // Change origin and size in order to contain the given rect
667  m_Pos.x = std::min( m_Pos.x, aPoint.x );
668  m_Pos.y = std::min( m_Pos.y, aPoint.y );
669  end.x = std::max( end.x, aPoint.x );
670  end.y = std::max( end.y, aPoint.y );
671  SetEnd( end );
672 }
const wxPoint GetEnd() const
Definition: eda_rect.h:116
wxSize m_Size
Definition: eda_rect.h:48
void SetEnd(int x, int y)
Definition: eda_rect.h:192
void Normalize()
Function Normalize ensures that the height ant width are positive.
bool m_init
Definition: eda_rect.h:49
wxPoint m_Pos
Definition: eda_rect.h:47

References GetEnd(), m_init, m_Pos, m_Size, Normalize(), SetEnd(), wxPoint::x, and wxPoint::y.

◆ 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 284 of file base_struct.cpp.

285 {
286  m_Pos += aMoveVector;
287 }
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos.

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

◆ Normalize()

◆ Offset() [1/2]

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

Definition at line 157 of file eda_rect.h.

158  {
159  m_Pos.x += dx;
160  m_Pos.y += dy;
161  }
wxPoint m_Pos
Definition: eda_rect.h:47

References m_Pos, wxPoint::x, and wxPoint::y.

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

◆ Offset() [2/2]

void EDA_RECT::Offset ( const wxPoint offset)
inline

Definition at line 163 of file eda_rect.h.

164  {
165  m_Pos += offset;
166  }
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 293 of file eda_rect.h.

294  {
295  EDA_RECT rect( m_Pos, m_Size );
296  rect.Normalize();
297  return BOX2I( rect.GetOrigin(), rect.GetSize() );
298  }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:521
wxSize m_Size
Definition: eda_rect.h:48
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 281 of file eda_rect.h.

282  {
283  EDA_RECT rect( m_Pos, m_Size );
284  rect.Normalize();
285  return wxRect( rect.m_Pos, rect.m_Size );
286  }
wxSize m_Size
Definition: eda_rect.h:48
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 209 of file eda_rect.h.

210  {
211  m_Pos.y = -m_Pos.y;
212  m_Size.y = -m_Size.y;
213  Normalize();
214  }
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, Normalize(), and wxPoint::y.

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

◆ SetEnd() [1/2]

◆ SetEnd() [2/2]

void EDA_RECT::SetEnd ( const wxPoint pos)
inline

Definition at line 198 of file eda_rect.h.

199  {
200  m_Size.x = pos.x - m_Pos.x;
201  m_Size.y = pos.y - m_Pos.y;
202  m_init = true;
203  }
wxSize m_Size
Definition: eda_rect.h:48
bool m_init
Definition: eda_rect.h:49
wxPoint m_Pos
Definition: eda_rect.h:47

References m_init, m_Pos, m_Size, wxPoint::x, and wxPoint::y.

◆ 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 137 of file eda_rect.h.

138  {
139  m_Pos.x = x;
140  m_Pos.y = y;
141  m_init = true;
142  }
bool m_init
Definition: eda_rect.h:49
wxPoint m_Pos
Definition: eda_rect.h:47

References m_init, m_Pos, wxPoint::x, and wxPoint::y.

◆ SetSize() [1/2]

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

Definition at line 144 of file eda_rect.h.

145  {
146  m_Size = size;
147  m_init = true;
148  }
wxSize m_Size
Definition: eda_rect.h:48
bool m_init
Definition: eda_rect.h:49

References m_init, and m_Size.

Referenced by WS_DRAW_ITEM_BITMAP::GetBoundingBox(), EDA_TEXT::GetTextBox(), and DIALOG_SHIM::ResetSize().

◆ SetSize() [2/2]

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

Definition at line 150 of file eda_rect.h.

151  {
152  m_Size.x = w;
153  m_Size.y = h;
154  m_init = true;
155  }
wxSize m_Size
Definition: eda_rect.h:48
bool m_init
Definition: eda_rect.h:49

References m_init, and m_Size.

◆ SetWidth()

void EDA_RECT::SetWidth ( int  val)
inline

◆ SetX()

void EDA_RECT::SetX ( int  val)
inline

◆ SetY()

void EDA_RECT::SetY ( int  val)
inline

Member Data Documentation

◆ m_init

bool EDA_RECT::m_init
private

◆ m_Pos

◆ m_Size


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