Compare commits

...

7 Commits

Author SHA1 Message Date
145eadfffa Merge pull request #36 from orange-cpp/u/orange-cpp/small-refactoring
U/orange cpp/small refactoring
2025-04-12 13:34:28 +03:00
14acebad5f fixed tests 2025-04-12 00:04:07 +03:00
4a7a631932 added const method to mat 2025-04-11 23:57:56 +03:00
e08c22f604 added new build option 2025-04-11 23:54:56 +03:00
1b47f45af9 improved naming 2025-04-11 23:30:07 +03:00
466d8f7bec improvement 2025-04-11 23:20:16 +03:00
3631c5d698 replaced with STL relization 2025-04-11 23:10:02 +03:00
4 changed files with 35 additions and 32 deletions

View File

@@ -12,6 +12,8 @@ option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF)
option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF)
option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build to improve general performance" ON)
if (OMATH_BUILD_AS_SHARED_LIBRARY)
add_library(omath SHARED source/matrix.cpp)
@@ -19,6 +21,7 @@ else()
add_library(omath STATIC source/matrix.cpp
source/matrix.cpp)
endif()
message(STATUS "Building on ${CMAKE_HOST_SYSTEM_NAME}")
add_library(omath::omath ALIAS omath)
@@ -45,6 +48,10 @@ if (OMATH_USE_AVX2)
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
endif()
if (OMATH_SUPRESS_SAFETY_CHECKS)
target_compile_definitions(omath PUBLIC OMATH_SUPRESS_SAFETY_CHECKS)
endif()
set_target_properties(omath PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"

View File

@@ -82,9 +82,9 @@ TEST(UnitTestProjection, IsPointOnScreen)
EXPECT_TRUE(proj.has_value());
}
```
## Showcase
<details>
<summary>OMATH for making cheats</summary>
<summary>OMATH for making cheats (click to open)</summary>
With `omath/projection` module you can achieve simple ESP hack for powered by Source/Unreal/Unity engine games, like [Apex Legends](https://store.steampowered.com/app/1172470/Apex_Legends/).

View File

@@ -9,6 +9,7 @@
#include <stdexcept>
#include <utility>
#include "omath/vector3.hpp"
#include <numeric>
#ifdef near
@@ -91,6 +92,12 @@ namespace omath
return At(row, col);
}
[[nodiscard]]
constexpr Type& operator[](const size_t row, const size_t col) const
{
return At(row, col);
}
constexpr Mat(Mat&& other) noexcept
{
m_data = std::move(other.m_data);
@@ -117,9 +124,10 @@ namespace omath
[[nodiscard]]
constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const
{
#if !defined(NDEBUG) && defined(OMATH_SUPRESS_SAFETY_CHECKS)
if (rowIndex >= Rows || columnIndex >= Columns)
throw std::out_of_range("Index out of range");
#endif
if constexpr (StoreType == MatStoreType::ROW_MAJOR)
return m_data[rowIndex * Columns + columnIndex];
@@ -141,12 +149,7 @@ namespace omath
[[nodiscard]]
constexpr Type Sum() const noexcept
{
Type sum = 0;
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Columns; ++j)
sum += At(i, j);
return sum;
return std::accumulate(m_data.begin(), m_data.end(), Type(0));
}
constexpr void Clear() noexcept
@@ -161,6 +164,7 @@ namespace omath
// Operator overloading for multiplication with another Mat
template<size_t OtherColumns>
[[nodiscard]]
constexpr Mat<Rows, OtherColumns, Type, StoreType>
operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
{
@@ -179,9 +183,7 @@ namespace omath
constexpr Mat& operator*=(const Type& f) noexcept
{
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Columns; ++j)
At(i, j) *= f;
std::ranges::for_each(m_data, [&f](auto& val) {val *= f;});
return *this;
}
@@ -193,47 +195,39 @@ namespace omath
}
[[nodiscard]]
constexpr Mat operator*(const Type& f) const noexcept
constexpr Mat operator*(const Type& value) const noexcept
{
Mat result(*this);
result *= f;
result *= value;
return result;
}
constexpr Mat& operator/=(const Type& f) noexcept
constexpr Mat& operator/=(const Type& value) noexcept
{
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Columns; ++j)
At(i, j) /= f;
std::ranges::for_each(m_data, [&value](auto& val) {val /= value;});
return *this;
}
[[nodiscard]]
constexpr Mat operator/(const Type& f) const noexcept
constexpr Mat operator/(const Type& value) const noexcept
{
Mat result(*this);
result /= f;
result /= value;
return result;
}
constexpr Mat& operator=(const Mat& other) noexcept
{
if (this == &other)
return *this;
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Columns; ++j)
At(i, j) = other.At(i, j);
if (this != &other)
m_data = other.m_data;
return *this;
}
constexpr Mat& operator=(Mat&& other) noexcept
{
if (this == &other)
return *this;
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Columns; ++j)
At(i, j) = other.At(i, j);
if (this != &other)
m_data = std::move(other.m_data);
return *this;
}
@@ -257,7 +251,7 @@ namespace omath
if constexpr (Rows == 1)
return At(0, 0);
else if constexpr (Rows == 2)
if constexpr (Rows == 2)
return At(0, 0) * At(1, 1) - At(0, 1) * At(1, 0);
else
{

View File

@@ -166,8 +166,10 @@ TEST_F(UnitTestMat, StaticMethod_ToScreenMat)
// Test exception handling in At() method
TEST_F(UnitTestMat, Method_At_OutOfRange)
{
#if !defined(NDEBUG) && defined(OMATH_SUPRESS_SAFETY_CHECKS)
EXPECT_THROW(std::ignore = m2.At(2, 0), std::out_of_range);
EXPECT_THROW(std::ignore = m2.At(0, 2), std::out_of_range);
#endif
}
// Test Determinant for 3x3 matrix