added additional methods

This commit is contained in:
2025-04-29 20:10:17 +03:00
parent 4ef674f7b4
commit 4615769682
2 changed files with 18 additions and 5 deletions

View File

@@ -257,9 +257,9 @@ namespace omath
if constexpr (Rows > 2) if constexpr (Rows > 2)
{ {
Type det = 0; Type det = 0;
for (size_t i = 0; i < Columns; ++i) for (size_t column = 0; column < Columns; ++column)
{ {
const Type cofactor = (i % 2 == 0 ? 1 : -1) * At(0, i) * Minor(0, i).Determinant(); const Type cofactor = At(0, column) * AlgComplement(0, column);
det += cofactor; det += cofactor;
} }
return det; return det;
@@ -268,7 +268,7 @@ namespace omath
} }
[[nodiscard]] [[nodiscard]]
constexpr Mat<Rows - 1, Columns - 1, Type, StoreType> Minor(const size_t row, const size_t column) const constexpr Mat<Rows - 1, Columns - 1, Type, StoreType> Strip(const size_t row, const size_t column) const
{ {
static_assert(Rows-1 > 0 && Columns-1 > 0); static_assert(Rows-1 > 0 && Columns-1 > 0);
Mat<Rows - 1, Columns - 1, Type, StoreType> result; Mat<Rows - 1, Columns - 1, Type, StoreType> result;
@@ -288,6 +288,19 @@ namespace omath
return result; return result;
} }
[[nodiscard]]
constexpr Type Minor(const size_t row, const size_t column) const
{
return Strip(row, column).Determinant();
}
[[nodiscard]]
constexpr Type AlgComplement(const size_t row, const size_t column) const
{
const auto minor = Minor(row, column);
return (row + column + 2) % 2 == 0 ? minor: -minor;
}
[[nodiscard]] [[nodiscard]]
constexpr const std::array<Type, Rows * Columns>& RawArray() const constexpr const std::array<Type, Rows * Columns>& RawArray() const
{ {

View File

@@ -180,10 +180,10 @@ TEST(UnitTestMatStandalone, Determinant_3x3)
} }
// Test Minor for 3x3 matrix // Test Minor for 3x3 matrix
TEST(UnitTestMatStandalone, Minor_3x3) TEST(UnitTestMatStandalone, Strip_3x3)
{ {
constexpr Mat<3, 3> m{{3, 0, 2}, {2, 0, -2}, {0, 1, 1}}; constexpr Mat<3, 3> m{{3, 0, 2}, {2, 0, -2}, {0, 1, 1}};
auto minor = m.Minor(0, 0); auto minor = m.Strip(0, 0);
EXPECT_EQ(minor.RowCount(), 2); EXPECT_EQ(minor.RowCount(), 2);
EXPECT_EQ(minor.ColumnsCount(), 2); EXPECT_EQ(minor.ColumnsCount(), 2);
EXPECT_FLOAT_EQ(minor.At(0, 0), 0.0f); EXPECT_FLOAT_EQ(minor.At(0, 0), 0.0f);