From b5e788385d670fc2965faabd1f868d350822531d Mon Sep 17 00:00:00 2001 From: Orange Date: Sat, 3 May 2025 20:38:58 +0300 Subject: [PATCH] fixed style --- include/omath/angles.hpp | 23 ++++++++++++----------- include/omath/mat.hpp | 12 ++++++------ include/omath/pathfinding/a_star.hpp | 2 +- include/omath/projection/camera.hpp | 2 +- source/collision/line_tracer.cpp | 1 + source/engines/iw_engine/camera.cpp | 2 +- source/engines/opengl_engine/camera.cpp | 2 +- source/engines/source_engine/camera.cpp | 2 +- source/engines/unity_engine/camera.cpp | 2 +- source/pathfinding/a_star.cpp | 9 +++++---- tests/general/unit_test_mat.cpp | 8 ++++---- 11 files changed, 34 insertions(+), 31 deletions(-) diff --git a/include/omath/angles.hpp b/include/omath/angles.hpp index bd65414..cafacbb 100644 --- a/include/omath/angles.hpp +++ b/include/omath/angles.hpp @@ -12,23 +12,23 @@ namespace omath::angles requires std::is_floating_point_v [[nodiscard]] constexpr Type radians_to_degrees(const Type& radians) { - return radians * (Type(180) / std::numbers::pi_v); + return radians * (static_cast(180) / std::numbers::pi_v); } template requires std::is_floating_point_v [[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees) { - return degrees * (std::numbers::pi_v / Type(180)); + return degrees * (std::numbers::pi_v / static_cast(180)); } - template - requires std::is_floating_point_v - [[nodiscard]] type horizontal_fov_to_vertical(const type& horizontal_fov, const type& aspect) + template + requires std::is_floating_point_v + [[nodiscard]] Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect) { const auto fov_rad = degrees_to_radians(horizontal_fov); - const auto vert_fov = type(2) * std::atan(std::tan(fov_rad / type(2)) / aspect); + const auto vert_fov = static_cast(2) * std::atan(std::tan(fov_rad / static_cast(2)) / aspect); return radians_to_degrees(vert_fov); } @@ -39,7 +39,8 @@ namespace omath::angles { const auto fov_as_radians = degrees_to_radians(vertical_fov); - const auto horizontal_fov = Type(2) * std::atan(std::tan(fov_as_radians / Type(2)) * aspect); + const auto horizontal_fov + = static_cast(2) * std::atan(std::tan(fov_as_radians / static_cast(2)) * aspect); return radians_to_degrees(horizontal_fov); } @@ -53,11 +54,11 @@ namespace omath::angles const Type range = max - min; - Type wrappedAngle = std::fmod(angle - min, range); + Type wrapped_angle = std::fmod(angle - min, range); - if (wrappedAngle < 0) - wrappedAngle += range; + if (wrapped_angle < 0) + wrapped_angle += range; - return wrappedAngle + min; + return wrapped_angle + min; } } // namespace omath::angles diff --git a/include/omath/mat.hpp b/include/omath/mat.hpp index d13dfc5..8ebbd22 100644 --- a/include/omath/mat.hpp +++ b/include/omath/mat.hpp @@ -226,7 +226,7 @@ namespace omath } [[nodiscard]] - constexpr Mat Transposed() const noexcept + constexpr Mat transposed() const noexcept { Mat transposed; for (size_t i = 0; i < Rows; ++i) @@ -237,7 +237,7 @@ namespace omath } [[nodiscard]] - constexpr Type Determinant() const + constexpr Type determinant() const { static_assert(Rows == Columns, "Determinant is only defined for square matrices."); @@ -284,7 +284,7 @@ namespace omath [[nodiscard]] constexpr Type minor(const size_t row, const size_t column) const { - return strip(row, column).Determinant(); + return strip(row, column).determinant(); } [[nodiscard]] @@ -355,17 +355,17 @@ namespace omath [[nodiscard]] constexpr std::optional inverted() const { - const auto det = Determinant(); + const auto det = determinant(); if (det == 0) return std::nullopt; - const auto transposed = Transposed(); + const auto transposed_mat = transposed(); Mat result; for (std::size_t row = 0; row < Rows; row++) for (std::size_t column = 0; column < Rows; column++) - result.at(row, column) = transposed.alg_complement(row, column); + result.at(row, column) = transposed_mat.alg_complement(row, column); result /= det; diff --git a/include/omath/pathfinding/a_star.hpp b/include/omath/pathfinding/a_star.hpp index 02ec0a4..ba5041d 100644 --- a/include/omath/pathfinding/a_star.hpp +++ b/include/omath/pathfinding/a_star.hpp @@ -25,6 +25,6 @@ namespace omath::pathfinding [[nodiscard]] static auto get_perfect_node(const std::unordered_map, PathNode>& open_list, - const Vector3& endVertex); + const Vector3& end_vertex); }; } // namespace omath::pathfinding diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index 2abb511..93f956a 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -19,7 +19,7 @@ namespace omath::projection float m_width; float m_height; - [[nodiscard]] constexpr float AspectRatio() const + [[nodiscard]] constexpr float aspect_ratio() const { return m_width / m_height; } diff --git a/source/collision/line_tracer.cpp b/source/collision/line_tracer.cpp index 06f22c7..e60c0de 100644 --- a/source/collision/line_tracer.cpp +++ b/source/collision/line_tracer.cpp @@ -42,6 +42,7 @@ namespace omath::collision return ray.end; const auto q = t.cross(side_a); + // ReSharper disable once CppTooWideScopeInitStatement const auto v = ray_dir.dot(q) * inv_det; if ((v < 0 && std::abs(v) > k_epsilon) || (u + v > 1 && std::abs(u + v - 1) > k_epsilon)) diff --git a/source/engines/iw_engine/camera.cpp b/source/engines/iw_engine/camera.cpp index 68849f9..77aaf20 100644 --- a/source/engines/iw_engine/camera.cpp +++ b/source/engines/iw_engine/camera.cpp @@ -27,7 +27,7 @@ namespace omath::iw_engine } Mat4X4 Camera::calc_projection_matrix() const { - return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.AspectRatio(), + return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(), m_near_plane_distance, m_far_plane_distance); } } // namespace omath::iw_engine \ No newline at end of file diff --git a/source/engines/opengl_engine/camera.cpp b/source/engines/opengl_engine/camera.cpp index 8fc0ec5..4b69410 100644 --- a/source/engines/opengl_engine/camera.cpp +++ b/source/engines/opengl_engine/camera.cpp @@ -27,7 +27,7 @@ namespace omath::opengl_engine } Mat4X4 Camera::calc_projection_matrix() const { - return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.AspectRatio(), + return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(), m_near_plane_distance, m_far_plane_distance); } } // namespace omath::opengl_engine diff --git a/source/engines/source_engine/camera.cpp b/source/engines/source_engine/camera.cpp index efc059c..3b550f5 100644 --- a/source/engines/source_engine/camera.cpp +++ b/source/engines/source_engine/camera.cpp @@ -29,7 +29,7 @@ namespace omath::source_engine Mat4X4 Camera::calc_projection_matrix() const { - return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.AspectRatio(), + return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(), m_near_plane_distance, m_far_plane_distance); } } // namespace omath::source_engine diff --git a/source/engines/unity_engine/camera.cpp b/source/engines/unity_engine/camera.cpp index 836b4e9..f06304d 100644 --- a/source/engines/unity_engine/camera.cpp +++ b/source/engines/unity_engine/camera.cpp @@ -21,7 +21,7 @@ namespace omath::unity_engine } Mat4X4 Camera::calc_projection_matrix() const { - return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.AspectRatio(), + return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(), m_near_plane_distance, m_far_plane_distance); } } // namespace omath::unity_engine diff --git a/source/pathfinding/a_star.cpp b/source/pathfinding/a_star.cpp index 658d9ed..593c907 100644 --- a/source/pathfinding/a_star.cpp +++ b/source/pathfinding/a_star.cpp @@ -38,13 +38,13 @@ namespace omath::pathfinding return path; } auto Astar::get_perfect_node(const std::unordered_map, PathNode>& open_list, - const Vector3& endVertex) + const Vector3& end_vertex) { return std::ranges::min_element(open_list, - [&endVertex](const auto& a, const auto& b) + [&end_vertex](const auto& a, const auto& b) { - const float fa = a.second.g_cost + a.first.distance_to(endVertex); - const float fb = b.second.g_cost + b.first.distance_to(endVertex); + const float fa = a.second.g_cost + a.first.distance_to(end_vertex); + const float fb = b.second.g_cost + b.first.distance_to(end_vertex); return fa < fb; }); } @@ -86,6 +86,7 @@ namespace omath::pathfinding const float tentative_g_cost = current_node.g_cost + neighbor.distance_to(current); + // ReSharper disable once CppTooWideScopeInitStatement const auto open_it = open_list.find(neighbor); if (open_it == open_list.end() || tentative_g_cost < open_it->second.g_cost) diff --git a/tests/general/unit_test_mat.cpp b/tests/general/unit_test_mat.cpp index 9350f82..c6162c7 100644 --- a/tests/general/unit_test_mat.cpp +++ b/tests/general/unit_test_mat.cpp @@ -96,7 +96,7 @@ TEST_F(UnitTestMat, Operator_Division_Scalar) // Test matrix functions TEST_F(UnitTestMat, Transpose) { - Mat<2, 2> m3 = m2.Transposed(); + Mat<2, 2> m3 = m2.transposed(); EXPECT_FLOAT_EQ(m3.at(0, 0), m2.at(0, 0)); EXPECT_FLOAT_EQ(m3.at(0, 1), m2.at(1, 0)); EXPECT_FLOAT_EQ(m3.at(1, 0), m2.at(0, 1)); @@ -105,7 +105,7 @@ TEST_F(UnitTestMat, Transpose) TEST_F(UnitTestMat, Determinant) { - const float det = m2.Determinant(); + const float det = m2.determinant(); EXPECT_FLOAT_EQ(det, -2.0f); } @@ -175,7 +175,7 @@ TEST_F(UnitTestMat, Method_At_OutOfRange) // Test Determinant for 3x3 matrix TEST(UnitTestMatStandalone, Determinant_3x3) { - constexpr auto det = Mat<3, 3>{{6, 1, 1}, {4, -2, 5}, {2, 8, 7}}.Determinant(); + constexpr auto det = Mat<3, 3>{{6, 1, 1}, {4, -2, 5}, {2, 8, 7}}.determinant(); EXPECT_FLOAT_EQ(det, -306.0f); } @@ -196,7 +196,7 @@ TEST(UnitTestMatStandalone, Strip_3x3) TEST(UnitTestMatStandalone, Transpose_NonSquare) { constexpr Mat<2, 3> m{{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}}; - auto transposed = m.Transposed(); + auto transposed = m.transposed(); EXPECT_EQ(transposed.row_count(), 3); EXPECT_EQ(transposed.columns_count(), 2); EXPECT_FLOAT_EQ(transposed.at(0, 0), 1.0f);