mag and normal

v1
Brett 2024-09-19 23:48:58 -04:00
parent 6646db8249
commit 1ceb71aac9
2 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake)
set(BLT_VERSION 0.20.11)
set(BLT_VERSION 0.20.12)
set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT)

View File

@ -135,6 +135,26 @@ namespace blt
return mat;
}
T magnitude() const
{
T ret;
for (blt::u32 i = 0; i < columns; i++)
{
for (blt::u32 j = 0; j < rows; j++)
ret += (data[i][j] * data[i][j]);
}
return std::sqrt(ret);
}
matrix_t normalize() const
{
auto mag = magnitude();
matrix_t mat = *this;
if (mag == 0)
return mat;
return mat / mag;
}
constexpr inline const blt::vec<T, rows>& operator[](u32 column) const
{
return data[column];