Files
j3ml/include/J3ML/LinearAlgebra/Matrix.hpp
josh 6aa7dc9745
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 58s
Build Docs With Doxygen / Explore-Gitea-Actions (push) Successful in 21s
Fixed undefined reference in Bezier curve. Other additions and fixes included.
2024-08-05 15:14:06 -04:00

78 lines
1.9 KiB
C++

/// Josh's 3D Math Library
/// A C++20 Library for 3D Math, Computer Graphics, and Scientific Computing.
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
/// Special Thanks to William Tomasine II and Maxine Hayes.
/// (c) 2024 Redacted Software
/// This work is dedicated to the public domain.
/// @file Matrix.hpp
/// @desc Templated implementation of arbitrary-sized N-by-M matrices.
/// @edit 2024-08-01
/// @note On backlog, low-priority.
#pragma once
#include <cstddef>
#include <cstdlib>
#include <algorithm>
#include "Vector.hpp"
namespace J3ML::LinearAlgebra
{
template <uint ROWS, uint COLS, typename T>
class Matrix
{
static constexpr uint Diag = std::min(ROWS, COLS);
using RowVector = Vector<ROWS, T>;
using ColVector = Vector<COLS, T>;
using DiagVector = Vector<Diag, T>;
enum { Rows = ROWS };
enum { Cols = COLS };
void AssertRowSize(uint rows)
{
assert(rows < Rows && "");
}
void AssertColumnSize(uint cols)
{
assert(cols < Cols && "");
}
RowVector GetRow(uint index) const;
ColVector GetColumn(uint index) const;
void SetRow(uint index, RowVector);
void SetColumn(uint index, ColVector);
RowVector &Row(uint index) const;
ColVector &Column(uint index) const;
const T At(uint row, uint col) const
{
AssertRowSize(row);
AssertColumnSize(col);
return elems[row][col];
}
T &At(uint row, uint col)
{
AssertRowSize(row);
AssertColumnSize(col);
return elems[row][col];
}
float* ptr();
const float* ptr() const;
float operator[](uint index) const;
float& operator[](uint index);
private:
T elems[ROWS][COLS];
};
}