From 4fd7f8efa6e4e8769a6bf4c8bcad3cea5ef8cfc0 Mon Sep 17 00:00:00 2001 From: Orange Date: Fri, 19 Dec 2025 23:49:54 +0300 Subject: [PATCH] replaced numeric limits --- include/omath/projection/camera.hpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index 1d1994f..c4e094b 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -230,17 +230,14 @@ namespace omath::projection auto projected = get_view_projection_matrix() * mat_column_from_vector(world_position); - constexpr float w_epsilon = 1e-6f; - const auto w = projected.at(3, 0); - if (w <= w_epsilon) { + const auto& w = projected.at(3, 0); + if (w <= std::numeric_limits::epsilon()) return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS); - } projected /= w; - if (is_ndc_out_of_bounds(projected)) { + if (is_ndc_out_of_bounds(projected)) return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS); - } return Vector3{projected.at(0, 0), projected.at(1, 0), projected.at(2, 0)}; } @@ -249,29 +246,28 @@ namespace omath::projection { const auto inv_view_proj = get_view_projection_matrix().inverted(); - if (!inv_view_proj) { + if (!inv_view_proj) return std::unexpected(Error::INV_VIEW_PROJ_MAT_DET_EQ_ZERO); - } auto inverted_projection = inv_view_proj.value() * mat_column_from_vector(ndc); - constexpr float w_epsilon = 1e-6f; - const auto w = inverted_projection.at(3, 0); - if (std::abs(w) < w_epsilon) { + const auto& w = inverted_projection.at(3, 0); + + if (std::abs(w) < std::numeric_limits::epsilon()) return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS); - } inverted_projection /= w; const Vector3 world_pos{inverted_projection.at(0, 0), inverted_projection.at(1, 0), - inverted_projection.at(2, 0)}; + inverted_projection.at(2, 0)}; // Validate that the computed world position is reasonable constexpr float max_reasonable_component = 1e6f; - if (!std::isfinite(world_pos.x) || !std::isfinite(world_pos.y) - || !std::isfinite(world_pos.z) || std::abs(world_pos.x) > max_reasonable_component - || std::abs(world_pos.y) > max_reasonable_component || std::abs(world_pos.z) > max_reasonable_component) { + if (!std::isfinite(world_pos.x) || !std::isfinite(world_pos.y) || !std::isfinite(world_pos.z) + || std::abs(world_pos.x) > max_reasonable_component || std::abs(world_pos.y) > max_reasonable_component + || std::abs(world_pos.z) > max_reasonable_component) + { return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS); }