* Add a forgotten file.
This commit is contained in:
jean.chalard
2009-08-28 15:09:21 +00:00
parent 71e9a3b2cc
commit fe6e811f0b

View File

@@ -0,0 +1,31 @@
#ifndef _CLOSEST_H_
#define _CLOSEST_H_
template <typename T, typename Target>
static inline Target* closest(vector<Target*>& cards, Limitor* limitor, Target* ref)
{
Target* card = ref;
float curdist = 1000000.0f; // This is bigger than any possible distance
for (typename vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
{
if (!T::test(ref, (*it))) continue;
if ((*it)->actA < 32) continue;
if ((NULL != limitor) && (!limitor->select(*it))) continue;
if (ref)
{
float dist = ((*it)->x - ref->x) * ((*it)->x - ref->x) + ((*it)->y - ref->y) * ((*it)->y - ref->y);
if (dist < curdist)
{
curdist = dist;
card = *it;
}
}
else
card = *it;
}
{ CardView* c = dynamic_cast<CardView*>(ref); if (c) c->zoom = 1.0; }
{ CardView* c = dynamic_cast<CardView*>(card); if (c) c->zoom = 1.4; }
return card;
}
#endif