Exemplo n.º 1
0
            public static Node Read(
                BinaryReader reader, Vector <float> position, Vector <float> size, int contentElements)
            {
                var value      = BinaryUtil.ReadVector(reader, contentElements);
                var splitIndex = reader.ReadInt32();

                if (splitIndex == 0)
                {
                    return(new LeafNode(position, size, value));
                }
                splitIndex--;
                var halfSize  = size[splitIndex] * 0.5f;
                var childSize = CreateVector.SparseOfVector(size);

                childSize[splitIndex] = halfSize;
                var leftPosition = CreateVector.SparseOfVector(position);

                leftPosition[splitIndex] -= halfSize * 0.5f;
                var left          = Read(reader, leftPosition, childSize, contentElements);
                var rightPosition = CreateVector.SparseOfVector(position);

                rightPosition[splitIndex] += halfSize * 0.5f;
                var right = Read(reader, rightPosition, childSize, contentElements);

                return(new InternalNode(position, size, value, splitIndex, left, right));
            }