/// <summary> /// Initializes a new instance of the <see cref="KDTree{TNode}"/> class. /// </summary> /// <param name="dimensions">The number of dimensions in the data set.</param> /// <param name="nodes">The nodes associated with each point.</param> /// <param name="metric">The metric function which implicitly defines the metric space in which the KDTree operates in. This should satisfy the triangle inequality.</param> public KDTree( int dimensions, Func <double[], double[], double> metric, Func <TNode, double[]> selector = null) { this.PointSelector = selector ?? CoordinateSelector.CreateDefaultCoordinateSelector <TNode>(); this.InternalList = new List <TNode>(); this.Dimensions = dimensions; this.Metric = metric; }
public KDTree(int dimensions, IEnumerable <TNode> nodes, Func <double[], double[], double> metric, Func <TNode, double[]> selector = null) { this.PointSelector = selector ?? CoordinateSelector.CreateDefaultCoordinateSelector <TNode>(); this.InternalList = new List <TNode>(nodes); this.Dimensions = dimensions; this.Metric = metric; var points = this.InternalList.Select((p, i) => new CoordinateWithIndex(i, this.PointSelector(p))).ToArray(); this.GenerateTree(ref this.rootNode, null, 0, points); }