Compare commits

...

5 Commits

Author SHA1 Message Date
9a4fb67289 hotfix 2025-01-02 20:32:25 +03:00
824b301d40 small code improvement 2025-01-02 18:40:19 +03:00
dcf466316c Merge pull request #23 from orange-cpp/u/orange-cpp/vec3-angle-calc
added AngleBetween method for Vector3 + tests
2025-01-02 12:54:27 +03:00
dc0bca14c5 added method + tests 2025-01-02 12:52:34 +03:00
b2db06a739 updated read me 2024-12-26 18:52:24 +03:00
5 changed files with 41 additions and 10 deletions

View File

@@ -11,7 +11,7 @@
Oranges's Math Library (omath) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research. Oranges's Math Library (omath) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research.
## Features ## 👁‍🗨 Features
- **Efficiency**: Optimized for performance, ensuring quick computations. - **Efficiency**: Optimized for performance, ensuring quick computations.
- **Versatility**: Includes a wide array of mathematical functions and algorithms. - **Versatility**: Includes a wide array of mathematical functions and algorithms.
- **Ease of Use**: Simplified interface for convenient integration into various projects. - **Ease of Use**: Simplified interface for convenient integration into various projects.
@@ -20,7 +20,7 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces. - **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution - **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
## Getting Started ## Getting Started
### Prerequisites ### Prerequisites
- C++ Compiler - C++ Compiler
- CMake (for building the project) - CMake (for building the project)
@@ -54,7 +54,7 @@ For detailed commands on installing different versions and more information, ple
cmake --build cmake-build/build/windows-release --target server -j 6 cmake --build cmake-build/build/windows-release --target server -j 6
``` ```
Use **\<platform\>-\<build configuration\>** preset to build siutable version for yourself. Like **windows-release** or **linux-release**. Use **\<platform\>-\<build configuration\>** preset to build siutable version for yourself. Like **windows-release** or **linux-release**.
## Usage ## Usage
Simple world to screen function Simple world to screen function
```c++ ```c++
TEST(UnitTestProjection, IsPointOnScreen) TEST(UnitTestProjection, IsPointOnScreen)
@@ -76,11 +76,11 @@ With `omath/projection` module you can achieve simple ESP hack for powered by So
</details> </details>
## Contributing ## 🫵🏻 Contributing
Contributions to `omath` are welcome! Please read `CONTRIBUTING.md` for details on our code of conduct and the process for submitting pull requests. Contributions to `omath` are welcome! Please read `CONTRIBUTING.md` for details on our code of conduct and the process for submitting pull requests.
## License ## 📜 License
This project is licensed under the MIT - see the `LICENSE` file for details. This project is licensed under the MIT - see the `LICENSE` file for details.
## Acknowledgments ## 💘 Acknowledgments
- [All contributors](https://github.com/orange-cpp/omath/graphs/contributors) - [All contributors](https://github.com/orange-cpp/omath/graphs/contributors)

View File

@@ -38,10 +38,7 @@ namespace omath
[[nodiscard]] [[nodiscard]]
float& operator[](size_t row, size_t column) float& operator[](size_t row, size_t column);
{
return At(row, column);
}
[[nodiscard]] [[nodiscard]]
size_t ColumnsCount() const noexcept; size_t ColumnsCount() const noexcept;

View File

@@ -7,9 +7,18 @@
#include <cstdint> #include <cstdint>
#include <functional> #include <functional>
#include "omath/Vector2.hpp" #include "omath/Vector2.hpp"
#include "omath/Angle.hpp"
#include <expected>
namespace omath namespace omath
{ {
enum class Vector3Error
{
IMPOSSIBLE_BETWEEN_ANGLE,
};
class Vector3 : public Vector2 class Vector3 : public Vector2
{ {
public: public:
@@ -208,6 +217,17 @@ namespace omath
return Sum2D() + z; return Sum2D() + z;
} }
[[nodiscard]] std::expected<Angle<float, 0.f, 180.f, AngleFlags::Clamped>, Vector3Error>
AngleBetween(const Vector3& other) const
{
const auto bottom = Length() * other.Length();
if (bottom == 0.f)
return std::unexpected(Vector3Error::IMPOSSIBLE_BETWEEN_ANGLE);
return Angle<float, 0.f, 180.f, AngleFlags::Clamped>::FromRadians(std::acos(Dot(other) / bottom));
}
[[nodiscard]] constexpr float Sum2D() const [[nodiscard]] constexpr float Sum2D() const
{ {
return Vector2::Sum(); return Vector2::Sum();

View File

@@ -75,6 +75,11 @@ namespace omath
return m_rows; return m_rows;
} }
float& Matrix::operator[](const size_t row, const size_t column)
{
return At(row, column);
}
Matrix::Matrix(Matrix&& other) noexcept Matrix::Matrix(Matrix&& other) noexcept
{ {
m_rows = other.m_rows; m_rows = other.m_rows;

View File

@@ -387,6 +387,15 @@ TEST_F(UnitTestVector3, AsTuple)
EXPECT_FLOAT_EQ(std::get<2>(tuple), v1.z); EXPECT_FLOAT_EQ(std::get<2>(tuple), v1.z);
} }
// Test AsTuple method
TEST_F(UnitTestVector3, AngleBeatween)
{
EXPECT_EQ(Vector3(0.0f, 0.0f, 1.0f).AngleBetween({1, 0 ,0}).value().AsDegrees(), 90.0f);
EXPECT_EQ(Vector3(0.0f, 0.0f, 1.0f).AngleBetween({0.0f, 0.0f, 1.0f}).value().AsDegrees(), 0.0f);
EXPECT_FALSE(Vector3(0.0f, 0.0f, 0.0f).AngleBetween({0.0f, 0.0f, 1.0f}).has_value());
}
// Static assertions (compile-time checks) // Static assertions (compile-time checks)
static_assert(Vector3(1.0f, 2.0f, 3.0f).LengthSqr() == 14.0f, "LengthSqr should be 14"); static_assert(Vector3(1.0f, 2.0f, 3.0f).LengthSqr() == 14.0f, "LengthSqr should be 14");
static_assert(Vector3(1.0f, 2.0f, 3.0f).Dot(Vector3(4.0f, 5.0f, 6.0f)) == 32.0f, "Dot product should be 32"); static_assert(Vector3(1.0f, 2.0f, 3.0f).Dot(Vector3(4.0f, 5.0f, 6.0f)) == 32.0f, "Dot product should be 32");