KiCad PCB EDA Suite
shape_index.h File Reference
#include <vector>
#include <geometry/rtree.h>
#include <geometry/shape.h>
#include <math/box2.h>

Go to the source code of this file.

Classes

class  SHAPE_INDEX< T >
 
class  SHAPE_INDEX< T >::Iterator
 

Functions

template<class T >
static const SHAPEshapeFunctor (T aItem)
 Used by SHAPE_INDEX to get a SHAPE* from another type. More...
 
template<class T >
static const SHAPEholeFunctor (T aItem)
 Used by SHAPE_INDEX to get a SHAPE* for a hole from another type. More...
 
template<class T >
BOX2I boundingBox (T aObject)
 Used by SHAPE_INDEX to get the bounding box of a generic T object. More...
 
template<class T , class V >
void acceptVisitor (T aObject, V aVisitor)
 Used by SHAPE_INDEX to implement Accept(). More...
 
template<class T , class U >
bool collide (T aObject, U aAnotherObject, int aMinDistance)
 Used by SHAPE_INDEX to implement Query(). More...
 
template<class T , class V >
bool queryCallback (T aShape, void *aContext)
 

Function Documentation

◆ acceptVisitor()

template<class T , class V >
void acceptVisitor ( aObject,
aVisitor 
)

Used by SHAPE_INDEX to implement Accept().

By default relies on V::operation() redefinition, should be specialized if V class doesn't have its () operation defined to accept T objects.

Parameters
aObjectis a generic T object.
aVisitoris a visitor object.

Definition at line 97 of file shape_index.h.

98{
99 aVisitor( aObject );
100}

Referenced by SHAPE_INDEX< T >::Accept().

◆ boundingBox()

template<class T >
BOX2I boundingBox ( aObject)

Used by SHAPE_INDEX to get the bounding box of a generic T object.

By default relies on T::BBox() method, should be specialized if the T object doesn't allow that method.

Parameters
aObjectis a generic T object.
Returns
a BOX2I object containing the bounding box of the T object.

Definition at line 77 of file shape_index.h.

78{
79 BOX2I bbox = shapeFunctor( aObject )->BBox();
80
81 if( holeFunctor( aObject ) )
82 bbox.Merge( holeFunctor( aObject )->BBox() );
83
84 return bbox;
85}
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:588
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.
static const SHAPE * shapeFunctor(T aItem)
Used by SHAPE_INDEX to get a SHAPE* from another type.
Definition: shape_index.h:47
static const SHAPE * holeFunctor(T aItem)
Used by SHAPE_INDEX to get a SHAPE* for a hole from another type.
Definition: shape_index.h:62

References SHAPE::BBox(), holeFunctor(), BOX2< Vec >::Merge(), and shapeFunctor().

Referenced by SHAPE_INDEX< T >::Add(), SHAPE_INDEX< T >::Reindex(), SHAPE_INDEX< T >::Remove(), and KIFONT::FONT::StringBoundaryLimits().

◆ collide()

template<class T , class U >
bool collide ( aObject,
aAnotherObject,
int  aMinDistance 
)

Used by SHAPE_INDEX to implement Query().

By default relies on T::Collide(U) method, should be specialized if the T object doesn't allow that method.

Parameters
aObjectis a generic T object.
aAnotherObjectis a generic U object.
aMinDistanceis the minimum collision distance.
Returns
true if object and anotherObject collide.

Definition at line 114 of file shape_index.h.

115{
116 return shapeFunctor( aObject )->Collide( aAnotherObject, aMinDistance );
117}
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition: shape.h:179

References SHAPE::Collide(), and shapeFunctor().

Referenced by AUTOPLACER::chooseSideFiltered().

◆ holeFunctor()

template<class T >
static const SHAPE * holeFunctor ( aItem)
static

Used by SHAPE_INDEX to get a SHAPE* for a hole from another type.

By default relies on T::GetHole() method, should be specialized if the T object doesn't allow that method.

Parameters
aItemgeneric T object.
Returns
a SHAPE* object equivalent to object.

Definition at line 62 of file shape_index.h.

63{
64 return aItem->Hole();
65}

Referenced by boundingBox().

◆ queryCallback()

template<class T , class V >
bool queryCallback ( aShape,
void *  aContext 
)

Definition at line 120 of file shape_index.h.

121{
122 V* visitor = (V*) aContext;
123
124 acceptVisitor<T, V>( aShape, *visitor );
125
126 return true;
127}

◆ shapeFunctor()

template<class T >
static const SHAPE * shapeFunctor ( aItem)
static

Used by SHAPE_INDEX to get a SHAPE* from another type.

By default relies on T::GetShape() method, should be specialized if the T object doesn't allow that method.

Parameters
aItemgeneric T object.
Returns
a SHAPE* object equivalent to object.

Definition at line 47 of file shape_index.h.

48{
49 return aItem->Shape();
50}

Referenced by boundingBox(), and collide().