fixed style

This commit is contained in:
2025-05-03 20:38:58 +03:00
parent df6d75e554
commit b5e788385d
11 changed files with 34 additions and 31 deletions

View File

@@ -12,23 +12,23 @@ namespace omath::angles
requires std::is_floating_point_v<Type> requires std::is_floating_point_v<Type>
[[nodiscard]] constexpr Type radians_to_degrees(const Type& radians) [[nodiscard]] constexpr Type radians_to_degrees(const Type& radians)
{ {
return radians * (Type(180) / std::numbers::pi_v<Type>); return radians * (static_cast<Type>(180) / std::numbers::pi_v<Type>);
} }
template<class Type> template<class Type>
requires std::is_floating_point_v<Type> requires std::is_floating_point_v<Type>
[[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees) [[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees)
{ {
return degrees * (std::numbers::pi_v<Type> / Type(180)); return degrees * (std::numbers::pi_v<Type> / static_cast<Type>(180));
} }
template<class type> template<class Type>
requires std::is_floating_point_v<type> requires std::is_floating_point_v<Type>
[[nodiscard]] type horizontal_fov_to_vertical(const type& horizontal_fov, const type& aspect) [[nodiscard]] Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect)
{ {
const auto fov_rad = degrees_to_radians(horizontal_fov); 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<Type>(2) * std::atan(std::tan(fov_rad / static_cast<Type>(2)) / aspect);
return radians_to_degrees(vert_fov); 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 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<Type>(2) * std::atan(std::tan(fov_as_radians / static_cast<Type>(2)) * aspect);
return radians_to_degrees(horizontal_fov); return radians_to_degrees(horizontal_fov);
} }
@@ -53,11 +54,11 @@ namespace omath::angles
const Type range = max - min; const Type range = max - min;
Type wrappedAngle = std::fmod(angle - min, range); Type wrapped_angle = std::fmod(angle - min, range);
if (wrappedAngle < 0) if (wrapped_angle < 0)
wrappedAngle += range; wrapped_angle += range;
return wrappedAngle + min; return wrapped_angle + min;
} }
} // namespace omath::angles } // namespace omath::angles

View File

@@ -226,7 +226,7 @@ namespace omath
} }
[[nodiscard]] [[nodiscard]]
constexpr Mat<Columns, Rows, Type, StoreType> Transposed() const noexcept constexpr Mat<Columns, Rows, Type, StoreType> transposed() const noexcept
{ {
Mat<Columns, Rows, Type, StoreType> transposed; Mat<Columns, Rows, Type, StoreType> transposed;
for (size_t i = 0; i < Rows; ++i) for (size_t i = 0; i < Rows; ++i)
@@ -237,7 +237,7 @@ namespace omath
} }
[[nodiscard]] [[nodiscard]]
constexpr Type Determinant() const constexpr Type determinant() const
{ {
static_assert(Rows == Columns, "Determinant is only defined for square matrices."); static_assert(Rows == Columns, "Determinant is only defined for square matrices.");
@@ -284,7 +284,7 @@ namespace omath
[[nodiscard]] [[nodiscard]]
constexpr Type minor(const size_t row, const size_t column) const constexpr Type minor(const size_t row, const size_t column) const
{ {
return strip(row, column).Determinant(); return strip(row, column).determinant();
} }
[[nodiscard]] [[nodiscard]]
@@ -355,17 +355,17 @@ namespace omath
[[nodiscard]] [[nodiscard]]
constexpr std::optional<Mat> inverted() const constexpr std::optional<Mat> inverted() const
{ {
const auto det = Determinant(); const auto det = determinant();
if (det == 0) if (det == 0)
return std::nullopt; return std::nullopt;
const auto transposed = Transposed(); const auto transposed_mat = transposed();
Mat result; Mat result;
for (std::size_t row = 0; row < Rows; row++) for (std::size_t row = 0; row < Rows; row++)
for (std::size_t column = 0; column < Rows; column++) 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; result /= det;

View File

@@ -25,6 +25,6 @@ namespace omath::pathfinding
[[nodiscard]] [[nodiscard]]
static auto get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list, static auto get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list,
const Vector3<float>& endVertex); const Vector3<float>& end_vertex);
}; };
} // namespace omath::pathfinding } // namespace omath::pathfinding

View File

@@ -19,7 +19,7 @@ namespace omath::projection
float m_width; float m_width;
float m_height; float m_height;
[[nodiscard]] constexpr float AspectRatio() const [[nodiscard]] constexpr float aspect_ratio() const
{ {
return m_width / m_height; return m_width / m_height;
} }

View File

@@ -42,6 +42,7 @@ namespace omath::collision
return ray.end; return ray.end;
const auto q = t.cross(side_a); const auto q = t.cross(side_a);
// ReSharper disable once CppTooWideScopeInitStatement
const auto v = ray_dir.dot(q) * inv_det; 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)) if ((v < 0 && std::abs(v) > k_epsilon) || (u + v > 1 && std::abs(u + v - 1) > k_epsilon))

View File

@@ -27,7 +27,7 @@ namespace omath::iw_engine
} }
Mat4X4 Camera::calc_projection_matrix() const 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); m_near_plane_distance, m_far_plane_distance);
} }
} // namespace omath::iw_engine } // namespace omath::iw_engine

View File

@@ -27,7 +27,7 @@ namespace omath::opengl_engine
} }
Mat4X4 Camera::calc_projection_matrix() const 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); m_near_plane_distance, m_far_plane_distance);
} }
} // namespace omath::opengl_engine } // namespace omath::opengl_engine

View File

@@ -29,7 +29,7 @@ namespace omath::source_engine
Mat4X4 Camera::calc_projection_matrix() const 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); m_near_plane_distance, m_far_plane_distance);
} }
} // namespace omath::source_engine } // namespace omath::source_engine

View File

@@ -21,7 +21,7 @@ namespace omath::unity_engine
} }
Mat4X4 Camera::calc_projection_matrix() const 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); m_near_plane_distance, m_far_plane_distance);
} }
} // namespace omath::unity_engine } // namespace omath::unity_engine

View File

@@ -38,13 +38,13 @@ namespace omath::pathfinding
return path; return path;
} }
auto Astar::get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list, auto Astar::get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list,
const Vector3<float>& endVertex) const Vector3<float>& end_vertex)
{ {
return std::ranges::min_element(open_list, 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 fa = a.second.g_cost + a.first.distance_to(end_vertex);
const float fb = b.second.g_cost + b.first.distance_to(endVertex); const float fb = b.second.g_cost + b.first.distance_to(end_vertex);
return fa < fb; return fa < fb;
}); });
} }
@@ -86,6 +86,7 @@ namespace omath::pathfinding
const float tentative_g_cost = current_node.g_cost + neighbor.distance_to(current); 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); const auto open_it = open_list.find(neighbor);
if (open_it == open_list.end() || tentative_g_cost < open_it->second.g_cost) if (open_it == open_list.end() || tentative_g_cost < open_it->second.g_cost)

View File

@@ -96,7 +96,7 @@ TEST_F(UnitTestMat, Operator_Division_Scalar)
// Test matrix functions // Test matrix functions
TEST_F(UnitTestMat, Transpose) 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, 0), m2.at(0, 0));
EXPECT_FLOAT_EQ(m3.at(0, 1), m2.at(1, 0)); EXPECT_FLOAT_EQ(m3.at(0, 1), m2.at(1, 0));
EXPECT_FLOAT_EQ(m3.at(1, 0), m2.at(0, 1)); EXPECT_FLOAT_EQ(m3.at(1, 0), m2.at(0, 1));
@@ -105,7 +105,7 @@ TEST_F(UnitTestMat, Transpose)
TEST_F(UnitTestMat, Determinant) TEST_F(UnitTestMat, Determinant)
{ {
const float det = m2.Determinant(); const float det = m2.determinant();
EXPECT_FLOAT_EQ(det, -2.0f); EXPECT_FLOAT_EQ(det, -2.0f);
} }
@@ -175,7 +175,7 @@ TEST_F(UnitTestMat, Method_At_OutOfRange)
// Test Determinant for 3x3 matrix // Test Determinant for 3x3 matrix
TEST(UnitTestMatStandalone, Determinant_3x3) 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); EXPECT_FLOAT_EQ(det, -306.0f);
} }
@@ -196,7 +196,7 @@ TEST(UnitTestMatStandalone, Strip_3x3)
TEST(UnitTestMatStandalone, Transpose_NonSquare) TEST(UnitTestMatStandalone, Transpose_NonSquare)
{ {
constexpr Mat<2, 3> m{{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}}; 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.row_count(), 3);
EXPECT_EQ(transposed.columns_count(), 2); EXPECT_EQ(transposed.columns_count(), 2);
EXPECT_FLOAT_EQ(transposed.at(0, 0), 1.0f); EXPECT_FLOAT_EQ(transposed.at(0, 0), 1.0f);