25 #ifndef __SHAPE_INDEX_LIST_H 26 #define __SHAPE_INDEX_LIST_H 28 #include <boost/unordered_map.hpp> 31 const SHAPE* defaultShapeFunctor(
const T aItem )
33 return aItem->Shape();
36 template <
class T, const SHAPE* (ShapeFunctor) (const T) = defaultShapeFunctor<T> >
41 SHAPE_ENTRY( T aParent )
43 shape = ShapeFunctor( aParent );
44 bbox = shape->BBox( 0 );
57 typedef std::vector<SHAPE_ENTRY> SHAPE_VEC;
58 typedef typename std::vector<SHAPE_ENTRY>::iterator SHAPE_VEC_ITER;
68 iterator( SHAPE_VEC_ITER aCurrent ) :
73 m_current( aB.m_current )
78 return (*m_current).parent;
92 bool operator==(
const iterator& aRhs )
const 94 return m_current == aRhs.m_current;
97 bool operator!=(
const iterator& aRhs )
const 99 return m_current != aRhs.m_current;
104 m_current = aRhs.m_current;
109 SHAPE_VEC_ITER m_current;
121 int aMinDistance,
bool aExact ) :
123 m_current( aCurrent ),
125 m_minDistance( aMinDistance ),
130 m_refBBox = aShape->
BBox();
137 m_current( aB.m_current ),
138 m_shape( aB.m_shape ),
139 m_minDistance( aB.m_minDistance ),
140 m_exact( aB.m_exact ),
141 m_refBBox( aB.m_refBBox )
147 return (*m_current).parent;
166 return m_current == aRhs.m_current;
171 return m_current != aRhs.m_current;
177 m_current = aRhs.m_current;
178 m_shape = aRhs.m_shape;
179 m_minDistance = aRhs.m_minDistance;
180 m_exact = aRhs.m_exact;
181 m_refBBox = aRhs.m_refBBox;
188 while( m_current != m_end )
190 if( m_refBBox.Distance( m_current->bbox ) <= m_minDistance )
192 if( !m_exact || m_current->shape->Collide( m_shape, m_minDistance ) )
200 SHAPE_VEC_ITER m_end;
201 SHAPE_VEC_ITER m_current;
210 SHAPE_ENTRY s( aItem );
212 m_shapes.push_back( s );
215 void Remove(
const T aItem )
219 for( i = m_shapes.begin(); i != m_shapes.end(); ++i )
221 if( i->parent == aItem )
225 if( i == m_shapes.end() )
233 return m_shapes.size();
236 template <
class Visitor>
237 int Query(
const SHAPE* aShape,
int aMinDistance, Visitor& aV,
bool aExact =
true )
241 VECTOR2I::extended_type minDistSq = (VECTOR2I::extended_type) aMinDistance * aMinDistance;
245 for( i = m_shapes.begin(); i != m_shapes.end(); ++i )
247 if( refBBox.SquaredDistance( i->bbox ) <= minDistSq )
249 if( !aExact || i->shape->Collide( aShape, aMinDistance ) )
253 if( !aV( i->parent ) )
269 return query_iterator( m_shapes.begin(), m_shapes.end(), aShape, aMinDistance, aExact );
274 return query_iterator( m_shapes.end(), m_shapes.end(), NULL, 0, false );
279 return iterator( m_shapes.begin() );
Definition: shape_index_list.h:37
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Definition: shape_index_list.h:62
Definition: shape_index_list.h:113
Class SHAPE.
Definition: shape.h:57