Skip to content

[Feature Request]: vecmat osiris fusion into one modernized linalg math library adding aligned matrix type #690

Description

@jopadan
  • integrate existing math library code into one single header file
  • add aligned ROWxCOL mat type based on std::array of aligned vec
  • use rvec,uvec,fvec,pos component accessor functions using () instead of vec type
  • add C++26 mdspan/submdspan minor/laplace splice or C++17 kokkos
  • use vector4/vector/scalar for polyeffect
  • switch to vec<float,4>, vec<uint8_t,4> based colour types
  • add 16-bit bitfield colour types for RGB565, RGBA4444 and RGBA5551 with convert to standard vector colour types
template<typename T, size_t ROW, size_t COL,
enum align A = align::adaptive,
size_t ROW_POW2 = VM_BIT_CEIL(ROW),
size_t COL_POW2 = VM_BIT_CEIL(COL),
size_t V_A = alignof(vec<T,COL,A>)>
struct alignas((((ROW * COL == ROW_POW2 * COL_POW2) && A != align::scalar) || (A == align::matrix)) ? ROW_POW2 * V_A : V_A) mat : std::array<vec<T,COL,A>, ROW>
{
constexpr static const size_t RIGHT_HAND = 0;
constexpr static const size_t UP         = 1;
constexpr static const size_t FORWARD    = 2;
constexpr static const size_t POSITION   = 3;

        vec<T,COL,A>& rvec() { return (*this)[0];                          }
        vec<T,COL,A>& uvec() { static_assert(ROW >= 2); return (*this)[1]; }
        vec<T,COL,A>& fvec() { static_assert(ROW >= 3); return (*this)[2]; }
        vec<T,COL,A>& pos()  { static_assert(ROW >= 4); return (*this)[3]; }
        constexpr inline mat<T,ROW-1,COL-1,A> minor(size_t i, size_t p = 0) const
        {
                static_assert(ROW == COL);

                mat<T,ROW-1,COL-1,A> dst{};

                for(size_t j = 0; j < ROW; j++)
                {
                        if(j == i) continue;
                        dst[p++] = (*this)[j].splice(j);
                }
                return dst;
        }
        constexpr inline T det() const
        {
                return (vec<T,COL,A>::id_alt_sign() * (*this)[0] * laplace()).sum();
        }

        constexpr inline vec<T,COL,A> laplace() const
        {
                vec<T,COL,A> dst;
                for(size_t i = 0; i < COL; i++)
                        dst[i] = (*this)[i]->minor(i).det();
                return dst;
        }
};

using matrix2 = mat<scalar,2,2>;
using matrix3 = mat<scalar,3,3>;
using mat_aligned_matrix3 = mat<scalar,3,3,aligned::matrix>  /* stores 3x3 aligned to 4x4 */
using vec_aligned_matrix3 = mat<scalar,3,3,aligned::linear> /* stores 3x3 aligned to 3x4 */
using matrix4 = mat<scalar,4,4>;
using matrix  = matrix3;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions