From 0bd9eda48fa24f8e309860ad84117c7c389f77c2 Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 12 Aug 2025 09:12:57 +0300 Subject: [PATCH] Introduces CameraEngine concept Adds a concept `CameraEngineConcept` to ensure that camera engine implementations provide the necessary functions with the correct signatures and `noexcept` specifications. This enables compile-time checks for valid camera engine implementations, improving code reliability and preventing runtime errors. --- include/omath/projection/camera.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index 79eb191..76b07d8 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -26,7 +26,23 @@ namespace omath::projection }; using FieldOfView = Angle; + template + concept CameraEngineConcept = + requires(const Vector3& cam_origin, const Vector3& look_at, const ViewAnglesType& angles, + const FieldOfView& fov, const ViewPort& viewport, float znear, float zfar) { + // Presence + return types + { T::calc_look_at_angle(cam_origin, look_at) } -> std::same_as; + { T::calc_view_matrix(angles, cam_origin) } -> std::same_as; + { T::calc_projection_matrix(fov, viewport, znear, zfar) } -> std::same_as; + + // Enforce noexcept as in the trait declaration + requires noexcept(T::calc_look_at_angle(cam_origin, look_at)); + requires noexcept(T::calc_view_matrix(angles, cam_origin)); + requires noexcept(T::calc_projection_matrix(fov, viewport, znear, zfar)); + }; + template + requires CameraEngineConcept class Camera final { public: