/**
 * @template T
 * @param {T[]} result
 * @param {number} result_offset
 * @param {QuadTreeNode<T>} root
 * @returns {number}
 */
export function qt_collect_data_all(result, result_offset, root) {

    const data = root.data;
    const data_count = data.length;

    let cursor = result_offset;

    for (let i = 0; i < data_count; i++) {
        result[cursor++] = data[i].data;
    }

    if (root.isSplit()) {

        cursor += qt_collect_data_all(result, cursor, root.topLeft);
        cursor += qt_collect_data_all(result, cursor, root.topRight);
        cursor += qt_collect_data_all(result, cursor, root.bottomLeft);
        cursor += qt_collect_data_all(result, cursor, root.bottomRight);

    }

    return cursor - result_offset;
}