From 5c682330041f6e32d8ab6c0201b4351b4dcb993b Mon Sep 17 00:00:00 2001 From: Moses Turner Date: Tue, 29 Nov 2022 03:11:05 -0600 Subject: [PATCH] Add test for m_vec3_angle --- tests/CMakeLists.txt | 2 ++ tests/tests_vec3_angle.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/tests_vec3_angle.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3812a7f6a..662512d07 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,6 +27,7 @@ set(tests tests_vector tests_worker tests_pose + tests_vec3_angle ) if(XRT_HAVE_D3D11) list(APPEND tests tests_aux_d3d_d3d11 tests_comp_client_d3d11) @@ -68,6 +69,7 @@ target_link_libraries(tests_rational PRIVATE aux_math) target_link_libraries(tests_pose PRIVATE aux_math) target_link_libraries(tests_quat_change_of_basis PRIVATE aux_math) target_link_libraries(tests_quat_swing_twist PRIVATE aux_math) +target_link_libraries(tests_vec3_angle PRIVATE aux_math) target_include_directories(tests_quat_change_of_basis SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR}) target_include_directories(tests_quat_swing_twist SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR}) diff --git a/tests/tests_vec3_angle.cpp b/tests/tests_vec3_angle.cpp new file mode 100644 index 000000000..32c248887 --- /dev/null +++ b/tests/tests_vec3_angle.cpp @@ -0,0 +1,20 @@ +// Copyright 2022, Collabora, Inc. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Test for m_vec3_angle. + * @author Moses Turner + */ +#include "xrt/xrt_defines.h" +#include + + +#include "catch/catch.hpp" + +TEST_CASE("Vec3Angle") +{ + float sqrt2_2 = sqrtf(2) / 2; + CHECK(m_vec3_angle({1, 0, 0}, {-1, 0, 0}) == Approx(M_PI)); + CHECK(m_vec3_angle({1, 0, 0}, {0, 1, 0}) == Approx(M_PI / 2)); + CHECK(m_vec3_angle({1, 0, 0}, {sqrt2_2, sqrt2_2, 0}) == Approx(M_PI / 4)); +}