25 #ifndef __SHAPE_INDEX_LIST_H
26 #define __SHAPE_INDEX_LIST_H
29 const SHAPE* defaultShapeFunctor(
const T aItem )
31 return aItem->Shape();
34 template <
class T, const SHAPE* (ShapeFunctor) (const T) = defaultShapeFunctor<T> >
39 SHAPE_ENTRY( T aParent )
41 shape = ShapeFunctor( aParent );
42 bbox = shape->BBox( 0 );
55 typedef std::vector<SHAPE_ENTRY> SHAPE_VEC;
56 typedef typename std::vector<SHAPE_ENTRY>::iterator SHAPE_VEC_ITER;
66 iterator( SHAPE_VEC_ITER aCurrent ) :
71 m_current( aB.m_current )
76 return (*m_current).parent;
90 bool operator==(
const iterator& aRhs )
const
92 return m_current == aRhs.m_current;
95 bool operator!=(
const iterator& aRhs )
const
97 return m_current != aRhs.m_current;
102 m_current = aRhs.m_current;
107 SHAPE_VEC_ITER m_current;
119 int aMinDistance,
bool aExact ) :
121 m_current( aCurrent ),
123 m_minDistance( aMinDistance ),
128 m_refBBox = aShape->
BBox();
135 m_current( aB.m_current ),
136 m_shape( aB.m_shape ),
137 m_minDistance( aB.m_minDistance ),
138 m_exact( aB.m_exact ),
139 m_refBBox( aB.m_refBBox )
145 return (*m_current).parent;
164 return m_current == aRhs.m_current;
169 return m_current != aRhs.m_current;
175 m_current = aRhs.m_current;
176 m_shape = aRhs.m_shape;
177 m_minDistance = aRhs.m_minDistance;
178 m_exact = aRhs.m_exact;
179 m_refBBox = aRhs.m_refBBox;
186 while( m_current != m_end )
188 if( m_refBBox.Distance( m_current->bbox ) <= m_minDistance )
190 if( !m_exact || m_current->shape->Collide( m_shape, m_minDistance ) )
198 SHAPE_VEC_ITER m_end;
199 SHAPE_VEC_ITER m_current;
208 SHAPE_ENTRY s( aItem );
210 m_shapes.push_back( s );
213 void Remove(
const T aItem )
217 for( i = m_shapes.begin(); i != m_shapes.end(); ++i )
219 if( i->parent == aItem )
223 if( i == m_shapes.end() )
231 return m_shapes.size();
234 template <
class Visitor>
235 int Query(
const SHAPE* aShape,
int aMinDistance, Visitor& aV,
bool aExact =
true )
239 VECTOR2I::extended_type minDistSq = (VECTOR2I::extended_type) aMinDistance * aMinDistance;
243 for( i = m_shapes.begin(); i != m_shapes.end(); ++i )
245 if( refBBox.SquaredDistance( i->bbox ) <= minDistSq )
247 if( !aExact || i->shape->Collide( aShape, aMinDistance ) )
251 if( !aV( i->parent ) )
265 query_iterator qbegin(
SHAPE* aShape,
int aMinDistance,
bool aExact )
267 return query_iterator( m_shapes.begin(), m_shapes.end(), aShape, aMinDistance, aExact );
270 const query_iterator qend()
272 return query_iterator( m_shapes.end(), m_shapes.end(), NULL, 0,
false );
277 return iterator( m_shapes.begin() );
282 return iterator( m_shapes.end() );