KiCad PCB EDA Suite
BOX2< Vec > Class Template Reference

BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated class Vec. 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)
 
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)
 Function Move moves the rectangle by the aMoveVector. More...
 
BOX2< Vec > & Normalize ()
 Function Normalize ensures that the height ant width are positive. More...
 
bool Contains (const Vec &aPoint) const
 Function Contains. More...
 
bool Contains (coord_type x, coord_type y) const
 Function Contains. More...
 
bool Contains (const BOX2< Vec > &aRect) const
 Function Contains. More...
 
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
 Function Intersects. More...
 
BOX2< Vec > Intersect (const BOX2< Vec > &aRect)
 Function Intersect Returns the intersection of this with another rectangle. More...
 
const std::string Format () const
 
BOX2< Vec > & Inflate (coord_type dx, coord_type dy)
 Function Inflate inflates the rectangle horizontally by dx and vertically by dy. More...
 
BOX2< Vec > & Inflate (int aDelta)
 Function Inflate inflates the rectangle horizontally and vertically by aDelta. More...
 
BOX2< Vec > & Merge (const BOX2< Vec > &aRect)
 Function Merge modifies the position and size of the rectangle in order to contain aRect. More...
 
BOX2< Vec > & Merge (const Vec &aPoint)
 Function Merge modifies the position and size of the rectangle in order to contain the given point. More...
 
ecoord_type GetArea () const
 Function GetArea returns the area of the rectangle. More...
 
ecoord_type Diagonal () const
 Function GetArea returns 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
 Function SquaredDistance returns the square of the minimum distance between self and box aBox. More...
 
ecoord_type Distance (const BOX2< Vec > &aBox) const
 Function Distance returns the minimum distance between self and box 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 >

BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated class Vec.

Definition at line 42 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 51 of file box2.h.

◆ coord_type

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

Definition at line 49 of file box2.h.

◆ ecoord_type

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

Definition at line 50 of file box2.h.

Constructor & Destructor Documentation

◆ BOX2() [1/2]

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

Definition at line 53 of file box2.h.

53 {};

◆ BOX2() [2/2]

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

Definition at line 55 of file box2.h.

55  :
56  m_Pos( aPos ),
57  m_Size( aSize )
58  {
59  Normalize();
60  }
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: box2.h:128
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

Member Function Documentation

◆ Centre()

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

◆ 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 90 of file box2.h.

91  {
92  Vec vmin, vmax;
93 
94  typename Container::const_iterator i;
95 
96  if( !aPointList.size() )
97  return;
98 
99  vmin = vmax = aPointList[0];
100 
101  for( i = aPointList.begin(); i != aPointList.end(); ++i )
102  {
103  Vec p( *i );
104  vmin.x = std::min( vmin.x, p.x );
105  vmin.y = std::min( vmin.y, p.y );
106  vmax.x = std::max( vmax.x, p.x );
107  vmax.y = std::max( vmax.y, p.y );
108  }
109 
110  SetOrigin( vmin );
111  SetSize( vmax - vmin );
112  }
void SetSize(const Vec &size)
Definition: box2.h:211
void SetOrigin(const Vec &pos)
Definition: box2.h:209

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

◆ Contains() [1/3]

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

Function Contains.

Parameters
aPoint= 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 150 of file box2.h.

151  {
152  Vec rel_pos = aPoint - m_Pos;
153  Vec size = m_Size;
154 
155  if( size.x < 0 )
156  {
157  size.x = -size.x;
158  rel_pos.x += size.x;
159  }
160 
161  if( size.y < 0 )
162  {
163  size.y = -size.y;
164  rel_pos.y += size.y;
165  }
166 
167  return ( rel_pos.x >= 0 ) && ( rel_pos.y >= 0 ) && ( rel_pos.y <= size.y) && ( rel_pos.x <= size.x);
168  }
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

Referenced by PNS::LINE_RESTRICTIONS::Build(), BOX2< VECTOR2I >::Contains(), POLY_GRID_PARTITION::containsPoint(), SHAPE_LINE_CHAIN::PointInside(), EE_SELECTION_TOOL::selectionContains(), 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

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 176 of file box2.h.

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

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

◆ Contains() [3/3]

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

Function Contains.

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

Definition at line 183 of file box2.h.

184  {
185  return Contains( aRect.GetOrigin() ) && Contains( aRect.GetEnd() );
186  }
const Vec GetEnd() const
Definition: box2.h:194
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:150
const Vec & GetOrigin() const
Definition: box2.h:192

◆ Diagonal()

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

Function GetArea returns the length of the diagonal of the rectangle.

Returns
The area of the diagonal.

Definition at line 436 of file box2.h.

437  {
438  return m_Size.EuclideanNorm();
439  }
Vec m_Size
Definition: box2.h:46

◆ Distance() [1/2]

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

Definition at line 450 of file box2.h.

451  {
452  return sqrt( SquaredDistance( aP ) );
453  }
ecoord_type SquaredDistance(const Vec &aP) const
Definition: box2.h:441

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

Function Distance returns the minimum distance between self and box aBox.

Parameters
aBoxthe other box
Returns
The distance

Definition at line 496 of file box2.h.

497  {
498  return sqrt( SquaredDistance( aBox ) );
499  }
ecoord_type SquaredDistance(const Vec &aP) const
Definition: box2.h:441

◆ Format()

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

Definition at line 287 of file box2.h.

288  {
289  std::stringstream ss;
290 
291  ss << "( box corner " << m_Pos.Format() << " w " << m_Size.x << " h " << m_Size.y << " )";
292 
293  return ss.str();
294  }
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

◆ GetArea()

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

Function GetArea returns the area of the rectangle.

Returns
The area of the rectangle.

Definition at line 426 of file box2.h.

427  {
428  return (ecoord_type) GetWidth() * (ecoord_type) GetHeight();
429  }
Vec::extended_type ecoord_type
Definition: box2.h:50
coord_type GetWidth() const
Definition: box2.h:196
coord_type GetHeight() const
Definition: box2.h:197

◆ GetBottom()

◆ GetEnd()

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

◆ 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

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 301 of file box2.h.

302  {
303  if( m_Size.x >= 0 )
304  {
305  if( m_Size.x < -2 * dx )
306  {
307  // Don't allow deflate to eat more width than we have,
308  m_Pos.x += m_Size.x / 2;
309  m_Size.x = 0;
310  }
311  else
312  {
313  // The inflate is valid.
314  m_Pos.x -= dx;
315  m_Size.x += 2 * dx;
316  }
317  }
318  else // size.x < 0:
319  {
320  if( m_Size.x > -2 * dx )
321  {
322  // Don't allow deflate to eat more width than we have,
323  m_Pos.x -= m_Size.x / 2;
324  m_Size.x = 0;
325  }
326  else
327  {
328  // The inflate is valid.
329  m_Pos.x += dx;
330  m_Size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0
331  }
332  }
333 
334  if( m_Size.y >= 0 )
335  {
336  if( m_Size.y < -2 * dy )
337  {
338  // Don't allow deflate to eat more height than we have,
339  m_Pos.y += m_Size.y / 2;
340  m_Size.y = 0;
341  }
342  else
343  {
344  // The inflate is valid.
345  m_Pos.y -= dy;
346  m_Size.y += 2 * dy;
347  }
348  }
349  else // size.y < 0:
350  {
351  if( m_Size.y > 2 * dy )
352  {
353  // Don't allow deflate to eat more height than we have,
354  m_Pos.y -= m_Size.y / 2;
355  m_Size.y = 0;
356  }
357  else
358  {
359  // The inflate is valid.
360  m_Pos.y += dy;
361  m_Size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0
362  }
363  }
364 
365  return *this;
366  }
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

Referenced by SHAPE_SEGMENT::BBox(), SHAPE_ARC::BBox(), SHAPE_LINE_CHAIN::BBox(), SHAPE_POLY_SET::BBox(), ZONE_FILLER::buildThermalSpokes(), PNS::LINE::ChangedArea(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), SHAPE_LINE_CHAIN::GenerateBBoxCache(), BOX2< VECTOR2I >::Inflate(), SHAPE_INDEX< T >::Query(), DIALOG_PAD_PROPERTIES::redraw(), EE_SELECTION_TOOL::selectionContains(), SELECTION_TOOL::selectionContains(), ROUTER_PREVIEW_ITEM::ViewBBox(), and TRACK::ViewBBox().

◆ Inflate() [2/2]

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

Function Inflate inflates the rectangle horizontally and vertically by aDelta.

If aDelta is negative the rectangle is deflated.

Definition at line 373 of file box2.h.

374  {
375  Inflate( aDelta, aDelta );
376  return *this;
377  }
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:301

◆ Intersect()

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

Function Intersect Returns the intersection of this with another rectangle.

Definition at line 267 of file box2.h.

268  {
269  BOX2<Vec> me( *this );
270  BOX2<Vec> rect( aRect );
271  me.Normalize(); // ensure size is >= 0
272  rect.Normalize(); // ensure size is >= 0
273 
274  Vec topLeft, bottomRight;
275 
276  topLeft.x = std::max( me.m_Pos.x, rect.m_Pos.x );
277  bottomRight.x = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
278  topLeft.y = std::max( me.m_Pos.y, rect.m_Pos.y );
279  bottomRight.y = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
280 
281  if ( topLeft.x < bottomRight.x && topLeft.y < bottomRight.y )
282  return BOX2<Vec>( topLeft, bottomRight - topLeft );
283  else
284  return BOX2<Vec>( Vec( 0, 0 ), Vec( 0, 0 ) );
285  }
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:42

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

◆ Intersects()

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

Function Intersects.

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 235 of file box2.h.

236  {
237  // this logic taken from wxWidgets' geometry.cpp file:
238  bool rc;
239 
240  BOX2<Vec> me( *this );
241  BOX2<Vec> rect( aRect );
242  me.Normalize(); // ensure size is >= 0
243  rect.Normalize(); // ensure size is >= 0
244 
245  // calculate the left common area coordinate:
246  int left = std::max( me.m_Pos.x, rect.m_Pos.x );
247  // calculate the right common area coordinate:
248  int right = std::min( me.m_Pos.x + me.m_Size.x, rect.m_Pos.x + rect.m_Size.x );
249  // calculate the upper common area coordinate:
250  int top = std::max( me.m_Pos.y, aRect.m_Pos.y );
251  // calculate the lower common area coordinate:
252  int bottom = std::min( me.m_Pos.y + me.m_Size.y, rect.m_Pos.y + rect.m_Size.y );
253 
254  // if a common area exists, it must have a positive (null accepted) size
255  if( left <= right && top <= bottom )
256  rc = true;
257  else
258  rc = false;
259 
260  return rc;
261  }
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:42
Vec m_Pos
Definition: box2.h:45

Referenced by ZONE_FILLER::buildThermalSpokes(), CN_VISITOR::checkZoneItemConnection(), BOARD::CombineAllAreasInNet(), SHAPE_LINE_CHAIN::Intersect(), and BOARD::TestAreaIntersection().

◆ Merge() [1/2]

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

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 385 of file box2.h.

386  {
387  Normalize(); // ensure width and height >= 0
388  BOX2<Vec> rect = aRect;
389  rect.Normalize(); // ensure width and height >= 0
390  Vec end = GetEnd();
391  Vec rect_end = rect.GetEnd();
392 
393  // Change origin and size in order to contain the given rect
394  m_Pos.x = std::min( m_Pos.x, rect.m_Pos.x );
395  m_Pos.y = std::min( m_Pos.y, rect.m_Pos.y );
396  end.x = std::max( end.x, rect_end.x );
397  end.y = std::max( end.y, rect_end.y );
398  SetEnd( end );
399  return *this;
400  }
const Vec GetEnd() const
Definition: box2.h:194
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:42
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: box2.h:128
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:224
Vec m_Pos
Definition: box2.h:45

Referenced by SHAPE_LINE_CHAIN::Append(), SHAPE_POLY_SET::BBox(), PNS::VIA::ChangedArea(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), PNS::extendBox(), DIALOG_BOARD_STATISTICS::getDataFromPCB(), FOOTPRINT_PREVIEW_PANEL::renderFootprint(), KIGFX::VIEW_GROUP::ViewBBox(), DIMENSION::ViewBBox(), and EDIT_POINTS::ViewBBox().

◆ Merge() [2/2]

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

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 407 of file box2.h.

408  {
409  Normalize(); // ensure width and height >= 0
410 
411  Vec end = GetEnd();
412  // Change origin and size in order to contain the given rect
413  m_Pos.x = std::min( m_Pos.x, aPoint.x );
414  m_Pos.y = std::min( m_Pos.y, aPoint.y );
415  end.x = std::max( end.x, aPoint.x );
416  end.y = std::max( end.y, aPoint.y );
417  SetEnd( end );
418  return *this;
419  }
const Vec GetEnd() const
Definition: box2.h:194
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: box2.h:128
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:224
Vec m_Pos
Definition: box2.h:45

◆ Move()

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

Function Move moves the rectangle by the aMoveVector.

Parameters
aMoveVectorA point that is the value to move this rectangle

Definition at line 119 of file box2.h.

120  {
121  m_Pos += aMoveVector;
122  }
Vec m_Pos
Definition: box2.h:45

Referenced by DIALOG_PAD_PROPERTIES::redraw().

◆ MoveBottomTo()

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

Definition at line 205 of file box2.h.

205 { m_Size.y = aBottom - m_Pos.y; }
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

◆ MoveLeftTo()

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

Definition at line 206 of file box2.h.

206 { m_Pos.x = aLeft; }
Vec m_Pos
Definition: box2.h:45

◆ MoveRightTo()

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

Definition at line 207 of file box2.h.

207 { m_Size.x = aRight - m_Pos.x; }
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

◆ MoveTopTo()

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

Definition at line 204 of file box2.h.

204 { m_Pos.y = aTop; }
Vec m_Pos
Definition: box2.h:45

◆ Normalize()

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

Function Normalize ensures that the height ant width are positive.

Definition at line 128 of file box2.h.

129  {
130  if( m_Size.y < 0 )
131  {
132  m_Size.y = -m_Size.y;
133  m_Pos.y -= m_Size.y;
134  }
135 
136  if( m_Size.x < 0 )
137  {
138  m_Size.x = -m_Size.x;
139  m_Pos.x -= m_Size.x;
140  }
141 
142  return *this;
143  }
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

Referenced by BOX2< VECTOR2I >::BOX2(), PNS::ConvexHull(), KIGFX::VIEW::GetViewport(), BOX2< VECTOR2I >::Intersect(), BOX2< VECTOR2I >::Intersects(), BOX2< VECTOR2I >::Merge(), SVG_PLOTTER::Rect(), KIGFX::VIEW::Redraw(), KIGFX::PREVIEW::ARC_ASSISTANT::ViewBBox(), KIGFX::PREVIEW::RULER_ITEM::ViewBBox(), 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 213 of file box2.h.

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

◆ Offset() [2/2]

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

Definition at line 214 of file box2.h.

215  {
216  m_Pos.x += offset.x; m_Pos.y +=
217  offset.y;
218  }
Vec m_Pos
Definition: box2.h:45

◆ operator!=()

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

Definition at line 510 of file box2.h.

511  {
512  auto t1 ( *this );
513  auto t2 ( aOther );
514  t1.Normalize();
515  t2.Normalize();
516  return ( t1.m_Pos != t2.m_Pos || t1.m_Size != t2.m_Size );
517  }

◆ operator==()

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

Definition at line 501 of file box2.h.

502  {
503  auto t1 ( *this );
504  auto t2 ( aOther );
505  t1.Normalize();
506  t2.Normalize();
507  return ( t1.m_Pos == t2.m_Pos && t1.m_Size == t2.m_Size );
508  }

◆ SetEnd() [1/2]

◆ SetEnd() [2/2]

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

Definition at line 225 of file box2.h.

226  {
227  m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
228  }
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

◆ SetHeight()

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

Definition at line 223 of file box2.h.

223 { m_Size.y = val; }
Vec m_Size
Definition: box2.h:46

◆ SetMaximum()

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

◆ SetOrigin() [1/2]

◆ SetOrigin() [2/2]

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

Definition at line 210 of file box2.h.

210 { m_Pos.x = x; m_Pos.y = y; }
Vec m_Pos
Definition: box2.h:45

◆ SetSize() [1/2]

template<class Vec>
void BOX2< Vec >::SetSize ( const Vec &  size)
inline

◆ SetSize() [2/2]

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

Definition at line 212 of file box2.h.

212 { m_Size.x = w; m_Size.y = h; }
Vec m_Size
Definition: box2.h:46

◆ SetWidth()

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

Definition at line 222 of file box2.h.

222 { m_Size.x = val; }
Vec m_Size
Definition: box2.h:46

◆ SetX()

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

Definition at line 220 of file box2.h.

220 { m_Pos.x = val; }
Vec m_Pos
Definition: box2.h:45

◆ SetY()

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

Definition at line 221 of file box2.h.

221 { m_Pos.y = val; }
Vec m_Pos
Definition: box2.h:45

◆ SquaredDistance() [1/2]

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

Definition at line 441 of file box2.h.

442  {
443  ecoord_type x2 = m_Pos.x + m_Size.x;
444  ecoord_type y2 = m_Pos.y + m_Size.y;
445  ecoord_type xdiff = std::max( aP.x < m_Pos.x ? m_Pos.x - aP.x : m_Pos.x - x2, (ecoord_type) 0 );
446  ecoord_type ydiff = std::max( aP.y < m_Pos.y ? m_Pos.y - aP.y : m_Pos.y - y2, (ecoord_type) 0 );
447  return xdiff * xdiff + ydiff * ydiff;
448  }
Vec::extended_type ecoord_type
Definition: box2.h:50
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

Referenced by SHAPE_LINE_CHAIN::Collide(), 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

Function SquaredDistance returns the square of the minimum distance between self and box aBox.

Parameters
aBoxthe other box
Returns
The distance, squared

Definition at line 461 of file box2.h.

462  {
463  ecoord_type s = 0;
464 
465  if( aBox.m_Pos.x + aBox.m_Size.x < m_Pos.x )
466  {
467  ecoord_type d = aBox.m_Pos.x + aBox.m_Size.x - m_Pos.x;
468  s += d * d;
469  }
470  else if( aBox.m_Pos.x > m_Pos.x + m_Size.x )
471  {
472  ecoord_type d = aBox.m_Pos.x - m_Size.x - m_Pos.x;
473  s += d * d;
474  }
475 
476  if( aBox.m_Pos.y + aBox.m_Size.y < m_Pos.y )
477  {
478  ecoord_type d = aBox.m_Pos.y + aBox.m_Size.y - m_Pos.y;
479  s += d * d;
480  }
481  else if( aBox.m_Pos.y > m_Pos.y + m_Size.y )
482  {
483  ecoord_type d = aBox.m_Pos.y - m_Size.y - m_Pos.y;
484  s += d * d;
485  }
486 
487  return s;
488  }
Vec::extended_type ecoord_type
Definition: box2.h:50
Vec m_Pos
Definition: box2.h:45
Vec m_Size
Definition: box2.h:46

Member Data Documentation

◆ m_Pos

◆ m_Size


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