// ========================================================================== //
// Class inclusion
#include "Utilities/math_operations.hpp"

// External libraries
#include <GEL/CGLA/CGLA.h>

// Standard libraries
#include <vector>

namespace Utilities {
    // ====================================================================== //
    // Generic vector operations

    // Rotate the vector v around normal n by angle theta
    CGLA::Vec3d rotate(const CGLA::Vec3d &v, const CGLA::Vec3d &n,
                       const double &theta) {
        const double le = CGLA::length(v);
        const double ct = cos(theta);
        const double st = sin(theta);
        return le * CGLA::normalize(v * ct + cross(n, v) * st +
                                    n * dot(n, v) * (1.0 - ct));
    }

    // ====================================================================== //
    // Combinatorials

    // Combinatorial list of K integers from [0, N)
    std::vector<std::vector<int>> combinatorial_list(const int &N,
                                                     const int &K) {
        std::string bitmask(K, 1); // K leading 1's
        bitmask.resize(N, 0);      // N-K trailing 0's

        std::vector<std::vector<int>> R;
        std::vector<int>              r(K);

        // print integers and permute bitmask
        do {
            int idx = 0;
            for (int i = 0; i < N; ++i) // [0..N-1] integers
            {
                if (bitmask[i]) r[idx++] = i;
            }
            R.push_back(r);
        } while (std::prev_permutation(bitmask.begin(), bitmask.end()));
        return R;
    }
} // namespace Utilities

// End of File
// ========================================================================== //