How should I write a FindClosestMatching function?
<p>Of all objects matching a condition, find the one closest to a position. Supposedly a very common problem. The current code looks like this:</p>

<pre><code>protected Foo FindClosestFooMatching (Vec pos, Func&lt;Foo, bool&gt; matches)
{
 float bestDist = float.MaxValue;
 Foo bestFoo = null;

 foreach (Foo foo in AllFoos()) {
  if (matches (foo)) {
   float dist = pos.Dist (foo.Center);
   if (dist &lt;= bestDist) {
    bestDist = dist;
    bestFoo = foo;
   }
  }
 }
 return bestFoo;
}
</code></pre>

<p>I'm thinking of several ways to refactor this code, but failed to find a really nice one yet. If you've got a minute, give it a shot.  :-)</p>

<p><b>Edit:</b> Regarding Eric's questions. It's a standard 3D space with Euclidian metric (= fast). Point clustering and junk query likelihood is unknown.</p>
