KiCad PCB EDA Suite
BOX2< Vec > Class Template Reference

A 2D bounding box built on top of an origin point and size vector. More...

#include <box2.h>

Public Types

typedef Vec::coord_type coord_type
 
typedef Vec::extended_type ecoord_type
 
typedef std::numeric_limits< coord_typecoord_limits
 

Public Member Functions

 BOX2 ()
 
 BOX2 (const Vec &aPos, const Vec &aSize=Vec(0, 0))
 
void SetMaximum ()
 
Vec Centre () const
 
template<class Container >
void Compute (const Container &aPointList)
 Compute the bounding box from a given list of points. More...
 
void Move (const Vec &aMoveVector)
 Move the rectangle by the aMoveVector. More...
 
BOX2< Vec > & Normalize ()
 Ensure that the height ant width are positive. More...
 
bool Contains (const Vec &aPoint) const
 
bool Contains (coord_type x, coord_type y) const
 
bool Contains (const BOX2< Vec > &aRect) const
 
const Vec & GetSize () const
 
coord_type GetX () const
 
coord_type GetY () const
 
const Vec & GetOrigin () const
 
const Vec & GetPosition () const
 
const Vec GetEnd () const
 
coord_type GetWidth () const
 
coord_type GetHeight () const
 
coord_type GetRight () const
 
coord_type GetBottom () const
 
coord_type GetLeft () const
 
coord_type GetTop () const
 
void MoveTopTo (coord_type aTop)
 
void MoveBottomTo (coord_type aBottom)
 
void MoveLeftTo (coord_type aLeft)
 
void MoveRightTo (coord_type aRight)
 
void SetOrigin (const Vec &pos)
 
void SetOrigin (coord_type x, coord_type y)
 
void SetSize (const Vec &size)
 
void SetSize (coord_type w, coord_type h)
 
void Offset (coord_type dx, coord_type dy)
 
void Offset (const Vec &offset)
 
void SetX (coord_type val)
 
void SetY (coord_type val)
 
void SetWidth (coord_type val)
 
void SetHeight (coord_type val)
 
void SetEnd (coord_type x, coord_type y)
 
void SetEnd (const Vec &pos)
 
bool Intersects (const BOX2< Vec > &aRect) const
 
BOX2< Vec > Intersect (const BOX2< Vec > &aRect)
 Return the intersection of this with another rectangle. More...
 
const std::string Format () const
 
BOX2< Vec > & Inflate (coord_type dx, coord_type dy)
 Inflates the rectangle horizontally by dx and vertically by dy. More...
 
BOX2< Vec > & Inflate (int aDelta)
 Inflate the rectangle horizontally and vertically by aDelta. More...
 
BOX2< Vec > & Merge (const BOX2< Vec > &aRect)
 Modify the position and size of the rectangle in order to contain aRect. More...
 
BOX2< Vec > & Merge (const Vec &aPoint)
 Modify the position and size of the rectangle in order to contain the given point. More...
 
ecoord_type GetArea () const
 Return the area of the rectangle. More...
 
ecoord_type Diagonal () const
 Return the length of the diagonal of the rectangle. More...
 
ecoord_type SquaredDistance (const Vec &aP) const
 
ecoord_type Distance (const Vec &aP) const
 
ecoord_type SquaredDistance (const BOX2< Vec > &aBox) const
 Return the square of the minimum distance between self and box aBox. More...
 
ecoord_type Distance (const BOX2< Vec > &aBox) const
 Return the minimum distance between self and aBox. More...
 
bool operator== (const BOX2< Vec > &aOther) const
 
bool operator!= (const BOX2< Vec > &aOther) const
 

Private Attributes

Vec m_Pos
 
Vec m_Size
 

Detailed Description

template<class Vec>
class BOX2< Vec >

A 2D bounding box built on top of an origin point and size vector.

Definition at line 41 of file box2.h.

Member Typedef Documentation

◆ coord_limits

template<class Vec>
typedef std::numeric_limits<coord_type> BOX2< Vec >::coord_limits

Definition at line 46 of file box2.h.

◆ coord_type

template<class Vec>
typedef Vec::coord_type BOX2< Vec >::coord_type

Definition at line 44 of file box2.h.

◆ ecoord_type

template<class Vec>
typedef Vec::extended_type BOX2< Vec >::ecoord_type

Definition at line 45 of file box2.h.

Constructor & Destructor Documentation

◆ BOX2() [1/2]

template<class Vec>
BOX2< Vec >::BOX2 ( )
inline

Definition at line 48 of file box2.h.

48 {};

◆ BOX2() [2/2]

template<class Vec>
BOX2< Vec >::BOX2 ( const Vec &  aPos,
const Vec &  aSize = Vec(0, 0) 
)
inline

Definition at line 50 of file box2.h.

50  :
51  m_Pos( aPos ),
52  m_Size( aSize )
53  {
54  Normalize();
55  }
BOX2< Vec > & Normalize()
Ensure that the height ant width are positive.
Definition: box2.h:112
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

Member Function Documentation

◆ Centre()

◆ Compute()

template<class Vec>
template<class Container >
void BOX2< Vec >::Compute ( const Container &  aPointList)
inline

Compute the bounding box from a given list of points.

Parameters
aPointListis the list points of the object.

Definition at line 75 of file box2.h.

76  {
77  Vec vmin, vmax;
78 
79  typename Container::const_iterator i;
80 
81  if( !aPointList.size() )
82  return;
83 
84  vmin = vmax = aPointList[0];
85 
86  for( i = aPointList.begin(); i != aPointList.end(); ++i )
87  {
88  Vec p( *i );
89  vmin.x = std::min( vmin.x, p.x );
90  vmin.y = std::min( vmin.y, p.y );
91  vmax.x = std::max( vmax.x, p.x );
92  vmax.y = std::max( vmax.y, p.y );
93  }
94 
95  SetOrigin( vmin );
96  SetSize( vmax - vmin );
97  }
void SetSize(const Vec &size)
Definition: box2.h:195
void SetOrigin(const Vec &pos)
Definition: box2.h:193

Referenced by SHAPE_LINE_CHAIN::BBox(), SHAPE_LINE_CHAIN::GenerateBBoxCache(), and SHAPE_ARC::update_bbox().

◆ Contains() [1/3]

template<class Vec>
bool BOX2< Vec >::Contains ( const Vec &  aPoint) const
inline
Parameters
aPointis the point to test.
Returns
true if aPoint is inside the boundary box. A point on a edge is seen as inside.

Definition at line 134 of file box2.h.

135  {
136  Vec rel_pos = aPoint - m_Pos;
137  Vec size = m_Size;
138 
139  if( size.x < 0 )
140  {
141  size.x = -size.x;
142  rel_pos.x += size.x;
143  }
144 
145  if( size.y < 0 )
146  {
147  size.y = -size.y;
148  rel_pos.y += size.y;
149  }
150 
151  return ( rel_pos.x >= 0 ) && ( rel_pos.y >= 0 ) && ( rel_pos.y <= size.y) &&
152  ( rel_pos.x <= size.x);
153  }
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

Referenced by LABEL_MANAGER::boxMtv(), PNS::AREA_CONSTRAINT::Check(), CN_VISITOR::checkZoneZoneConnection(), BOX2< VECTOR2I >::Contains(), POLY_GRID_PARTITION::containsPoint(), drawBacksideTicks(), drawTicksAlongLine(), EDA_DRAW_FRAME::FocusOnLocation(), PNS::NODE::QueryJoints(), PL_SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectionContains(), KIGFX::VIEW::SetCenter(), KIGFX::WX_VIEW_CONTROLS::SetCrossHairCursorPosition(), and KIGFX::WX_VIEW_CONTROLS::WarpCursor().

◆ Contains() [2/3]

template<class Vec>
bool BOX2< Vec >::Contains ( coord_type  x,
coord_type  y 
) const
inline
Parameters
xis the x coordinate of the point to test.
yis 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 160 of file box2.h.

160 { return Contains( Vec( x, y ) ); }
bool Contains(const Vec &aPoint) const
Definition: box2.h:134

Referenced by BOX2< VECTOR2I >::Contains().

◆ Contains() [3/3]

template<class Vec>
bool BOX2< Vec >::Contains ( const BOX2< Vec > &  aRect) const
inline
Parameters
aRectis the the area to test.
Returns
true if aRect is contained. A common edge is seen as contained.

Definition at line 167 of file box2.h.

168  {
169  return Contains( aRect.GetOrigin() ) && Contains( aRect.GetEnd() );
170  }
const Vec GetEnd() const
Definition: box2.h:178
bool Contains(const Vec &aPoint) const
Definition: box2.h:134
const Vec & GetOrigin() const
Definition: box2.h:176

◆ Diagonal()

template<class Vec>
ecoord_type BOX2< Vec >::Diagonal ( ) const
inline

Return the length of the diagonal of the rectangle.

Returns
The length of the rectangle diagonal.

Definition at line 415 of file box2.h.

416  {
417  return m_Size.EuclideanNorm();
418  }
Vec m_Size
Definition: box2.h:502

◆ Distance() [1/2]

template<class Vec>
ecoord_type BOX2< Vec >::Distance ( const Vec &  aP) const
inline

Definition at line 431 of file box2.h.

432  {
433  return sqrt( SquaredDistance( aP ) );
434  }
ecoord_type SquaredDistance(const Vec &aP) const
Definition: box2.h:420

Referenced by SHAPE_INDEX_LIST< T, >::query_iterator::next().

◆ Distance() [2/2]

template<class Vec>
ecoord_type BOX2< Vec >::Distance ( const BOX2< Vec > &  aBox) const
inline

Return the minimum distance between self and aBox.

Parameters
aBoxis the other box to get the distance from.
Returns
The distance from aBox.

Definition at line 477 of file box2.h.

478  {
479  return sqrt( SquaredDistance( aBox ) );
480  }
ecoord_type SquaredDistance(const Vec &aP) const
Definition: box2.h:420

◆ Format()

template<class Vec>
const std::string BOX2< Vec >::Format ( ) const
inline

Definition at line 268 of file box2.h.

269  {
270  std::stringstream ss;
271 
272  ss << "( box corner " << m_Pos.Format() << " w " << m_Size.x << " h " << m_Size.y << " )";
273 
274  return ss.str();
275  }
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

◆ GetArea()

template<class Vec>
ecoord_type BOX2< Vec >::GetArea ( ) const
inline

Return the area of the rectangle.

Returns
The area of the rectangle.

Definition at line 405 of file box2.h.

406  {
407  return (ecoord_type) GetWidth() * (ecoord_type) GetHeight();
408  }
Vec::extended_type ecoord_type
Definition: box2.h:45
coord_type GetWidth() const
Definition: box2.h:180
coord_type GetHeight() const
Definition: box2.h:181

◆ GetBottom()

◆ GetEnd()

◆ GetHeight()

◆ GetLeft()

template<class Vec>
coord_type BOX2< Vec >::GetLeft ( ) const
inline

◆ GetOrigin()

◆ GetPosition()

◆ GetRight()

◆ GetSize()

◆ GetTop()

template<class Vec>
coord_type BOX2< Vec >::GetTop ( ) const
inline

◆ GetWidth()

◆ GetX()

◆ GetY()

◆ Inflate() [1/2]

template<class Vec>
BOX2<Vec>& BOX2< Vec >::Inflate ( coord_type  dx,
coord_type  dy 
)
inline

Inflates the rectangle horizontally by dx and vertically by dy.

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

Definition at line 281 of file box2.h.

282  {
283  if( m_Size.x >= 0 )
284  {
285  if( m_Size.x < -2 * dx )
286  {
287  // Don't allow deflate to eat more width than we have,
288  m_Pos.x += m_Size.x / 2;
289  m_Size.x = 0;
290  }
291  else
292  {
293  // The inflate is valid.
294  m_Pos.x -= dx;
295  m_Size.x += 2 * dx;
296  }
297  }
298  else // size.x < 0:
299  {
300  if( m_Size.x > -2 * dx )
301  {
302  // Don't allow deflate to eat more width than we have,
303  m_Pos.x -= m_Size.x / 2;
304  m_Size.x = 0;
305  }
306  else
307  {
308  // The inflate is valid.
309  m_Pos.x += dx;
310  m_Size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0
311  }
312  }
313 
314  if( m_Size.y >= 0 )
315  {
316  if( m_Size.y < -2 * dy )
317  {
318  // Don't allow deflate to eat more height than we have,
319  m_Pos.y += m_Size.y / 2;
320  m_Size.y = 0;
321  }
322  else
323  {
324  // The inflate is valid.
325  m_Pos.y -= dy;
326  m_Size.y += 2 * dy;
327  }
328  }
329  else // size.y < 0:
330  {
331  if( m_Size.y > 2 * dy )
332  {
333  // Don't allow deflate to eat more height than we have,
334  m_Pos.y -= m_Size.y / 2;
335  m_Size.y = 0;
336  }
337  else
338  {
339  // The inflate is valid.
340  m_Pos.y += dy;
341  m_Size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0
342  }
343  }
344 
345  return *this;
346  }
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

Referenced by SHAPE_SEGMENT::BBox(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::BBox(), SHAPE_ARC::BBox(), SHAPE_LINE_CHAIN::BBox(), SHAPE_POLY_SET::BBox(), ZONE_FILLER::buildThermalSpokes(), PNS::LINE::ChangedArea(), DRC_RTREE::CheckColliding(), drawBacksideTicks(), drawTicksAlongLine(), DRAWING_TOOL::DrawVia(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), EDA_DRAW_FRAME::FocusOnLocation(), SHAPE_LINE_CHAIN::GenerateBBoxCache(), PCB_DIMENSION_BASE::GetBoundingBox(), FOOTPRINT_EDIT_FRAME::GetDocumentExtents(), BOX2< VECTOR2I >::Inflate(), DRC_RTREE::Insert(), SHAPE_INDEX< T >::Query(), DRC_RTREE::QueryCollidingPairs(), DIALOG_PAD_PROPERTIES::redraw(), PL_SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectionContains(), PNS_LOG_VIEWER_FRAME::SetLogFile(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances(), ROUTER_PREVIEW_ITEM::ViewBBox(), PCB_TRACK::ViewBBox(), and PCB_SHAPE::ViewBBox().

◆ Inflate() [2/2]

template<class Vec>
BOX2<Vec>& BOX2< Vec >::Inflate ( int  aDelta)
inline

Inflate the rectangle horizontally and vertically by aDelta.

If aDelta is negative the rectangle is deflated.

Definition at line 352 of file box2.h.

353  {
354  Inflate( aDelta, aDelta );
355  return *this;
356  }
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:281

◆ Intersect()

template<class Vec>
BOX2<Vec> BOX2< Vec >::Intersect ( const BOX2< Vec > &  aRect)
inline

Return the intersection of this with another rectangle.

Definition at line 248 of file box2.h.

249  {
250  BOX2<Vec> me( *this );
251  BOX2<Vec> rect( aRect );
252  me.Normalize(); // ensure size is >= 0
253  rect.Normalize(); // ensure size is >= 0
254 
255  Vec topLeft, bottomRight;
256 
257  topLeft.x = std::max( me.m_Pos.x, rect.m_Pos.x );
258  bottomRight.x = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
259  topLeft.y = std::max( me.m_Pos.y, rect.m_Pos.y );
260  bottomRight.y = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
261 
262  if ( topLeft.x < bottomRight.x && topLeft.y < bottomRight.y )
263  return BOX2<Vec>( topLeft, bottomRight - topLeft );
264  else
265  return BOX2<Vec>( Vec( 0, 0 ), Vec( 0, 0 ) );
266  }
A 2D bounding box built on top of an origin point and size vector.
Definition: box2.h:41

Referenced by KIGFX::VIEW::SetCenter().

◆ Intersects()

template<class Vec>
bool BOX2< Vec >::Intersects ( const BOX2< Vec > &  aRect) const
inline
Returns
true if the argument rectangle intersects this rectangle. (i.e. if the 2 rectangles have at least a common point)

Definition at line 217 of file box2.h.

218  {
219  // this logic taken from wxWidgets' geometry.cpp file:
220  bool rc;
221 
222  BOX2<Vec> me( *this );
223  BOX2<Vec> rect( aRect );
224  me.Normalize(); // ensure size is >= 0
225  rect.Normalize(); // ensure size is >= 0
226 
227  // calculate the left common area coordinate:
228  int left = std::max( me.m_Pos.x, rect.m_Pos.x );
229  // calculate the right common area coordinate:
230  int right = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
231  // calculate the upper common area coordinate:
232  int top = std::max( me.m_Pos.y, aRect.m_Pos.y );
233  // calculate the lower common area coordinate:
234  int bottom = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
235 
236  // if a common area exists, it must have a positive (null accepted) size
237  if( left <= right && top <= bottom )
238  rc = true;
239  else
240  rc = false;
241 
242  return rc;
243  }
A 2D bounding box built on top of an origin point and size vector.
Definition: box2.h:41
Vec m_Pos
Definition: box2.h:501

Referenced by LABEL_MANAGER::boxMtv(), ZONE_FILLER::buildThermalSpokes(), CN_VISITOR::checkZoneItemConnection(), SHAPE_LINE_CHAIN::Intersect(), FABMASTER::loadZones(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances(), and BOARD::TestZoneIntersection().

◆ Merge() [1/2]

template<class Vec>
BOX2<Vec>& BOX2< Vec >::Merge ( const BOX2< Vec > &  aRect)
inline

Modify the position and size of the rectangle in order to contain aRect.

Parameters
aRectis the rectangle to merge with this rectangle.

Definition at line 363 of file box2.h.

364  {
365  Normalize(); // ensure width and height >= 0
366  BOX2<Vec> rect = aRect;
367  rect.Normalize(); // ensure width and height >= 0
368  Vec end = GetEnd();
369  Vec rect_end = rect.GetEnd();
370 
371  // Change origin and size in order to contain the given rect
372  m_Pos.x = std::min( m_Pos.x, rect.m_Pos.x );
373  m_Pos.y = std::min( m_Pos.y, rect.m_Pos.y );
374  end.x = std::max( end.x, rect_end.x );
375  end.y = std::max( end.y, rect_end.y );
376  SetEnd( end );
377  return *this;
378  }
const Vec GetEnd() const
Definition: box2.h:178
A 2D bounding box built on top of an origin point and size vector.
Definition: box2.h:41
BOX2< Vec > & Normalize()
Ensure that the height ant width are positive.
Definition: box2.h:112
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:207
Vec m_Pos
Definition: box2.h:501

Referenced by SHAPE_LINE_CHAIN::Append(), HPGL_PLOTTER::Arc(), SHAPE_COMPOUND::BBox(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::BBox(), SHAPE_POLY_SET::BBox(), SHAPE_POLY_SET::BBoxFromCaches(), PNS::ARC::ChangedArea(), PNS::VIA::ChangedArea(), HPGL_PLOTTER::Circle(), HPGL_PLOTTER::EndPlot(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), PNS::extendBox(), DIALOG_BOARD_STATISTICS::getDataFromPCB(), PNS_TEST_DEBUG_DECORATOR::GetStageExtents(), HPGL_PLOTTER::PenTo(), HPGL_PLOTTER::Rect(), FOOTPRINT_PREVIEW_PANEL::renderFootprint(), KIGFX::VIEW_GROUP::ViewBBox(), PCB_DIMENSION_BASE::ViewBBox(), and EDIT_POINTS::ViewBBox().

◆ Merge() [2/2]

template<class Vec>
BOX2<Vec>& BOX2< Vec >::Merge ( const Vec &  aPoint)
inline

Modify the position and size of the rectangle in order to contain the given point.

Parameters
aPointis the point to merge with the rectangle.

Definition at line 385 of file box2.h.

386  {
387  Normalize(); // ensure width and height >= 0
388 
389  Vec end = GetEnd();
390 
391  // Change origin and size in order to contain the given rectangle.
392  m_Pos.x = std::min( m_Pos.x, aPoint.x );
393  m_Pos.y = std::min( m_Pos.y, aPoint.y );
394  end.x = std::max( end.x, aPoint.x );
395  end.y = std::max( end.y, aPoint.y );
396  SetEnd( end );
397  return *this;
398  }
const Vec GetEnd() const
Definition: box2.h:178
BOX2< Vec > & Normalize()
Ensure that the height ant width are positive.
Definition: box2.h:112
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:207
Vec m_Pos
Definition: box2.h:501

◆ Move()

template<class Vec>
void BOX2< Vec >::Move ( const Vec &  aMoveVector)
inline

Move the rectangle by the aMoveVector.

Parameters
aMoveVectoris a point that is the value to move this rectangle.

Definition at line 104 of file box2.h.

105  {
106  m_Pos += aMoveVector;
107  }
Vec m_Pos
Definition: box2.h:501

Referenced by LABEL_MANAGER::boxMtv(), and DIALOG_PAD_PROPERTIES::redraw().

◆ MoveBottomTo()

template<class Vec>
void BOX2< Vec >::MoveBottomTo ( coord_type  aBottom)
inline

Definition at line 189 of file box2.h.

189 { m_Size.y = aBottom - m_Pos.y; }
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

◆ MoveLeftTo()

template<class Vec>
void BOX2< Vec >::MoveLeftTo ( coord_type  aLeft)
inline

Definition at line 190 of file box2.h.

190 { m_Pos.x = aLeft; }
Vec m_Pos
Definition: box2.h:501

◆ MoveRightTo()

template<class Vec>
void BOX2< Vec >::MoveRightTo ( coord_type  aRight)
inline

Definition at line 191 of file box2.h.

191 { m_Size.x = aRight - m_Pos.x; }
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

◆ MoveTopTo()

template<class Vec>
void BOX2< Vec >::MoveTopTo ( coord_type  aTop)
inline

Definition at line 188 of file box2.h.

188 { m_Pos.y = aTop; }
Vec m_Pos
Definition: box2.h:501

◆ Normalize()

template<class Vec>
BOX2<Vec>& BOX2< Vec >::Normalize ( )
inline

Ensure that the height ant width are positive.

Definition at line 112 of file box2.h.

113  {
114  if( m_Size.y < 0 )
115  {
116  m_Size.y = -m_Size.y;
117  m_Pos.y -= m_Size.y;
118  }
119 
120  if( m_Size.x < 0 )
121  {
122  m_Size.x = -m_Size.x;
123  m_Pos.x -= m_Size.x;
124  }
125 
126  return *this;
127  }
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

Referenced by BOX2< VECTOR2I >::BOX2(), LABEL_MANAGER::boxMtv(), PNS::ConvexHull(), KIGFX::VIEW::GetViewport(), BOX2< VECTOR2I >::Intersect(), BOX2< VECTOR2I >::Intersects(), BOX2< VECTOR2I >::Merge(), SVG_PLOTTER::Rect(), KIGFX::VIEW::Redraw(), and KIGFX::PREVIEW::SELECTION_AREA::ViewBBox().

◆ Offset() [1/2]

template<class Vec>
void BOX2< Vec >::Offset ( coord_type  dx,
coord_type  dy 
)
inline

Definition at line 197 of file box2.h.

197 { m_Pos.x += dx; m_Pos.y += dy; }
Vec m_Pos
Definition: box2.h:501

◆ Offset() [2/2]

template<class Vec>
void BOX2< Vec >::Offset ( const Vec &  offset)
inline

Definition at line 198 of file box2.h.

199  {
200  m_Pos.x += offset.x; m_Pos.y += offset.y;
201  }
Vec m_Pos
Definition: box2.h:501

◆ operator!=()

template<class Vec>
bool BOX2< Vec >::operator!= ( const BOX2< Vec > &  aOther) const
inline

Definition at line 491 of file box2.h.

492  {
493  auto t1 ( *this );
494  auto t2 ( aOther );
495  t1.Normalize();
496  t2.Normalize();
497  return ( t1.m_Pos != t2.m_Pos || t1.m_Size != t2.m_Size );
498  }

◆ operator==()

template<class Vec>
bool BOX2< Vec >::operator== ( const BOX2< Vec > &  aOther) const
inline

Definition at line 482 of file box2.h.

483  {
484  auto t1 ( *this );
485  auto t2 ( aOther );
486  t1.Normalize();
487  t2.Normalize();
488  return ( t1.m_Pos == t2.m_Pos && t1.m_Size == t2.m_Size );
489  }

◆ SetEnd() [1/2]

template<class Vec>
void BOX2< Vec >::SetEnd ( coord_type  x,
coord_type  y 
)
inline

◆ SetEnd() [2/2]

template<class Vec>
void BOX2< Vec >::SetEnd ( const Vec &  pos)
inline

Definition at line 208 of file box2.h.

209  {
210  m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
211  }
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

◆ SetHeight()

template<class Vec>
void BOX2< Vec >::SetHeight ( coord_type  val)
inline

Definition at line 206 of file box2.h.

206 { m_Size.y = val; }
Vec m_Size
Definition: box2.h:502

Referenced by PNS_LOG_VIEWER_FRAME::SetLogFile().

◆ SetMaximum()

◆ SetOrigin() [1/2]

◆ SetOrigin() [2/2]

template<class Vec>
void BOX2< Vec >::SetOrigin ( coord_type  x,
coord_type  y 
)
inline

Definition at line 194 of file box2.h.

194 { m_Pos.x = x; m_Pos.y = y; }
Vec m_Pos
Definition: box2.h:501

◆ SetSize() [1/2]

◆ SetSize() [2/2]

template<class Vec>
void BOX2< Vec >::SetSize ( coord_type  w,
coord_type  h 
)
inline

Definition at line 196 of file box2.h.

196 { m_Size.x = w; m_Size.y = h; }
Vec m_Size
Definition: box2.h:502

◆ SetWidth()

template<class Vec>
void BOX2< Vec >::SetWidth ( coord_type  val)
inline

Definition at line 205 of file box2.h.

205 { m_Size.x = val; }
Vec m_Size
Definition: box2.h:502

Referenced by PNS_LOG_VIEWER_FRAME::SetLogFile().

◆ SetX()

template<class Vec>
void BOX2< Vec >::SetX ( coord_type  val)
inline

Definition at line 203 of file box2.h.

203 { m_Pos.x = val; }
Vec m_Pos
Definition: box2.h:501

◆ SetY()

template<class Vec>
void BOX2< Vec >::SetY ( coord_type  val)
inline

Definition at line 204 of file box2.h.

204 { m_Pos.y = val; }
Vec m_Pos
Definition: box2.h:501

◆ SquaredDistance() [1/2]

template<class Vec>
ecoord_type BOX2< Vec >::SquaredDistance ( const Vec &  aP) const
inline

Definition at line 420 of file box2.h.

421  {
422  ecoord_type x2 = m_Pos.x + m_Size.x;
423  ecoord_type y2 = m_Pos.y + m_Size.y;
424  ecoord_type xdiff = std::max( aP.x < m_Pos.x ? m_Pos.x - aP.x : m_Pos.x - x2,
425  (ecoord_type) 0 );
426  ecoord_type ydiff = std::max( aP.y < m_Pos.y ? m_Pos.y - aP.y : m_Pos.y - y2,
427  (ecoord_type) 0 );
428  return xdiff * xdiff + ydiff * ydiff;
429  }
Vec::extended_type ecoord_type
Definition: box2.h:45
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

Referenced by BOX2< VECTOR2I >::Distance(), and SHAPE_INDEX_LIST< PNS::ITEM * >::Query().

◆ SquaredDistance() [2/2]

template<class Vec>
ecoord_type BOX2< Vec >::SquaredDistance ( const BOX2< Vec > &  aBox) const
inline

Return the square of the minimum distance between self and box aBox.

Parameters
aBoxis the other box.
Returns
The distance squared from aBox.

Definition at line 442 of file box2.h.

443  {
444  ecoord_type s = 0;
445 
446  if( aBox.m_Pos.x + aBox.m_Size.x < m_Pos.x )
447  {
448  ecoord_type d = aBox.m_Pos.x + aBox.m_Size.x - m_Pos.x;
449  s += d * d;
450  }
451  else if( aBox.m_Pos.x > m_Pos.x + m_Size.x )
452  {
453  ecoord_type d = aBox.m_Pos.x - m_Size.x - m_Pos.x;
454  s += d * d;
455  }
456 
457  if( aBox.m_Pos.y + aBox.m_Size.y < m_Pos.y )
458  {
459  ecoord_type d = aBox.m_Pos.y + aBox.m_Size.y - m_Pos.y;
460  s += d * d;
461  }
462  else if( aBox.m_Pos.y > m_Pos.y + m_Size.y )
463  {
464  ecoord_type d = aBox.m_Pos.y - m_Size.y - m_Pos.y;
465  s += d * d;
466  }
467 
468  return s;
469  }
Vec::extended_type ecoord_type
Definition: box2.h:45
Vec m_Pos
Definition: box2.h:501
Vec m_Size
Definition: box2.h:502

Member Data Documentation

◆ m_Pos

◆ m_Size


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