From eb1ca6055b2e29a77135ecf26b1b99c8908cf5c4 Mon Sep 17 00:00:00 2001 From: Orange Date: Sat, 21 Mar 2026 16:15:48 +0300 Subject: [PATCH] added additional error code --- include/omath/projection/camera.hpp | 15 ++++++++++++--- include/omath/projection/error_codes.hpp | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index 0848f81..ed7d3e5 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -294,12 +294,21 @@ namespace omath::projection * mat_column_from_vector(world_position); const auto& w = projected.at(3, 0); - if (w <= std::numeric_limits::epsilon()) - return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS); + constexpr auto eps = std::numeric_limits::epsilon(); + if (w <= eps) + return std::unexpected(Error::PERSPECTIVE_DIVIDER_LESS_EQ_ZERO); projected /= w; - if (clipping == ViewPortClipping::AUTO && is_ndc_out_of_bounds(projected)) + // ReSharper disable once CppTooWideScope + const auto clipped_automatically = clipping == ViewPortClipping::AUTO && is_ndc_out_of_bounds(projected); + if (clipped_automatically) + return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS); + + // ReSharper disable once CppTooWideScope + const auto clipped_manually = clipping == ViewPortClipping::MANUAL && (projected.at(2, 0) < 0.0f - eps + || projected.at(2, 0) > 1.0f + eps); + if (clipped_manually) 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)}; diff --git a/include/omath/projection/error_codes.hpp b/include/omath/projection/error_codes.hpp index 0129af2..099e8e6 100644 --- a/include/omath/projection/error_codes.hpp +++ b/include/omath/projection/error_codes.hpp @@ -11,5 +11,6 @@ namespace omath::projection { WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS, INV_VIEW_PROJ_MAT_DET_EQ_ZERO, + PERSPECTIVE_DIVIDER_LESS_EQ_ZERO, }; } \ No newline at end of file