Beispiel #1
0
        public KDTreeNode(T[] values, int depth, int maxDepth)
        {
            var dimension = (Dimension)(depth % 3);

            _lowerBound = new Vector3(
                values.Min(v => v.MinX),
                values.Min(v => v.MinY),
                values.Min(v => v.MinZ)
                );
            _upperBound = new Vector3(
                values.Max(v => v.MaxX),
                values.Max(v => v.MaxY),
                values.Max(v => v.MaxZ)
                );
            if (depth == maxDepth)
            {
                _values = values;
                return;
            }
            Array.Sort(values, (a, b) => a.CompareTo(b, dimension));
            var median = values.Length / 2;

            _left  = new KDTreeNode <T>(values[..median], depth + 1, maxDepth);
Beispiel #2
0
 public KDTree(T[] values)
 {
     Console.WriteLine((int)Math.Log2(values.Length));
     Root = new KDTreeNode <T>(values, 0, (int)Math.Log2(values.Length));
 }