Accord KDTree with custom distance function
<p>I have a graph data structure representing a road network (nodes are points/intersections in the road and edges are roads). The Node object has a latitude and longitude associated with it. </p>

<p>I'm using Accord's KDTree class to find nearby nodes to a given GPS co-ordinate. Since Accord doesn't seem to have the Haversine distance as a built-in distance function (am I wrong?), I define my own custom distance function, and pass it in as an extra parameter to the KDTree.FromData() method, as follows:</p>

<pre><code>        var nodes = graph.Nodes;
        //Initialize KD-tree with distance function defined as the cartesian approximate distance (in meters) 
        Func&lt;double[], double[], double&gt; distanceFunc = (x, y) =&gt; DistanceFunctions.ApproximateDistance(x,y);
        kdTreeOfNodes = KDTree.FromData&lt;Node&gt;(nodes.Select(x =&gt; new double[] { x.Value.Latitude, x.Value.Longitude }).ToArray(), nodes.ToArray(), distanceFunc);
</code></pre>

<p>Note that 'ApproximateDistance' is defined as a static method in a separate class, and is a cartesian approximation to the more correct Haversine distance. </p>

<p>I get an exception when attempting to excecute the last line. In this line I pass in the data to put into the KDTree (namely an array of lat/lon arrays) as well as the associated nodes, plus my custom distance function. It seems that this FromData constructor actually (for some reason?) calls my ApproximateDistance function, with the arrays [1] and [1] as the two input parameters, obviously raising an exception since this method expects two 2-dimensional arrays. </p>

<p>I have no idea why this constructor is calling my ApproximateDistance function  (especially with these strange parameters), and can't seem to find out using the debugger...</p>