From 2f518e5e28d35ae24a5ac0e31000835e43b01972 Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 14 Jun 2022 00:06:42 -0500 Subject: add cglm as 3rd-party library --- libs/cglm/test/CMakeLists.txt | 48 + libs/cglm/test/include/common.h | 159 ++++ libs/cglm/test/runner.c | 98 ++ libs/cglm/test/src/test_affine.h | 634 +++++++++++++ libs/cglm/test/src/test_affine2d.h | 310 ++++++ libs/cglm/test/src/test_affine_mat.h | 112 +++ libs/cglm/test/src/test_bezier.c | 66 ++ libs/cglm/test/src/test_cam.c | 55 ++ libs/cglm/test/src/test_cam_lh_no.c | 36 + libs/cglm/test/src/test_cam_lh_zo.c | 36 + libs/cglm/test/src/test_cam_rh_no.c | 36 + libs/cglm/test/src/test_cam_rh_zo.c | 36 + libs/cglm/test/src/test_camera.h | 68 ++ libs/cglm/test/src/test_clamp.c | 31 + libs/cglm/test/src/test_common.c | 341 +++++++ libs/cglm/test/src/test_common.h | 118 +++ libs/cglm/test/src/test_euler.c | 45 + libs/cglm/test/src/test_ivec2.h | 189 ++++ libs/cglm/test/src/test_ivec3.h | 199 ++++ libs/cglm/test/src/test_ivec4.h | 214 +++++ libs/cglm/test/src/test_mat2.h | 286 ++++++ libs/cglm/test/src/test_mat3.h | 311 ++++++ libs/cglm/test/src/test_mat4.h | 488 ++++++++++ libs/cglm/test/src/test_plane.h | 39 + libs/cglm/test/src/test_project.h | 92 ++ libs/cglm/test/src/test_quat.h | 1086 +++++++++++++++++++++ libs/cglm/test/src/test_ray.h | 34 + libs/cglm/test/src/test_struct.c | 78 ++ libs/cglm/test/src/test_vec2.h | 625 ++++++++++++ libs/cglm/test/src/test_vec3.h | 1731 ++++++++++++++++++++++++++++++++++ libs/cglm/test/src/test_vec4.h | 1420 ++++++++++++++++++++++++++++ libs/cglm/test/src/tests.c | 63 ++ libs/cglm/test/tests.h | 1672 ++++++++++++++++++++++++++++++++ 33 files changed, 10756 insertions(+) create mode 100644 libs/cglm/test/CMakeLists.txt create mode 100644 libs/cglm/test/include/common.h create mode 100644 libs/cglm/test/runner.c create mode 100644 libs/cglm/test/src/test_affine.h create mode 100644 libs/cglm/test/src/test_affine2d.h create mode 100644 libs/cglm/test/src/test_affine_mat.h create mode 100644 libs/cglm/test/src/test_bezier.c create mode 100644 libs/cglm/test/src/test_cam.c create mode 100644 libs/cglm/test/src/test_cam_lh_no.c create mode 100644 libs/cglm/test/src/test_cam_lh_zo.c create mode 100644 libs/cglm/test/src/test_cam_rh_no.c create mode 100644 libs/cglm/test/src/test_cam_rh_zo.c create mode 100644 libs/cglm/test/src/test_camera.h create mode 100644 libs/cglm/test/src/test_clamp.c create mode 100644 libs/cglm/test/src/test_common.c create mode 100644 libs/cglm/test/src/test_common.h create mode 100644 libs/cglm/test/src/test_euler.c create mode 100644 libs/cglm/test/src/test_ivec2.h create mode 100644 libs/cglm/test/src/test_ivec3.h create mode 100644 libs/cglm/test/src/test_ivec4.h create mode 100644 libs/cglm/test/src/test_mat2.h create mode 100644 libs/cglm/test/src/test_mat3.h create mode 100644 libs/cglm/test/src/test_mat4.h create mode 100644 libs/cglm/test/src/test_plane.h create mode 100644 libs/cglm/test/src/test_project.h create mode 100644 libs/cglm/test/src/test_quat.h create mode 100644 libs/cglm/test/src/test_ray.h create mode 100644 libs/cglm/test/src/test_struct.c create mode 100644 libs/cglm/test/src/test_vec2.h create mode 100644 libs/cglm/test/src/test_vec3.h create mode 100644 libs/cglm/test/src/test_vec4.h create mode 100644 libs/cglm/test/src/tests.c create mode 100644 libs/cglm/test/tests.h (limited to 'libs/cglm/test') diff --git a/libs/cglm/test/CMakeLists.txt b/libs/cglm/test/CMakeLists.txt new file mode 100644 index 0000000..26fef9c --- /dev/null +++ b/libs/cglm/test/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.8.2) + +# List all files containing tests. (Change as needed) +set(TESTFILES + runner.c + src/test_euler.c + src/test_bezier.c + src/test_cam.c + src/test_cam_lh_zo.c + src/test_cam_rh_zo.c + src/test_cam_lh_no.c + src/test_cam_rh_no.c + src/test_struct.c + src/test_clamp.c + src/test_common.c + src/tests.c + ) + +set(TEST_MAIN tests) +set(TEST_RUNNER_PARAMS "") + +add_executable(${TEST_MAIN} ${TESTFILES}) +target_compile_definitions(${TEST_MAIN} PRIVATE CGLM_DEFINE_PRINTS=1) + +if(NOT MSVC) + target_link_libraries(${TEST_MAIN} PRIVATE m) +endif() + +target_link_libraries(${TEST_MAIN} PRIVATE cglm) +target_include_directories(${TEST_MAIN} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/include + ${CMAKE_CURRENT_LIST_DIR}/src + ) + +set_target_properties(${TEST_MAIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) + +if(LDFLAGS) + target_compile_options(${TEST_MAIN} PRIVATE ${LDFLAGS}) +endif() + +add_test( + NAME cglm.${TEST_MAIN} + COMMAND ${TEST_MAIN} ${TEST_RUNNER_PARAMS}) + +add_custom_target(check + make + COMMAND ${CMAKE_CTEST_COMMAND} -V + DEPENDS cglm) diff --git a/libs/cglm/test/include/common.h b/libs/cglm/test/include/common.h new file mode 100644 index 0000000..2eb2e83 --- /dev/null +++ b/libs/cglm/test/include/common.h @@ -0,0 +1,159 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef tests_common_h +#define tests_common_h + +#ifndef _USE_MATH_DEFINES +# define _USE_MATH_DEFINES /* for windows */ +#endif + +#ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS /* for windows */ +#endif + +#ifndef _GNU_SOURCE +# define _GNU_SOURCE /* for drand48() */ +#endif + +#ifndef CGLM_CLIPSPACE_INCLUDE_ALL +# define CGLM_CLIPSPACE_INCLUDE_ALL +#endif + +#include +#include +#include + +#include +#include +#include + +typedef struct test_status_t { + const char *msg; + int status; +} test_status_t; + +typedef test_status_t (*fntest)(void); + +typedef struct test_entry_t { + char *name; + fntest entry; + int ret; + int show_output; +} test_entry_t; + +#ifndef GLM_TESTS_NO_COLORFUL_OUTPUT + +#define RESET "\033[0m" +#define BLACK "\033[30m" /* Black */ +#define RED "\033[31m" /* Red */ +#define GREEN "\033[32m" /* Green */ +#define YELLOW "\033[33m" /* Yellow */ +#define BLUE "\033[34m" /* Blue */ +#define MAGENTA "\033[35m" /* Magenta */ +#define CYAN "\033[36m" /* Cyan */ +#define WHITE "\033[37m" /* White */ +#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ +#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ + +#else + +#define RESET +#define BLACK +#define RED +#define GREEN +#define YELLOW +#define BLUE +#define MAGENTA +#define CYAN +#define WHITE +#define BOLDBLACK +#define BOLDRED +#define BOLDGREEN +#define BOLDYELLOW +#define BOLDBLUE +#define BOLDMAGENTA +#define BOLDCYAN +#define BOLDWHITE + +#endif + +#define TEST_DECLARE(FUN) test_status_t test_ ## FUN(void); +#define TEST_ENTRY(FUN) { #FUN, test_ ## FUN, 0, 0 }, +#define TEST_LIST static test_entry_t tests[] = + +/* __VA_ARGS__ workaround for MSVC: https://stackoverflow.com/a/5134656 */ +#define EXPAND(x) x + +#define TEST_OK 1 +#define TEST_SUCCESS return (test_status_t){NULL, TEST_OK}; + +#define TEST_IMPL_ARG1(FUN) \ + test_status_t test_ ## FUN (void); \ + test_status_t test_ ## FUN() + +#define TEST_IMPL_ARG2(PREFIX, FUN) TEST_IMPL_ARG1(PREFIX ## FUN) +#define TEST_IMPL_ARG3(arg1, arg2, arg3, ...) arg3 + +#define TEST_IMPL_CHOOSER(...) \ + EXPAND(TEST_IMPL_ARG3(__VA_ARGS__, TEST_IMPL_ARG2, TEST_IMPL_ARG1)) + +#define TEST_IMPL(...) EXPAND(TEST_IMPL_CHOOSER(__VA_ARGS__)(__VA_ARGS__)) + +#define ASSERT_EXT(expr, msg) \ + if (!(expr)) { \ + fprintf(stderr, \ + RED " assert fail" RESET \ + " in " BOLDCYAN "%s " RESET \ + "on " BOLDMAGENTA "line %d" RESET \ + " : " BOLDWHITE " ASSERT(%s)\n" RESET, \ + __FILE__, \ + __LINE__, \ + #expr); \ + return (test_status_t){msg, 0}; \ + } + +#define ASSERT_ARG1(expr) ASSERT_EXT(expr, NULL) +#define ASSERT_ARG2(expr, msg) ASSERT_EXT(expr, msg) +#define ASSERT_ARG3(arg1, arg2, arg3, ...) arg3 + +#define ASSERT_CHOOSER(...) ASSERT_ARG3(__VA_ARGS__, ASSERT_ARG2, ASSERT_ARG1) +#define ASSERT(...) do { ASSERT_CHOOSER(__VA_ARGS__)(__VA_ARGS__) } while(0); +#define ASSERTIFY(expr) do { \ + test_status_t ts; \ + ts = expr; \ + if (ts.status != TEST_OK) { \ + fprintf(stderr, \ + RED " assert fail" RESET \ + " in " BOLDCYAN "%s " RESET \ + "on " BOLDMAGENTA "line %d" RESET \ + " : " BOLDWHITE " ASSERTIFY(%s)\n" RESET, \ + __FILE__, \ + __LINE__, \ + #expr); \ + return (test_status_t){ts.msg, 0}; \ + } \ + } while(0); + +#if defined(_WIN32) +# define drand48() ((float)(rand() / (RAND_MAX + 1.0))) +# define OK_TEXT "ok:" +# define FAIL_TEXT "fail:" +# define FINAL_TEXT "^_^" +#else +# define OK_TEXT "✔︎" +# define FAIL_TEXT "𐄂" +# define FINAL_TEXT "🎉" +#endif + +#endif /* common_h */ diff --git a/libs/cglm/test/runner.c b/libs/cglm/test/runner.c new file mode 100644 index 0000000..e74d5e7 --- /dev/null +++ b/libs/cglm/test/runner.c @@ -0,0 +1,98 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "include/common.h" +#include "tests.h" + +#include +#include +#include + +int +main(int argc, const char * argv[]) { + test_entry_t *entry; + test_status_t st; + int32_t i, count, passed, failed, maxlen; + double start, end, elapsed, total; + (void)argc; + (void)argv; + + passed = failed = maxlen = 0; + total = 0.0; + count = sizeof(tests) / sizeof(tests[0]); + + fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET); + + srand((unsigned int)time(NULL)); + + for (i = 0; i < count; i++) { + int32_t len; + + entry = tests + i; + len = (int32_t)strlen(entry->name); + + maxlen = GLM_MAX(maxlen, len); + } + + maxlen += 5; + + fprintf(stderr, + BOLDWHITE " %-*s %-*s\n", + maxlen, "Test Name", maxlen, "Elapsed Time"); + + for (i = 0; i < count; i++) { + entry = tests + i; + start = clock(); + st = entry->entry(); + end = clock(); + elapsed = (end - start) / CLOCKS_PER_SEC; + total += elapsed; + + if (!st.status) { + fprintf(stderr, + BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name); + if (st.msg) { + fprintf(stderr, + YELLOW "- %s" RESET, + st.msg); + } + + fprintf(stderr, "\n"); + + failed++; + } else { + fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name); + + if (elapsed > 0.01) + fprintf(stderr, YELLOW "%.2fs", elapsed); + else + fprintf(stderr, "0"); + + fprintf(stderr, "\n" RESET); + passed++; + } + } + + if (failed == 0) { + fprintf(stderr, + BOLDGREEN "\n All tests passed " FINAL_TEXT "\n" RESET); + } + + fprintf(stderr, + CYAN "\ncglm test results (%0.2fs):\n" RESET + "--------------------------\n" + + MAGENTA "%d" RESET " tests ran, " + GREEN "%d" RESET " passed, " + RED "%d" RESET " failed\n\n" RESET, + total, + count, + passed, + failed); + + return failed; +} diff --git a/libs/cglm/test/src/test_affine.h b/libs/cglm/test/src/test_affine.h new file mode 100644 index 0000000..2199a43 --- /dev/null +++ b/libs/cglm/test/src/test_affine.h @@ -0,0 +1,634 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, translate) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate)(m1, (vec3){13.0f, 11.0f, 7.0f}); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 10.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate)(m1, (vec3){1.0f, -1.0f, -5.0f}); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 12.0f)) + ASSERT(test_eq(v2[2], 5.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_to) { + mat4 m1, m2; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_to)(m1, (vec3){13.0f, 11.0f, 7.0f}, m2); + glm_mat4_mulv(m2, v1, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 10.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_to)(m1, (vec3){1.0f, -1.0f, -5.0f}, m2); + glm_mat4_mulv(m2, v2, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 12.0f)) + ASSERT(test_eq(v2[2], 5.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_x) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_x)(m1, 13.0f); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 2.0f)) + ASSERT(test_eq(v2[2], 3.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_x)(m1, -1.0f); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 2.0f)) + ASSERT(test_eq(v2[2], 3.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_y) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_y)(m1, 11.0f); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 3.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_y)(m1, -1.0f); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 12.0f)) + ASSERT(test_eq(v2[2], 3.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_z) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_z)(m1, 7.0f); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 2.0f)) + ASSERT(test_eq(v2[2], 10.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_z)(m1, -5.0f); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 2.0f)) + ASSERT(test_eq(v2[2], 5.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_make) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_make)(m1, (vec3){13.0f, 11.0f, 7.0f}); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 10.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_make)(m1, (vec3){1.0f, -1.0f, -5.0f}); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 12.0f)) + ASSERT(test_eq(v2[2], 5.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale_to) { + mat4 m1, m2; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(scale_to)(m1, (vec3){13.0f, 11.0f, 7.0f}, m2); + glm_mat4_mulv(m2, v1, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 22.0f)) + ASSERT(test_eq(v2[2], 21.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(scale_to)(m1, (vec3){1.0f, -1.0f, -5.0f}, m2); + glm_mat4_mulv(m2, v2, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], -22.0f)) + ASSERT(test_eq(v2[2], -105.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale_make) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + GLM(scale_make)(m1, (vec3){13.0f, 11.0f, 7.0f}); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 22.0f)) + ASSERT(test_eq(v2[2], 21.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + GLM(scale_make)(m1, (vec3){1.0f, -1.0f, -5.0f}); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], -22.0f)) + ASSERT(test_eq(v2[2], -105.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(scale)(m1, (vec3){13.0f, 11.0f, 7.0f}); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 22.0f)) + ASSERT(test_eq(v2[2], 21.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(scale)(m1, (vec3){1.0f, -1.0f, -5.0f}); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], -22.0f)) + ASSERT(test_eq(v2[2], -105.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale_uni) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(scale_uni)(m1, 13.0f); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 26.0f)) + ASSERT(test_eq(v2[2], 39.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(scale_uni)(m1, -5.0f); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], -65.0f)) + ASSERT(test_eq(v2[1], -130.0f)) + ASSERT(test_eq(v2[2], -195.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_x) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {0.0f, 1.0f, 0.0f, 1.0f}, v2 = {0.0f, 1.0f, 0.0f, 1.0f}; + + GLM(rotate_x)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_x)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_x)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_y) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}, v2 = {1.0f, 0.0f, 0.0f, 1.0f}; + + GLM(rotate_y)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_y)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_y)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_z) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {0.0f, 1.0f, 0.0f, 1.0f}, v2 = {0.0f, 1.0f, 0.0f, 1.0f}; + + GLM(rotate_z)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_z)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_z)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_make) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + /* rotate X around Y = -Z */ + GLM(rotate_make)(m1, GLM_PI_2f, GLM_YUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + GLM(rotate_make)(m1, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around X = +Z */ + GLM(rotate_make)(m1, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT, m2 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + /* 360 deg */ + glm_rotate(m1, GLM_PI_2f, GLM_YUP); + glm_rotate(m1, GLM_PI_2f, GLM_YUP); + glm_rotate(m1, GLM_PI_2f, GLM_YUP); + glm_rotate(m1, GLM_PI_2f, GLM_YUP); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + + /* rotate X around Y = -Z */ + GLM(rotate)(m1, GLM_PI_2f, GLM_YUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + glm_mat4_identity(m1); + + /* rotate -Z around X = Y */ + GLM(rotate)(m1, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_mat4_identity(m1); + + /* rotate Y around X = +Z */ + GLM(rotate)(m1, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_at) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + GLM(rotate_at)(m1, (vec3){0.5f, 0.0f, 0.0f}, GLM_PI_2f, GLM_YUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.5f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_mat4_identity(m1); + + GLM(rotate_at)(m1, GLM_VEC3_ZERO, GLM_PI_2f, GLM_ZUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.5f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_mat4_identity(m1); + + v1[0] = 1.0f; + v1[1] = 1.0f; + v1[2] = 1.0f; + + GLM(rotate_at)(m1, GLM_VEC3_ZERO, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_atm) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + GLM(rotate_atm)(m1, (vec3){0.5f, 0.0f, 0.0f}, GLM_PI_2f, GLM_YUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.5f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -0.5f)) + + GLM(rotate_atm)(m1, GLM_VEC3_ZERO, GLM_PI_2f, GLM_ZUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.5f)) + ASSERT(test_eq(v1[2], -0.5f)) + + v1[0] = 1.0f; + v1[1] = 1.0f; + v1[2] = 1.0f; + + GLM(rotate_atm)(m1, GLM_VEC3_ZERO, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, decompose_scalev) { + mat4 m1; + vec3 s1; + + GLM(scale_make)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose_scalev)(m1, s1); + + ASSERT(test_eq(s1[0], 7.0f)) + ASSERT(test_eq(s1[1], 8.0f)) + ASSERT(test_eq(s1[2], 9.0f)) + + GLM(scale)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose_scalev)(m1, s1); + + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + + glm_translate(m1, (vec3){4.0f, 5.0f, 6.0f}); + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, uniscaled) { + mat4 m1; + + GLM(scale_make)(m1, (vec3){7.0f, 8.0f, 9.0f}); + ASSERT(!GLM(uniscaled)(m1)) + + GLM(scale_make)(m1, (vec3){7.0f, 7.0f, 7.0f}); + ASSERT(GLM(uniscaled)(m1)) + + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + ASSERT(GLM(uniscaled)(m1)) + + glm_translate(m1, (vec3){4.0f, 5.0f, 6.0f}); + ASSERT(GLM(uniscaled)(m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, decompose_rs) { + mat4 m1, m2, r; + vec3 s1; + + GLM(scale_make)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose_rs)(m1, r, s1); + + ASSERT(test_eq(s1[0], 7.0f)) + ASSERT(test_eq(s1[1], 8.0f)) + ASSERT(test_eq(s1[2], 9.0f)) + ASSERTIFY(test_assert_mat4_eq_identity(r)); + + GLM(scale)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose_rs)(m1, r, s1); + + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + ASSERTIFY(test_assert_mat4_eq_identity(r)); + + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + GLM(decompose_rs)(m1, r, s1); + + glm_mat4_identity(m2); + glm_mat4_mul(m2, r, m2); + glm_scale(m2, s1); + + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00001f)); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, decompose) { + mat4 m1, m2, r; + vec4 t; + vec3 s; + + GLM(scale_make)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose)(m1, t, r, s); + + ASSERT(test_eq(s[0], 7.0f)) + ASSERT(test_eq(s[1], 8.0f)) + ASSERT(test_eq(s[2], 9.0f)) + ASSERTIFY(test_assert_mat4_eq_identity(r)); + + GLM(scale)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose)(m1, t, r, s); + + ASSERT(test_eq(s[0], 49.0f)) + ASSERT(test_eq(s[1], 64.0f)) + ASSERT(test_eq(s[2], 81.0f)) + ASSERTIFY(test_assert_mat4_eq_identity(r)); + + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + ASSERT(test_eq(s[0], 49.0f)) + ASSERT(test_eq(s[1], 64.0f)) + ASSERT(test_eq(s[2], 81.0f)) + GLM(decompose)(m1, t, r, s); + + glm_mat4_identity(m2); + glm_mat4_mul(m2, r, m2); + glm_scale(m2, s); + + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00001f)); + + glm_mat4_identity(m1); + glm_translate(m1, (vec3){56.0f, 13.0f, 90.0f}); + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + glm_scale(m1, (vec3){12.0f, 34.0f, 23.0f}); + + GLM(decompose)(m1, t, r, s); + + ASSERT(test_eq(t[0], 56.0f)) + ASSERT(test_eq(t[1], 13.0f)) + ASSERT(test_eq(t[2], 90.0f)) + + ASSERT(test_eq(s[0], 12.0f)) + ASSERT(test_eq(s[1], 34.0f)) + ASSERT(test_eq(s[2], 23.0f)) + + glm_mat4_identity(m2); + glm_translate(m2, t); + glm_mat4_mul(m2, r, m2); + glm_scale(m2, s); + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00001f)); + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_affine2d.h b/libs/cglm/test/src/test_affine2d.h new file mode 100644 index 0000000..8828661 --- /dev/null +++ b/libs/cglm/test/src/test_affine2d.h @@ -0,0 +1,310 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, translate2d) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d)(m1, (vec2){13.0f, 11.0f}); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 14.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d)(m1, (vec2){1.0f, -1.0f}); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 16.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate2d_to) { + mat3 m1, m2; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d_to)(m1, (vec2){13.0f, 11.0f}, m2); + glm_mat3_mulv(m2, v1, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 14.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d_to)(m1, (vec2){1.0f, -1.0f}, m2); + glm_mat3_mulv(m2, v2, v2); + + ASSERT(test_eq(v2[0], 16.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate2d_x) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d_x)(m1, 13.0f); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 3.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d_x)(m1, -1.0f); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 3.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate2d_y) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d_y)(m1, 11.0f); + glm_mat3_mulv(m1, v1, v2); + + + ASSERT(test_eq(v2[0], 2.0f)) + ASSERT(test_eq(v2[1], 14.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d_y)(m1, -1.0f); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 2.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate2d_make) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d_make)(m1, (vec2){13.0f, 11.0f}); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 14.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d_make)(m1, (vec2){-1.0f, -5.0f}); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 9.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale2d_to) { + mat3 m1, m2; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(scale2d_to)(m1, (vec2){13.0f, 11.0f}, m2); + glm_mat3_mulv(m2, v1, v2); + + ASSERT(test_eq(v2[0], 26.0f)) + ASSERT(test_eq(v2[1], 33.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(scale2d_to)(m1, (vec2){-1.0f, -5.0f}, m2); + glm_mat3_mulv(m2, v2, v2); + + ASSERT(test_eq(v2[0], -26.0f)) + ASSERT(test_eq(v2[1], -165.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale2d_make) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + GLM(scale2d_make)(m1, (vec2){13.0f, 11.0f}); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 26.0f)) + ASSERT(test_eq(v2[1], 33.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + GLM(scale2d_make)(m1, (vec3){-1.0f, -5.0f}); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], -26.0f)) + ASSERT(test_eq(v2[1], -165.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale2d) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(scale2d)(m1, (vec2){13.0f, 11.0f}); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 26.0f)) + ASSERT(test_eq(v2[1], 33.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(scale2d)(m1, (vec2){-1.0f, -5.0f}); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], -26.0f)) + ASSERT(test_eq(v2[1], -165.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale2d_uni) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(scale2d_uni)(m1, 13.0f); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 26.0f)) + ASSERT(test_eq(v2[1], 39.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(scale2d_uni)(m1, -5.0f); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], -130.0f)) + ASSERT(test_eq(v2[1], -195.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate2d_make) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + vec3 v1 = {0.0f, 1.0f, 1.0f}, v2 = {0.0f, 1.0f, 1.0f}; + + GLM(rotate2d_make)(m1, GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d_make)(m1, -GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d_make)(m1, GLM_PIf); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate2d) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + vec3 v1 = {0.0f, 1.0f, 1.0f}, v2 = {0.0f, 1.0f, 1.0f}; + + GLM(rotate2d)(m1, GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d)(m1, GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d)(m1, GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate2d_to) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT, m2; + vec3 v1 = {0.0f, 1.0f, 1.0f}, v2 = {0.0f, 1.0f, 1.0f}; + + GLM(rotate2d_to)(m1, GLM_PI_2f, m1); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d_to)(m1, GLM_PI_2f, m2); + glm_mat3_mulv(m2, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d_to)(m2, GLM_PI_2f, m1); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_affine_mat.h b/libs/cglm/test/src/test_affine_mat.h new file mode 100644 index 0000000..e928f8e --- /dev/null +++ b/libs/cglm/test/src/test_affine_mat.h @@ -0,0 +1,112 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#ifndef glm_affine_mat_test_guard +#define glm_affine_mat_test_guard +CGLM_INLINE +void +glm_inv_tr_raw(mat4 mat) { + CGLM_ALIGN_MAT mat3 r; + CGLM_ALIGN(8) vec3 t; + + /* rotate */ + glm_mat4_pick3t(mat, r); + glm_mat4_ins3(r, mat); + + /* translate */ + glm_mat3_mulv(r, mat[3], t); + glm_vec3_negate(t); + glm_vec3_copy(t, mat[3]); +} +#endif + +TEST_IMPL(GLM_PREFIX, mul) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + mat4 m3; + mat4 m4 = GLM_MAT4_ZERO_INIT; + int i, j, k; + + test_rand_mat4(m1); + test_rand_mat4(m2); + + GLM(mul)(m1, m2, m3); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + /* test pre compiled */ + GLM(mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mul_rot) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + mat4 m3; + mat4 m4 = GLM_MAT4_ZERO_INIT; + int i, j, k; + + glm_rotate(m1, drand48(), (vec3){drand48(), drand48(), drand48()}); + glm_rotate(m2, drand48(), (vec3){drand48(), drand48(), drand48()}); + + GLM(mul_rot)(m1, m2, m3); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + /* test pre compiled */ + GLM(mul_rot)(m1, m2, m3); + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, inv_tr) { + mat4 m1, m2; + int i; + + for (i = 0; i < 10000; i++) { + test_rand_mat4(m1); + + glm_mat4_copy(m1, m2); + + /* test inverse precise */ + GLM(inv_tr)(m1); + GLM(inv_tr)(m1); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + + /* test inverse precise */ + GLM(mat4_inv)(m1, m2); + GLM(inv_tr)(m2); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + + /* test with raw */ + glm_mat4_copy(m1, m2); + glm_inv_tr_raw(m2); + GLM(inv_tr)(m1); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + } + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_bezier.c b/libs/cglm/test/src/test_bezier.c new file mode 100644 index 0000000..3089dd5 --- /dev/null +++ b/libs/cglm/test/src/test_bezier.c @@ -0,0 +1,66 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +CGLM_INLINE +float +test_bezier_plain(float s, float p0, float c0, float c1, float p1) { + float x, xx, xxx, ss, sss; + + x = 1.0f - s; + xx = x * x; + xxx = xx * x; + ss = s * s; + sss = ss * s; + + return p0 * xxx + 3.0f * (c0 * s * xx + c1 * ss * x) + p1 * sss; +} + +CGLM_INLINE +float +test_hermite_plain(float s, float p0, float t0, float t1, float p1) { + float ss, sss; + + ss = s * s; + sss = ss * s; + + return p0 * (2.0f * sss - 3.0f * ss + 1.0f) + + t0 * (sss - 2.0f * ss + s) + + p1 * (-2.0f * sss + 3.0f * ss) + + t1 * (sss - ss); +} + +TEST_IMPL(bezier) { + float s, p0, p1, c0, c1, smc, Bs, Bs_plain; + + s = test_rand(); + p0 = test_rand(); + p1 = test_rand(); + c0 = test_rand(); + c1 = test_rand(); + + /* test cubic bezier */ + smc = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}); + Bs = glm_bezier(s, p0, c0, c1, p1); + Bs_plain = test_bezier_plain(s, p0, c0, c1, p1); + + ASSERT(test_eq(Bs, Bs_plain)); + ASSERTIFY(test_assert_eqf(smc, Bs_plain)) + ASSERTIFY(test_assert_eqf(Bs, smc)) + + /* test cubic hermite */ + smc = glm_smc(s, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1}); + Bs = glm_hermite(s, p0, c0, c1, p1); + Bs_plain = test_hermite_plain(s, p0, c0, c1, p1); + + ASSERT(test_eq(Bs, Bs_plain)); + ASSERT(test_eq(smc, Bs_plain)); + ASSERT(test_eq(Bs, smc)); + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_cam.c b/libs/cglm/test/src/test_cam.c new file mode 100644 index 0000000..b5fbf2b --- /dev/null +++ b/libs/cglm/test/src/test_cam.c @@ -0,0 +1,55 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(camera_lookat) { + mat4 view1, view2; + vec3 center, + eye = {0.024f, 14.6f, 67.04f}, + dir = {0.0f, 0.0f, -1.0f}, + up = {0.0f, 1.0f, 0.0f}; + + glm_vec3_add(eye, dir, center); + glm_lookat(eye, center, up, view1); + + glm_look(eye, dir, up, view2); + + ASSERTIFY(test_assert_mat4_eq(view1, view2)) + + TEST_SUCCESS +} + +TEST_IMPL(camera_decomp) { + mat4 proj, proj2; + vec4 sizes; + float aspect, fovy, nearZ, farZ; + + aspect = 0.782f; + fovy = glm_rad(49.984f); + nearZ = 0.1f; + farZ = 100.0f; + + glm_perspective(fovy, aspect, nearZ, farZ, proj); + ASSERT(fabsf(aspect - glm_persp_aspect(proj)) < GLM_FLT_EPSILON) + ASSERT(fabsf(fovy - glm_persp_fovy(proj)) < GLM_FLT_EPSILON) + ASSERT(fabsf(49.984f - glm_deg(glm_persp_fovy(proj))) < GLM_FLT_EPSILON) + + glm_persp_sizes(proj, fovy, sizes); + + glm_frustum(-sizes[0] * 0.5f, + sizes[0] * 0.5f, + -sizes[1] * 0.5f, + sizes[1] * 0.5f, + nearZ, + farZ, + proj2); + + ASSERTIFY(test_assert_mat4_eq(proj, proj2)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_cam_lh_no.c b/libs/cglm/test/src/test_cam_lh_no.c new file mode 100644 index 0000000..33a285a --- /dev/null +++ b/libs/cglm/test/src/test_cam_lh_no.c @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(perspective_lh_no) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_lh_no(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], (zFarVal + zNearVal) / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], 1.0f)) + ASSERT(test_eq(dst[3][2], -2 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_lh_no*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = 1.0020020f; + cmp[2][3] = 1.0000000f; + cmp[3][2] = -0.2002002f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/libs/cglm/test/src/test_cam_lh_zo.c b/libs/cglm/test/src/test_cam_lh_zo.c new file mode 100644 index 0000000..f5f50af --- /dev/null +++ b/libs/cglm/test/src/test_cam_lh_zo.c @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(perspective_lh_zo) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_lh_zo(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], zFarVal / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], 1.0f)) + ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /* "Reference values" generated by GLM's glm::perspectiveLH_ZO */ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = 1.0010010f; + cmp[2][3] = 1.0000000f; + cmp[3][2] = -0.1001001f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/libs/cglm/test/src/test_cam_rh_no.c b/libs/cglm/test/src/test_cam_rh_no.c new file mode 100644 index 0000000..2bcadcd --- /dev/null +++ b/libs/cglm/test/src/test_cam_rh_no.c @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(perspective_rh_no) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_rh_no(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], -1.0f * (zFarVal + zNearVal) / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], -1.0f)) + ASSERT(test_eq(dst[3][2], -2 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_rh_no*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = -1.0020020f; + cmp[2][3] = -1.0000000f; + cmp[3][2] = -0.2002002f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/libs/cglm/test/src/test_cam_rh_zo.c b/libs/cglm/test/src/test_cam_rh_zo.c new file mode 100644 index 0000000..95281a7 --- /dev/null +++ b/libs/cglm/test/src/test_cam_rh_zo.c @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(perspective_rh_zo) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_rh_zo(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], zFarVal / (zNearVal - zFarVal))) + ASSERT(test_eq(dst[2][3], -1.0f)) + ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_rh_zo*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = -1.0010010f; + cmp[2][3] = -1.0000000f; + cmp[3][2] = -0.1001001f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/libs/cglm/test/src/test_camera.h b/libs/cglm/test/src/test_camera.h new file mode 100644 index 0000000..fb1075a --- /dev/null +++ b/libs/cglm/test/src/test_camera.h @@ -0,0 +1,68 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, frustum) { + mat4 proj; + vec4 vp = {0.0f, 0.0f, 800.0f, 600.0f}; + float left, right, top, bottom, znear, zfar; + + znear = 0.1f; + zfar = 100.0f; + left = -100.0f; + right = 100.0f; + bottom = -100.0f; + top = 100.0f; + + GLM(frustum)(left, right, bottom, top, znear, zfar, proj); + + ASSERT(test_eq(proj[0][1], 0.0f)) + ASSERT(test_eq(proj[0][2], 0.0f)) + ASSERT(test_eq(proj[0][3], 0.0f)) + + ASSERT(test_eq(proj[1][0], 0.0f)) + ASSERT(test_eq(proj[1][2], 0.0f)) + ASSERT(test_eq(proj[1][3], 0.0f)) + + ASSERT(test_eq(proj[2][3], -1.0f)) + + ASSERT(test_eq(proj[3][0], 0.0f)) + ASSERT(test_eq(proj[3][1], 0.0f)) + ASSERT(test_eq(proj[3][3], 0.0f)) + + vec4 v1 = {1.0f, 20.0f, znear}; + vec4 v2 = {1.0f, 20.0f, zfar}; + vec4 v3, v4; + + /* perspective test */ + GLM(mat4_mulv)(proj, v1, v3); + GLM(project)(v3, proj, vp, v3); + + ASSERT(v3[0] > v1[0]) + ASSERT(v3[1] > v1[1]) + + GLM(mat4_mulv)(proj, v2, v4); + GLM(project)(v4, proj, vp, v4); + + ASSERT(v4[0] < v3[0]) + ASSERT(v4[1] < v3[1]) + + /* not infinity */ + ASSERT(!GLM(vec4_isinf)(proj[0])) + ASSERT(!GLM(vec4_isinf)(proj[1])) + ASSERT(!GLM(vec4_isinf)(proj[2])) + ASSERT(!GLM(vec4_isinf)(proj[3])) + + /* not NaN */ + ASSERT(!GLM(vec4_isnan)(proj[0])) + ASSERT(!GLM(vec4_isnan)(proj[1])) + ASSERT(!GLM(vec4_isnan)(proj[2])) + ASSERT(!GLM(vec4_isnan)(proj[3])) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_clamp.c b/libs/cglm/test/src/test_clamp.c new file mode 100644 index 0000000..1d1c0c2 --- /dev/null +++ b/libs/cglm/test/src/test_clamp.c @@ -0,0 +1,31 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(clamp) { + vec3 v3 = {15.07f, 0.4f, 17.3f}; + vec4 v4 = {5.07f, 2.3f, 1.3f, 1.4f}; + + ASSERT(glm_clamp(1.6f, 0.0f, 1.0f) == 1.0f) + ASSERT(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f) + ASSERT(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f) + + glm_vec3_clamp(v3, 0.0, 1.0); + glm_vec4_clamp(v4, 1.5, 3.0); + + ASSERT(v3[0] == 1.0f) + ASSERT(v3[1] == 0.4f) + ASSERT(v3[2] == 1.0f) + + ASSERT(v4[0] == 3.0f) + ASSERT(v4[1] == 2.3f) + ASSERT(v4[2] == 1.5f) + ASSERT(v4[3] == 1.5f) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_common.c b/libs/cglm/test/src/test_common.c new file mode 100644 index 0000000..46b6e63 --- /dev/null +++ b/libs/cglm/test/src/test_common.c @@ -0,0 +1,341 @@ +/* + * Copyright (c), Recep Aslantas. + * MIT License (MIT), http://opensource.org/licenses/MIT + */ + +#include "test_common.h" +#include + +void +test_rand_mat4(mat4 dest) { + glm_mat4_copy(GLM_MAT4_IDENTITY, dest); + + /* random position */ + dest[3][0] = drand48(); + dest[3][1] = drand48(); + dest[3][2] = drand48(); + + /* random rotatation around random axis with random angle */ + glm_rotate(dest, drand48(), (vec3){drand48(), drand48(), drand48()}); + + /* random scale */ + /* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */ +} + +void +test_rand_mat3(mat3 dest) { + mat4 m4; + + /* random rotatation around random axis with random angle */ + glm_rotate_make(m4, drand48(), (vec3){drand48(), drand48(), drand48()}); + glm_mat4_pick3(m4, dest); +} + +void +test_rand_mat2(mat2 dest) { + dest[0][0] = drand48(); + dest[0][1] = drand48(); + dest[1][0] = drand48(); + dest[1][1] = drand48(); +} + +void +test_rand_vec3(vec3 dest) { + dest[0] = drand48(); + dest[1] = drand48(); + dest[2] = drand48(); +} + +vec3s +test_rand_vec3s(void) { + vec3s r; + test_rand_vec3(r.raw); + return r; +} + +void +test_rand_vec4(vec4 dest) { + dest[0] = drand48(); + dest[1] = drand48(); + dest[2] = drand48(); + dest[3] = drand48(); +} + +vec4s +test_rand_vec4s(void) { + vec4s r; + test_rand_vec4(r.raw); + return r; +} + +float +test_rand(void) { + return drand48(); +} + +void +test_rand_quat(versor q) { + glm_quat(q, drand48(), drand48(), drand48(), drand48()); + glm_quat_normalize(q); +} + +test_status_t +test_assert_mat4_eq(mat4 m1, mat4 m2) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat4_eqt(mat4 m1, mat4 m2) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= eps); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat2_eqt(mat2 m1, mat2 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat2_eq(mat2 m1, mat2 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat2_eq_identity(mat2 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + if (i == j) { + ASSERT(test_eq(m2[i][j], 1.0f)) + } else { + ASSERT(test_eq(m2[i][j], 0.0f)) + } + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat2_eq_zero(mat2 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + ASSERT(test_eq(m2[i][j], 0.0f)) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat3_eq(mat3 m1, mat3 m2) { + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat3_eqt(mat3 m1, mat3 m2) { + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat3_eq_identity(mat3 m3) { + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + if (i == j) { + ASSERT(test_eq(m3[i][j], 1.0f)) + } else { + ASSERT(test_eq(m3[i][j], 0.0f)) + } + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat3_eq_zero(mat3 m3) { + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + ASSERT(test_eq(m3[i][j], 0.0f)) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat4_eq_identity(mat4 m4) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + if (i == j) { + ASSERT(test_eq(m4[i][j], 1.0f)) + } else { + ASSERT(test_eq(m4[i][j], 0.0f)) + } + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat4_eq_zero(mat4 m4) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + ASSERT(test_eq(m4[i][j], 0.0f)) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_eqf(float a, float b) { + ASSERT(fabsf(a - b) <= 0.000009); /* rounding errors */ + + TEST_SUCCESS +} + +test_status_t +test_assert_vec2_eq(vec2 v1, vec2 v2) { + ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); + + TEST_SUCCESS +} + +test_status_t +test_assert_vec3_eq(vec3 v1, vec3 v2) { + ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); + ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); + + TEST_SUCCESS +} + +test_status_t +test_assert_vec3s_eq(vec3s v1, vec3s v2) { + test_assert_vec3_eq(v1.raw, v2.raw); + + TEST_SUCCESS +} + +test_status_t +test_assert_vec4_eq(vec4 v1, vec4 v2) { + ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); + ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); + ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009); + + TEST_SUCCESS +} + +test_status_t +test_assert_vec4s_eq(vec4s v1, vec4s v2) { + test_assert_vec4_eq(v1.raw, v2.raw); + + TEST_SUCCESS +} + +test_status_t +test_assert_quat_eq_abs(versor v1, versor v2) { + ASSERT(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */ + ASSERT(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009); + ASSERT(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009); + ASSERT(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009); + + TEST_SUCCESS +} + +test_status_t +test_assert_quat_eq(versor v1, versor v2) { + ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); + ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); + ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009); + + TEST_SUCCESS +} + +test_status_t +test_assert_quat_eq_identity(versor q) { + versor p = GLM_QUAT_IDENTITY_INIT; + + ASSERT(fabsf(q[0] - p[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(q[1] - p[1]) <= 0.000009); + ASSERT(fabsf(q[2] - p[2]) <= 0.000009); + ASSERT(fabsf(q[3] - p[3]) <= 0.000009); + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_common.h b/libs/cglm/test/src/test_common.h new file mode 100644 index 0000000..9162a8d --- /dev/null +++ b/libs/cglm/test/src/test_common.h @@ -0,0 +1,118 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef test_common_h +#define test_common_h + +#include "../include/common.h" + +void +test_rand_mat4(mat4 dest); + +void +test_rand_mat3(mat3 dest); + +void +test_rand_mat2(mat2 dest); + +test_status_t +test_assert_eqf(float a, float b); + +test_status_t +test_assert_mat4_eq(mat4 m1, mat4 m2); + +test_status_t +test_assert_mat4_eqt(mat4 m1, mat4 m2); + +test_status_t +test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps); + +test_status_t +test_assert_mat4_eq_identity(mat4 m4); + +test_status_t +test_assert_mat4_eq_zero(mat4 m4); + +test_status_t +test_assert_mat2_eqt(mat2 m1, mat2 m2); + +test_status_t +test_assert_mat2_eq(mat2 m1, mat2 m2); + +test_status_t +test_assert_mat2_eq_identity(mat2 m2); + +test_status_t +test_assert_mat2_eq_zero(mat2 m2); + +test_status_t +test_assert_mat3_eq(mat3 m1, mat3 m2); + +test_status_t +test_assert_vec2_eq(vec2 v1, vec2 v2); + +test_status_t +test_assert_mat3_eqt(mat3 m1, mat3 m2); + +test_status_t +test_assert_mat3_eq_identity(mat3 m3); + +test_status_t +test_assert_mat3_eq_zero(mat3 m3); + +test_status_t +test_assert_vec3_eq(vec3 v1, vec3 v2); + +test_status_t +test_assert_vec3s_eq(vec3s v1, vec3s v2); + +test_status_t +test_assert_vec4_eq(vec4 v1, vec4 v2); + +test_status_t +test_assert_vec4s_eq(vec4s v1, vec4s v2); + +test_status_t +test_assert_quat_eq(versor v1, versor v2); + +test_status_t +test_assert_quat_eq_identity(versor q) ; + +test_status_t +test_assert_quat_eq_abs(versor v1, versor v2); + +void +test_rand_vec3(vec3 dest); + +vec3s +test_rand_vec3s(void); + +void +test_rand_vec4(vec4 dest); + +vec4s +test_rand_vec4s(void); + +float +test_rand(void); + +void +test_rand_quat(versor q); + +CGLM_INLINE +bool +test_eq(float a, float b) { + return fabsf(a - b) <= GLM_FLT_EPSILON * 10; +} + +CGLM_INLINE +bool +test_eq_th(float a, float b, float th) { + return fabsf(a - b) <= th; +} + +#endif /* test_common_h */ diff --git a/libs/cglm/test/src/test_euler.c b/libs/cglm/test/src/test_euler.c new file mode 100644 index 0000000..b71e0f0 --- /dev/null +++ b/libs/cglm/test/src/test_euler.c @@ -0,0 +1,45 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(euler) { + mat4 rot1, rot2; + vec3 inAngles, outAngles; + + inAngles[0] = glm_rad(-45.0f); /* X angle */ + inAngles[1] = glm_rad(88.0f); /* Y angle */ + inAngles[2] = glm_rad(18.0f); /* Z angle */ + + glm_euler_xyz(inAngles, rot1); + + /* extract angles */ + glmc_euler_angles(rot1, outAngles); + + /* angles must be equal in that range */ + ASSERTIFY(test_assert_vec3_eq(inAngles, outAngles)) + + /* matrices must be equal */ + glmc_euler_xyz(outAngles, rot2); + ASSERTIFY(test_assert_mat4_eq(rot1, rot2)) + + /* change range */ + inAngles[0] = glm_rad(-145.0f); /* X angle */ + inAngles[1] = glm_rad(818.0f); /* Y angle */ + inAngles[2] = glm_rad(181.0f); /* Z angle */ + + glm_euler_xyz(inAngles, rot1); + glmc_euler_angles(rot1, outAngles); + + /* angles may not be equal but matrices MUST! */ + + /* matrices must be equal */ + glmc_euler_xyz(outAngles, rot2); + ASSERTIFY(test_assert_mat4_eq(rot1, rot2)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_ivec2.h b/libs/cglm/test/src/test_ivec2.h new file mode 100644 index 0000000..5374688 --- /dev/null +++ b/libs/cglm/test/src/test_ivec2.h @@ -0,0 +1,189 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, ivec2) { + ivec4 v4 = {2, 3, 5, 7}; + ivec3 v3 = {11, 13, 17}; + ivec2 v2; + + GLM(ivec2)(v4, v2); + ASSERT(v2[0] == 2) + ASSERT(v2[1] == 3) + + GLM(ivec2)(v3, v2); + ASSERT(v2[0] == 11) + ASSERT(v2[1] == 13) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_copy) { + ivec2 src = {7, 5}; + ivec2 dst = {99, 99}; + + GLM(ivec2_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_zero) { + ivec2 v = {2, 3}; + + GLM(ivec2_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_one) { + ivec2 v = {-2, 9}; + + GLM(ivec2_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_add) { + ivec2 a = {14, 3}; + ivec2 b = {-3, 2}; + ivec2 v = {99, 99}; + + GLM(ivec2_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_adds) { + ivec2 a = {-3, 1}; + ivec2 v = {99, 99}; + int s = 2; + + GLM(ivec2_adds)(a, s, v); + ASSERT(v[0] == -1) + ASSERT(v[1] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_sub) { + ivec2 a = {-2, 9}; + ivec2 b = {3, 2}; + ivec2 v = {99, 99}; + + GLM(ivec2_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_subs) { + ivec2 a = {5, -2}; + ivec2 v = {99, 99}; + int s = -3; + + GLM(ivec2_subs)(a, s, v); + ASSERT(v[0] == 8) + ASSERT(v[1] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_mul) { + ivec2 a = {3, 4}; + ivec2 b = {-2, 3}; + ivec2 v = {99, 99}; + + GLM(ivec2_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_scale) { + ivec2 a = {-9, 2}; + ivec2 v = {99, 99}; + int s = -2; + + GLM(ivec2_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_distance2) { + ivec2 a = {-1, 3}; + ivec2 b = {5, 4}; + int v; + + v = GLM(ivec2_distance2)(a, b); + ASSERT(v == 37) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_distance) { + ivec2 a = {3, 2}; + ivec2 b = {-2, 5}; + float v; + + v = GLM(ivec2_distance)(a, b); + ASSERT(test_eq(v, 5.8309518948)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_maxv) { + ivec2 a = {9, -20}; + ivec2 b = {8, -1}; + ivec2 v = {99, 99}; + + GLM(ivec2_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_minv) { + ivec2 a = {16, 0}; + ivec2 b = {-15, 10}; + ivec2 v = {99, 99}; + + GLM(ivec2_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_clamp) { + ivec2 v = {3, -1}; + + GLM(ivec2_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + + v[0] = -15; + v[1] = 4; + GLM(ivec2_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_ivec3.h b/libs/cglm/test/src/test_ivec3.h new file mode 100644 index 0000000..dfa8794 --- /dev/null +++ b/libs/cglm/test/src/test_ivec3.h @@ -0,0 +1,199 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, ivec3) { + ivec4 v4 = {2, 3, 5, 7}; + ivec3 v3 = {99, 99, 99}; + + GLM(ivec3)(v4, v3); + ASSERT(v3[0] == 2) + ASSERT(v3[1] == 3) + ASSERT(v3[2] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_copy) { + ivec3 src = {7, 5, 2}; + ivec3 dst = {99, 99, 99}; + + GLM(ivec3_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + ASSERT(dst[2] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_zero) { + ivec3 v = {2, 3, 5}; + + GLM(ivec3_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + ASSERT(v[2] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_one) { + ivec3 v = {-2, 9, 12}; + + GLM(ivec3_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + ASSERT(v[2] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_add) { + ivec3 a = {14, 3, 2}; + ivec3 b = {-3, 2, 1}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + ASSERT(v[2] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_adds) { + ivec3 a = {-3, 1, 4}; + ivec3 v = {99, 99, 99}; + int s = 2; + + GLM(ivec3_adds)(a, s, v); + ASSERT(v[0] == -1) + ASSERT(v[1] == 3) + ASSERT(v[2] == 6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_sub) { + ivec3 a = {-2, 9, 1}; + ivec3 b = {3, 2, -1}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + ASSERT(v[2] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_subs) { + ivec3 a = {5, -2, 6}; + ivec3 v = {99, 99, 99}; + int s = -3; + + GLM(ivec3_subs)(a, s, v); + ASSERT(v[0] == 8) + ASSERT(v[1] == 1) + ASSERT(v[2] == 9) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_mul) { + ivec3 a = {3, 4, 5}; + ivec3 b = {-2, 3, 1}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + ASSERT(v[2] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_scale) { + ivec3 a = {-9, 2, 3}; + ivec3 v = {99, 99, 99}; + int s = -2; + + GLM(ivec3_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + ASSERT(v[2] == -6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_distance2) { + ivec3 a = {-1, 3, 0}; + ivec3 b = {5, 4, 2}; + int v; + + v = GLM(ivec3_distance2)(a, b); + ASSERT(v == 41) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_distance) { + ivec3 a = {3, 2, 4}; + ivec3 b = {-2, 5, 2}; + float v; + + v = GLM(ivec3_distance)(a, b); + ASSERT(test_eq(v, 6.1644140029)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_maxv) { + ivec3 a = {9, -20, 5}; + ivec3 b = {8, -1, 2}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + ASSERT(v[2] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_minv) { + ivec3 a = {16, 0, 4}; + ivec3 b = {-15, 10, 8}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + ASSERT(v[2] == 4) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_clamp) { + ivec3 v = {3, -1, 10}; + + GLM(ivec3_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + ASSERT(v[2] == 4) + + v[0] = -15; + v[1] = 4; + v[2] = 1; + GLM(ivec3_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) + ASSERT(v[2] == 1) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_ivec4.h b/libs/cglm/test/src/test_ivec4.h new file mode 100644 index 0000000..dd2d606 --- /dev/null +++ b/libs/cglm/test/src/test_ivec4.h @@ -0,0 +1,214 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, ivec4) { + ivec3 v3 = {2, 3, 5}; + ivec4 v4; + + GLM(ivec4)(v3, 7, v4); + ASSERT(test_eq(v4[0], 2)) + ASSERT(test_eq(v4[1], 3)) + ASSERT(test_eq(v4[2], 5)) + ASSERT(test_eq(v4[3], 7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_copy) { + ivec4 src = {7, 5, 2, 11}; + ivec4 dst = {99, 99, 99, 99}; + + GLM(ivec4_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + ASSERT(dst[2] == 2) + ASSERT(dst[3] == 11) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_zero) { + ivec4 v = {2, 3, 5, 7}; + + GLM(ivec4_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + ASSERT(v[2] == 0) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_one) { + ivec4 v = {-2, 9, 12, 7}; + + GLM(ivec4_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + ASSERT(v[2] == 1) + ASSERT(v[3] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_add) { + ivec4 a = {14, 3, 2, -4}; + ivec4 b = {-3, 2, 1, -1}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + ASSERT(v[2] == 3) + ASSERT(v[3] == -5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_adds) { + ivec4 a = {-3, 1, 4, 2}; + ivec4 v = {99, 99, 99, 99}; + int s = -2; + + GLM(ivec4_adds)(a, s, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == -1) + ASSERT(v[2] == 2) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_sub) { + ivec4 a = {-2, 9, 1, 5}; + ivec4 b = {3, 2, -1, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + ASSERT(v[2] == 2) + ASSERT(v[3] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_subs) { + ivec4 a = {5, -2, 6, 1}; + ivec4 v = {99, 99, 99, 99}; + int s = 2; + + GLM(ivec4_subs)(a, s, v); + ASSERT(v[0] == 3) + ASSERT(v[1] == -4) + ASSERT(v[2] == 4) + ASSERT(v[3] == -1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_mul) { + ivec4 a = {3, 4, 5, -3}; + ivec4 b = {-2, 3, 1, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + ASSERT(v[2] == 5) + ASSERT(v[3] == -6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_scale) { + ivec4 a = {-9, 2, 3, 0}; + ivec4 v = {99, 99, 99, 99}; + int s = -2; + + GLM(ivec4_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + ASSERT(v[2] == -6) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_distance2) { + ivec4 a = {-1, 3, 0, 4}; + ivec4 b = {5, 4, 2, 6}; + int v; + + v = GLM(ivec4_distance2)(a, b); + ASSERT(v == 45) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_distance) { + ivec4 a = {3, 2, 4, -1}; + ivec4 b = {-2, 5, 2, 4}; + float v; + + v = GLM(ivec4_distance)(a, b); + ASSERT(test_eq(v, 7.9372539331)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_maxv) { + ivec4 a = {9, -20, 5, -3}; + ivec4 b = {8, -1, 2, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + ASSERT(v[2] == 5) + ASSERT(v[3] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_minv) { + ivec4 a = {16, 0, 4, 5}; + ivec4 b = {-15, 10, 8, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + ASSERT(v[2] == 4) + ASSERT(v[3] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_clamp) { + ivec4 v = {3, -1, 10, -100}; + + GLM(ivec4_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + ASSERT(v[2] == 4) + ASSERT(v[3] == -2) + + v[0] = -15; + v[1] = 4; + v[2] = 1; + v[3] = 0; + GLM(ivec4_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) + ASSERT(v[2] == 1) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_mat2.h b/libs/cglm/test/src/test_mat2.h new file mode 100644 index 0000000..9141caf --- /dev/null +++ b/libs/cglm/test/src/test_mat2.h @@ -0,0 +1,286 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#define A_MATRIX2x2 {{1,2},{5,6}} + +#ifndef CGLM_TEST_MAT2_ONCE +#define CGLM_TEST_MAT2_ONCE + +TEST_IMPL(MACRO_GLM_MAT2_IDENTITY_INIT) { + mat2 m = GLM_MAT2_IDENTITY_INIT; + + ASSERT(test_eq(m[0][0], 1.0f)) + ASSERT(test_eq(m[0][1], 0.0f)) + ASSERT(test_eq(m[1][0], 0.0f)) + ASSERT(test_eq(m[1][1], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_MAT2_ZERO_INIT) { + mat2 m = GLM_MAT2_ZERO_INIT; + + ASSERT(test_eq(m[0][0], 0.0f)) + ASSERT(test_eq(m[0][1], 0.0f)) + ASSERT(test_eq(m[1][0], 0.0f)) + ASSERT(test_eq(m[1][1], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_MAT2_IDENTITY) { + ASSERT(test_eq(GLM_MAT2_IDENTITY[0][0], 1.0f)) + ASSERT(test_eq(GLM_MAT2_IDENTITY[0][1], 0.0f)) + ASSERT(test_eq(GLM_MAT2_IDENTITY[1][0], 0.0f)) + ASSERT(test_eq(GLM_MAT2_IDENTITY[1][1], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_MAT2_ZERO) { + ASSERT(test_eq(GLM_MAT2_ZERO[0][0], 0.0f)) + ASSERT(test_eq(GLM_MAT2_ZERO[0][1], 0.0f)) + ASSERT(test_eq(GLM_MAT2_ZERO[1][0], 0.0f)) + ASSERT(test_eq(GLM_MAT2_ZERO[1][1], 0.0f)) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_MAT2_ONCE */ + +TEST_IMPL(GLM_PREFIX, mat2_copy) { + mat2 m1 = A_MATRIX2x2; + mat2 m2 = GLM_MAT2_IDENTITY_INIT; + + GLM(mat2_copy)(m1, m2); + + test_assert_mat2_eq(m1, m2); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_identity) { + mat2 m1 = GLM_MAT2_IDENTITY_INIT; + mat2 m2 = GLM_MAT2_IDENTITY_INIT; + mat2 m3; + + GLM(mat2_identity)(m3); + + ASSERTIFY(test_assert_mat2_eq_identity(m1)) + ASSERTIFY(test_assert_mat2_eq_identity(m2)) + ASSERTIFY(test_assert_mat2_eq_identity(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_identity_array) { + int i, count; + mat2 matrices[4] = { + A_MATRIX2x2, + A_MATRIX2x2, + A_MATRIX2x2, + A_MATRIX2x2 + }; + + count = 4; + + GLM(mat2_identity_array)(matrices, count); + + for (i = 0; i < count; i++) { + ASSERTIFY(test_assert_mat2_eq_identity(matrices[i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_zero) { + mat2 m1 = GLM_MAT2_ZERO_INIT; + mat2 m2 = GLM_MAT2_ZERO_INIT; + mat2 m3; + + GLM(mat2_zero)(m3); + + ASSERTIFY(test_assert_mat2_eq_zero(m1)) + ASSERTIFY(test_assert_mat2_eq_zero(m2)) + ASSERTIFY(test_assert_mat2_eq_zero(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_mul) { + mat2 m1 = GLM_MAT2_IDENTITY_INIT; + mat2 m2 = GLM_MAT2_IDENTITY_INIT; + mat2 m3; + mat2 m4 = GLM_MAT2_ZERO_INIT; + int i, j, k; + + /* test random matrices */ + /* random matrices */ + test_rand_mat2(m1); + test_rand_mat2(m2); + + GLM(mat2_mul)(m1, m2, m3); + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + for (k = 0; k < 2; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat2_eq(m3, m4)) + + /* test pre compiled */ + GLM(mat2_mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat2_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_transpose_to) { + mat2 mat = A_MATRIX2x2; + mat2 m1; + + GLM(mat2_transpose_to)(mat, m1); + + ASSERTIFY(test_assert_mat2_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_transpose) { + mat2 mat = A_MATRIX2x2; + mat2 m1; + + GLM(mat2_copy)(mat, m1); + GLM(mat2_transpose)(m1); + + ASSERTIFY(test_assert_mat2_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_mulv) { + vec2 res; + mat2 mat = A_MATRIX2x2; + vec2 v = {11.0f, 21.0f}; + int i; + + GLM(mat2_mulv)(mat, v, res); + + for (i = 0; i < 2; i++) { + ASSERT(test_eq(res[i], v[0] * mat[0][i] + v[1] * mat[1][i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_trace) { + mat2 mat = A_MATRIX2x2; + float trace; + + trace = GLM(mat2_trace)(mat); + + ASSERT(test_eq(trace, mat[0][0] + mat[1][1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_scale) { + mat2 m1 = A_MATRIX2x2; + mat2 m2 = A_MATRIX2x2; + int i, j, scale; + + scale = rand() % 100; + + GLM(mat2_scale)(m1, (float)scale); + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_det) { + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_inv) { + mat2 m1 = GLM_MAT2_IDENTITY_INIT; + mat2 m2 = GLM_MAT2_IDENTITY_INIT; + mat2 m3; + int i; + + m1[0][0] = 41.0f; + m1[0][1] = 0.0f; + m1[1][0] = 0.0f; + m1[1][1] = 70.0f; + + for (i = 0; i < 10000; i++) { + /* test inverse precise */ + GLM(mat2_inv)(m1, m2); + GLM(mat2_inv)(m2, m3); + + ASSERTIFY(test_assert_mat2_eq(m1, m3)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_swap_col) { + mat2 m1 = A_MATRIX2x2; + mat2 m2 = A_MATRIX2x2; + + GLM(mat2_swap_col)(m1, 0, 1); + + ASSERTIFY(test_assert_vec2_eq(m1[0], m2[1])) + ASSERTIFY(test_assert_vec2_eq(m1[1], m2[0])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_swap_row) { + mat2 m1 = A_MATRIX2x2; + mat2 m2 = A_MATRIX2x2; + + GLM(mat2_swap_row)(m1, 0, 1); + + ASSERT(test_eq(m1[0][0], m2[0][1])) + ASSERT(test_eq(m1[0][1], m2[0][0])) + + ASSERT(test_eq(m1[1][0], m2[1][1])) + ASSERT(test_eq(m1[1][1], m2[1][0])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_rmc) { + mat2 mat = A_MATRIX2x2; + vec2 v = {11.0f, 12.0f}; + vec2 v1; + float r1, r2; + int i; + + r1 = GLM(mat2_rmc)(v, mat, v); + + for (i = 0; i < 2; i++) { + v1[i] = v[0] * mat[i][0] + v[1] * mat[i][1]; + } + + r2 = v[0] * v1[0] + v[1] * v1[1]; + + ASSERT(test_eq(r1, r2)) + + TEST_SUCCESS +} + +#undef A_MATRIX2x2 diff --git a/libs/cglm/test/src/test_mat3.h b/libs/cglm/test/src/test_mat3.h new file mode 100644 index 0000000..76b1786 --- /dev/null +++ b/libs/cglm/test/src/test_mat3.h @@ -0,0 +1,311 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#define A_MATRIX {{1,2,3},{5,6,7},{9,10,11}} + +TEST_IMPL(GLM_PREFIX, mat3_copy) { + mat3 m1 = A_MATRIX; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + + GLM(mat3_copy)(m1, m2); + + test_assert_mat3_eq(m1, m2); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_identity) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + mat3 m3; + + GLM(mat3_identity)(m3); + + ASSERTIFY(test_assert_mat3_eq_identity(m1)) + ASSERTIFY(test_assert_mat3_eq_identity(m2)) + ASSERTIFY(test_assert_mat3_eq_identity(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_identity_array) { + int i, count; + mat3 matrices[4] = { + A_MATRIX, + A_MATRIX, + A_MATRIX, + A_MATRIX + }; + + count = 4; + + GLM(mat3_identity_array)(matrices, count); + + for (i = 0; i < count; i++) { + ASSERTIFY(test_assert_mat3_eq_identity(matrices[i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_zero) { + mat3 m1 = GLM_MAT3_ZERO_INIT; + mat3 m2 = GLM_MAT3_ZERO_INIT; + mat3 m3; + + GLM(mat3_zero)(m3); + + ASSERTIFY(test_assert_mat3_eq_zero(m1)) + ASSERTIFY(test_assert_mat3_eq_zero(m2)) + ASSERTIFY(test_assert_mat3_eq_zero(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_mul) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + mat3 m3; + mat3 m4 = GLM_MAT3_ZERO_INIT; + int i, j, k; + + /* test random matrices */ + /* random matrices */ + test_rand_mat3(m1); + test_rand_mat3(m2); + + GLM(mat3_mul)(m1, m2, m3); + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 3; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat3_eq(m3, m4)) + + /* test pre compiled */ + GLM(mat3_mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat3_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_mulv) { + vec4 res; + mat3 mat = A_MATRIX; + vec4 v = {1.0f, 2.0f, 3.0f, 4.0f}; + int i; + + GLM(mat3_mulv)(mat, v, res); + + for (i = 0; i < 3; i++) { + ASSERT(test_eq(res[i], + v[0] * mat[0][i] + + v[1] * mat[1][i] + + v[2] * mat[2][i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_trace) { + mat3 mat = A_MATRIX; + float trace; + + trace = GLM(mat3_trace)(mat); + + ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_quat) { + mat3 m1, m3; + mat4 m2; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + GLM(quat_mat3)(q1, m1); + GLM(mat3_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat3_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + GLM(mat4_pick3)(m2, m3); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat3_eq(m1, m3)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_transpose_to) { + mat3 mat = A_MATRIX; + mat3 m1; + + GLM(mat3_transpose_to)(mat, m1); + + ASSERTIFY(test_assert_mat3_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_transpose) { + mat3 mat = A_MATRIX; + mat3 m1; + + GLM(mat3_copy)(mat, m1); + GLM(mat3_transpose)(m1); + + ASSERTIFY(test_assert_mat3_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_scale) { + mat3 m1 = A_MATRIX; + mat3 m2 = A_MATRIX; + int i, j, k, scale; + + scale = rand() % 100; + + GLM(mat3_scale)(m1, (float)scale); + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 3; k++) + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_det) { + mat3 mat; + float a, b, c, + d, e, f, + g, h, i; + float det1, det2; + + test_rand_mat3(mat); + + a = mat[0][0]; b = mat[0][1]; c = mat[0][2]; + d = mat[1][0]; e = mat[1][1]; f = mat[1][2]; + g = mat[2][0]; h = mat[2][1]; i = mat[2][2]; + + det1 = a * (e * i - h * f) - d * (b * i - c * h) + g * (b * f - c * e); + det2 = GLM(mat3_det)(mat); + + ASSERT(test_eq(det1, det2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_inv) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + mat3 m3; + int i; + + for (i = 0; i < 100000; i++) { + test_rand_mat3(m1); + test_rand_mat3(m2); + + /* test inverse precise */ + GLM(mat3_inv)(m1, m2); + GLM(mat3_inv)(m2, m3); + ASSERTIFY(test_assert_mat3_eq(m1, m3)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_swap_col) { + mat3 m1 = A_MATRIX; + mat3 m2 = A_MATRIX; + + GLM(mat3_swap_col)(m1, 0, 1); + + ASSERTIFY(test_assert_vec3_eq(m1[0], m2[1])) + ASSERTIFY(test_assert_vec3_eq(m1[1], m2[0])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_swap_row) { + mat3 m1 = A_MATRIX; + mat3 m2 = A_MATRIX; + + GLM(mat3_swap_row)(m1, 0, 1); + + ASSERT(test_eq(m1[0][0], m2[0][1])) + ASSERT(test_eq(m1[0][1], m2[0][0])) + ASSERT(test_eq(m1[0][2], m2[0][2])) + + ASSERT(test_eq(m1[1][0], m2[1][1])) + ASSERT(test_eq(m1[1][1], m2[1][0])) + ASSERT(test_eq(m1[1][2], m2[1][2])) + + ASSERT(test_eq(m1[2][0], m2[2][1])) + ASSERT(test_eq(m1[2][1], m2[2][0])) + ASSERT(test_eq(m1[2][2], m2[2][2])) + + GLM(mat3_swap_row)(m1, 1, 2); + + ASSERT(test_eq(m1[0][0], m2[0][1])) + ASSERT(test_eq(m1[0][1], m2[0][2])) + ASSERT(test_eq(m1[0][2], m2[0][0])) + + ASSERT(test_eq(m1[1][0], m2[1][1])) + ASSERT(test_eq(m1[1][1], m2[1][2])) + ASSERT(test_eq(m1[1][2], m2[1][0])) + + ASSERT(test_eq(m1[2][0], m2[2][1])) + ASSERT(test_eq(m1[2][1], m2[2][2])) + ASSERT(test_eq(m1[2][2], m2[2][0])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_rmc) { + mat3 mat = A_MATRIX; + vec3 v = {11.0f, 12.0f, 13.0f}; + vec3 v1; + float r1, r2; + int i; + + r1 = GLM(mat3_rmc)(v, mat, v); + + for (i = 0; i < 3; i++) { + v1[i] = v[0] * mat[i][0] + + v[1] * mat[i][1] + + v[2] * mat[i][2]; + } + + r2 = v[0] * v1[0] + v[1] * v1[1] + v[2] * v1[2]; + + ASSERT(test_eq(r1, r2)) + + TEST_SUCCESS +} + +#undef A_MATRIX diff --git a/libs/cglm/test/src/test_mat4.h b/libs/cglm/test/src/test_mat4.h new file mode 100644 index 0000000..d42e457 --- /dev/null +++ b/libs/cglm/test/src/test_mat4.h @@ -0,0 +1,488 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#define A_MATRIX {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}} +#define A_MATRIX3 {{1,2,3},{5,6,7},{9,10,11}} + +TEST_IMPL(GLM_PREFIX, mat4_ucopy) { + mat4 m1 = A_MATRIX; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + + GLM(mat4_ucopy)(m1, m2); + + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_copy) { + mat4 m1 = A_MATRIX; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + + GLM(mat4_copy)(m1, m2); + + test_assert_mat4_eq(m1, m2); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_identity) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + mat4 m3; + + GLM(mat4_identity)(m3); + + ASSERTIFY(test_assert_mat4_eq_identity(m1)) + ASSERTIFY(test_assert_mat4_eq_identity(m2)) + ASSERTIFY(test_assert_mat4_eq_identity(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_identity_array) { + int i, count; + mat4 matrices[4] = { + A_MATRIX, + A_MATRIX, + A_MATRIX, + A_MATRIX + }; + + count = 4; + + GLM(mat4_identity_array)(matrices, count); + + for (i = 0; i < count; i++) { + ASSERTIFY(test_assert_mat4_eq_identity(matrices[i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_zero) { + mat4 m1 = GLM_MAT4_ZERO_INIT; + mat4 m2 = GLM_MAT4_ZERO_INIT; + mat4 m3; + + GLM(mat4_zero)(m3); + + ASSERTIFY(test_assert_mat4_eq_zero(m1)) + ASSERTIFY(test_assert_mat4_eq_zero(m2)) + ASSERTIFY(test_assert_mat4_eq_zero(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_pick3) { + mat4 m1 = A_MATRIX; + mat3 m2 = GLM_MAT3_ZERO_INIT; + mat3 m3 = A_MATRIX3; + + GLM(mat4_pick3)(m1, m2); + + ASSERTIFY(test_assert_mat3_eq(m2, m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_pick3t) { + mat4 m1 = A_MATRIX; + mat3 m2 = GLM_MAT3_ZERO_INIT; + mat3 m3 = A_MATRIX3; + + GLM(mat4_pick3t)(m1, m2); + + ASSERTIFY(test_assert_mat3_eqt(m2, m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_ins3) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat3 m2 = A_MATRIX3; + int i, j; + + GLM(mat4_ins3)(m2, m1); + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + ASSERT(m1[i][j] == m2[i][j]) + } + } + + ASSERT(test_eq(m1[3][0], 0.0f)) + ASSERT(test_eq(m1[3][1], 0.0f)) + ASSERT(test_eq(m1[3][2], 0.0f)) + ASSERT(test_eq(m1[3][3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_mul) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + mat4 m3; + mat4 m4 = GLM_MAT4_ZERO_INIT; + int i, j, k; + + /* test random matrices */ + /* random matrices */ + test_rand_mat4(m1); + test_rand_mat4(m2); + + GLM(mat4_mul)(m1, m2, m3); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + /* test pre compiled */ + GLM(mat4_mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_mulN) { + mat4 res1, res2; + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + mat4 m3 = A_MATRIX; + + mat4 *matrices[] = { + &m1, &m2, &m3 + }; + + GLM(mat4_mulN)(matrices, sizeof(matrices) / sizeof(matrices[0]), res1); + + GLM(mat4_mul)(*matrices[0], *matrices[1], res2); + GLM(mat4_mul)(res2, *matrices[2], res2); + + ASSERTIFY(test_assert_mat4_eq(res1, res1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_mulv) { + vec4 res; + mat4 mat = A_MATRIX; + vec4 v = {1.0f, 2.0f, 3.0f, 4.0f}; + int i; + + GLM(mat4_mulv)(mat, v, res); + + for (i = 0; i < 4; i++) { + ASSERT(test_eq(res[i], + v[0] * mat[0][i] + + v[1] * mat[1][i] + + v[2] * mat[2][i] + + v[3] * mat[3][i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_mulv3) { + vec4 res; + mat4 mat = A_MATRIX; + vec3 v = {1.0f, 2.0f, 3.0f}; + float last; + int i; + + last = 1.0f; + + GLM(mat4_mulv3)(mat, v, last, res); + + for (i = 0; i < 3; i++) { + ASSERT(test_eq(res[i], + v[0] * mat[0][i] + + v[1] * mat[1][i] + + v[2] * mat[2][i] + + last * mat[3][i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_trace) { + mat4 mat = A_MATRIX; + float trace; + + trace = GLM(mat4_trace)(mat); + + ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2] + mat[3][3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_trace3) { + mat4 mat = A_MATRIX; + float trace; + + trace = GLM(mat4_trace3)(mat); + + ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_quat) { + mat4 m1, m2; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + GLM(quat_mat4)(q1, m1); + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_transpose_to) { + mat4 mat = A_MATRIX; + mat4 m1; + + GLM(mat4_transpose_to)(mat, m1); + + ASSERTIFY(test_assert_mat4_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_transpose) { + mat4 mat = A_MATRIX; + mat4 m1; + + GLM(mat4_copy)(mat, m1); + GLM(mat4_transpose)(m1); + + ASSERTIFY(test_assert_mat4_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_scale_p) { + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + int i, j, k, scale; + + scale = rand() % 100; + + GLM(mat4_scale_p)(m1, (float)scale); + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_scale) { + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + int i, j, k, scale; + + scale = rand() % 100; + + GLM(mat4_scale)(m1, (float)scale); + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_det) { + mat4 mat = GLM_MAT4_IDENTITY_INIT; + float t[6]; + float a, b, c, d, + e, f, g, h, + i, j, k, l, + m, n, o, p; + float det1, det2; + + test_rand_mat4(mat); + + a = mat[0][0]; b = mat[0][1]; c = mat[0][2]; d = mat[0][3]; + e = mat[1][0]; f = mat[1][1]; g = mat[1][2]; h = mat[1][3]; + i = mat[2][0]; j = mat[2][1]; k = mat[2][2]; l = mat[2][3]; + m = mat[3][0]; n = mat[3][1]; o = mat[3][2]; p = mat[3][3]; + + t[0] = k * p - o * l; + t[1] = j * p - n * l; + t[2] = j * o - n * k; + t[3] = i * p - m * l; + t[4] = i * o - m * k; + t[5] = i * n - m * j; + + det1 = a * (f * t[0] - g * t[1] + h * t[2]) + - b * (e * t[0] - g * t[3] + h * t[4]) + + c * (e * t[1] - f * t[3] + h * t[5]) + - d * (e * t[2] - f * t[4] + g * t[5]); + + det2 = GLM(mat4_det(mat)); + + ASSERT(test_eq(det1, det2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_inv) { + mat4 m1, m2, m3; + int i; + + for (i = 0; i < 100000; i++) { + test_rand_mat4(m1); + test_rand_mat4(m2); + + /* test inverse precise */ + GLM(mat4_inv)(m1, m2); + GLM(mat4_inv)(m2, m3); + ASSERTIFY(test_assert_mat4_eq(m1, m3)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_inv_precise) { + mat4 m1, m2, m3; + mat4 m4, m5, m6; + int i; + + for (i = 0; i < 100000; i++) { + test_rand_mat4(m1); + test_rand_mat4(m2); + + glm_mat4_inv_precise(m1, m2); + glm_mat4_inv_precise(m2, m3); + ASSERTIFY(test_assert_mat4_eq(m1, m3)) + + test_rand_mat4(m4); + test_rand_mat4(m5); + + glmc_mat4_inv_precise(m4, m5); + glmc_mat4_inv_precise(m5, m6); + ASSERTIFY(test_assert_mat4_eq(m4, m6)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_inv_fast) { + mat4 m1, m2, m3; + int i; + + for (i = 0; i < 100000; i++) { + test_rand_mat4(m1); + test_rand_mat4(m2); + + /* test inverse precise */ + GLM(mat4_inv_fast)(m1, m2); + GLM(mat4_inv_fast)(m2, m3); + ASSERTIFY(test_assert_mat4_eq2(m1, m3, 0.0009f)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_swap_col) { + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + + GLM(mat4_swap_col)(m1, 0, 1); + GLM(mat4_swap_col)(m1, 2, 3); + + ASSERTIFY(test_assert_vec4_eq(m1[0], m2[1])) + ASSERTIFY(test_assert_vec4_eq(m1[1], m2[0])) + ASSERTIFY(test_assert_vec4_eq(m1[2], m2[3])) + ASSERTIFY(test_assert_vec4_eq(m1[3], m2[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_swap_row) { + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + + GLM(mat4_swap_row)(m1, 0, 1); + GLM(mat4_swap_row)(m1, 2, 3); + + ASSERT(test_eq(m1[0][0], m2[0][1])) + ASSERT(test_eq(m1[0][1], m2[0][0])) + ASSERT(test_eq(m1[0][2], m2[0][3])) + ASSERT(test_eq(m1[0][3], m2[0][2])) + ASSERT(test_eq(m1[1][0], m2[1][1])) + ASSERT(test_eq(m1[1][1], m2[1][0])) + ASSERT(test_eq(m1[1][2], m2[1][3])) + ASSERT(test_eq(m1[1][3], m2[1][2])) + ASSERT(test_eq(m1[2][0], m2[2][1])) + ASSERT(test_eq(m1[2][1], m2[2][0])) + ASSERT(test_eq(m1[2][2], m2[2][3])) + ASSERT(test_eq(m1[2][3], m2[2][2])) + ASSERT(test_eq(m1[3][0], m2[3][1])) + ASSERT(test_eq(m1[3][1], m2[3][0])) + ASSERT(test_eq(m1[3][2], m2[3][3])) + ASSERT(test_eq(m1[3][3], m2[3][2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_rmc) { + mat4 mat = A_MATRIX; + vec4 v = {1.0f, 2.0f, 3.0f, 4.0f}; + vec4 v1; + float r1, r2; + int i; + + r1 = GLM(mat4_rmc)(v, mat, v); + + for (i = 0; i < 4; i++) { + v1[i] = v[0] * mat[i][0] + + v[1] * mat[i][1] + + v[2] * mat[i][2] + + v[3] * mat[i][3]; + } + + r2 = v[0] * v1[0] + v[1] * v1[1] + v[2] * v1[2] + v[3] * v1[3]; + + ASSERT(test_eq(r1, r2)) + + TEST_SUCCESS +} + +#undef A_MATRIX +#undef A_MATRIX3 diff --git a/libs/cglm/test/src/test_plane.h b/libs/cglm/test/src/test_plane.h new file mode 100644 index 0000000..896c8b5 --- /dev/null +++ b/libs/cglm/test/src/test_plane.h @@ -0,0 +1,39 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, plane_normalize) { + vec4 p1 = {2.0f, -3.0f, 4.0f, 5.0f}, p2 = {2.0f, -3.0f, 4.0f, 5.0f}; + float s = 1.0f; + float norm; + + GLM(plane_normalize)(p2); + + norm = sqrtf(p1[0] * p1[0] + p1[1] * p1[1] + p1[2] * p1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(p1[0], 0.0f)) + ASSERT(test_eq(p1[1], 0.0f)) + ASSERT(test_eq(p1[2], 0.0f)) + ASSERT(test_eq(p1[3], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(p1[0] * norm, p2[0])) + ASSERT(test_eq(p1[1] * norm, p2[1])) + ASSERT(test_eq(p1[2] * norm, p2[2])) + ASSERT(test_eq(p1[3] * norm, p2[3])) + + glm_vec4_zero(p1); + GLM(plane_normalize)(p1); + ASSERTIFY(test_assert_vec4_eq(p1, GLM_VEC4_ZERO)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_project.h b/libs/cglm/test/src/test_project.h new file mode 100644 index 0000000..41bdecd --- /dev/null +++ b/libs/cglm/test/src/test_project.h @@ -0,0 +1,92 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, unprojecti) { + mat4 model, view, proj, mvp; + vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f}; + vec3 pos = {13.0f, 45.0f, 0.74f}; + vec3 projected, unprojected; + + glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f}); + glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view); + + glm_perspective_default(0.5f, proj); + glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp); + + GLM(project)(pos, mvp, viewport, projected); + + glm_mat4_inv(mvp, mvp); + GLM(unprojecti)(projected, mvp, viewport, unprojected); + + /* unprojected of projected vector must be same as original one */ + /* we used 0.01 because of projection floating point errors */ + ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01) + ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) + ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, unproject) { + mat4 model, view, proj, mvp; + vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f}; + vec3 pos = {13.0f, 45.0f, 0.74f}; + vec3 projected, unprojected; + + glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f}); + glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view); + + glm_perspective_default(0.5f, proj); + glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp); + + GLM(project)(pos, mvp, viewport, projected); + GLM(unproject)(projected, mvp, viewport, unprojected); + + /* unprojected of projected vector must be same as original one */ + /* we used 0.01 because of projection floating point errors */ + ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01) + ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) + ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, project) { + mat4 model, view, proj, mvp; + vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f}; + vec3 pos = {13.0f, 45.0f, 0.74f}; + vec3 projected, unprojected; + + glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f}); + glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view); + + glm_perspective_default(0.5f, proj); + glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp); + + GLM(project)(pos, mvp, viewport, projected); + GLM(unproject)(projected, mvp, viewport, unprojected); + + /* unprojected of projected vector must be same as original one */ + /* we used 0.01 because of projection floating point errors */ + ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01) + ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) + ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) + + /* test with no projection */ + glm_mat4_identity(mvp); + + GLM(project)(pos, mvp, viewport, projected); + GLM(unproject)(projected, mvp, viewport, unprojected); + + ASSERT(test_eq(pos[0], unprojected[0])) + ASSERT(test_eq(pos[1], unprojected[1])) + ASSERT(test_eq(pos[2], unprojected[2])) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_quat.h b/libs/cglm/test/src/test_quat.h new file mode 100644 index 0000000..ab85b19 --- /dev/null +++ b/libs/cglm/test/src/test_quat.h @@ -0,0 +1,1086 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#ifndef CGLM_TEST_QUAT_ONCE +#define CGLM_TEST_QUAT_ONCE + +/* Macros */ + +TEST_IMPL(MACRO_GLM_QUAT_IDENTITY_INIT) { + versor v = GLM_QUAT_IDENTITY_INIT; + + ASSERT(test_eq(v[0], 0.0f)) + ASSERT(test_eq(v[1], 0.0f)) + ASSERT(test_eq(v[2], 0.0f)) + ASSERT(test_eq(v[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_QUAT_IDENTITY) { + ASSERT(test_eq(GLM_QUAT_IDENTITY[0], 0.0f)) + ASSERT(test_eq(GLM_QUAT_IDENTITY[1], 0.0f)) + ASSERT(test_eq(GLM_QUAT_IDENTITY[2], 0.0f)) + ASSERT(test_eq(GLM_QUAT_IDENTITY[3], 1.0f)) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_QUAT_ONCE */ + +TEST_IMPL(GLM_PREFIX, quat_identity) { + versor a = GLM_QUAT_IDENTITY_INIT; + versor b = GLM_QUAT_IDENTITY_INIT; + versor c; + mat4 r; + + GLM(quat_identity)(c); + + ASSERTIFY(test_assert_quat_eq_identity(a)) + ASSERTIFY(test_assert_quat_eq_identity(b)) + ASSERTIFY(test_assert_quat_eq_identity(c)) + + glm_quat_identity(c); + ASSERT(test_eq(glm_quat_real(c), cosf(glm_rad(0.0f) * 0.5f))) + + glm_quat_mat4(c, r); + ASSERTIFY(test_assert_mat4_eq2(r, GLM_MAT4_IDENTITY, 0.000009f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_identity_array) { + int i, count; + versor quats[4] = { + {1.0f, 2.0f, 3.0f, 4.0f}, + {1.0f, 2.0f, 3.0f, 4.0f}, + {1.0f, 2.0f, 3.0f, 4.0f}, + {1.0f, 2.0f, 3.0f, 4.0f}, + }; + + count = 4; + + GLM(quat_identity_array)(quats, count); + + for (i = 0; i < count; i++) { + ASSERTIFY(test_assert_quat_eq_identity(quats[i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_init) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}; + versor q2 = {1.0f, 2.0f, 3.0f, 4.0f}; + versor q3 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(quat_init)(q1, 10.0f, 11.0f, 12.0f, 13.0f); + GLM(quat_init)(q2, 100.0f, 110.0f, 120.0f, 130.0f); + GLM(quat_init)(q3, 1000.0f, 1100.0f, 1200.0f, 1300.0f); + + ASSERT(q1[0] == 10.0f) + ASSERT(q1[1] == 11.0f) + ASSERT(q1[2] == 12.0f) + ASSERT(q1[3] == 13.0f) + + ASSERT(q2[0] == 100.0f) + ASSERT(q2[1] == 110.0f) + ASSERT(q2[2] == 120.0f) + ASSERT(q2[3] == 130.0f) + + ASSERT(q3[0] == 1000.0f) + ASSERT(q3[1] == 1100.0f) + ASSERT(q3[2] == 1200.0f) + ASSERT(q3[3] == 1300.0f) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quatv) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}; + vec3 v1, v2; + float a1; + + test_rand_vec3(v1); + GLM(quatv)(q1, glm_rad(60.0f), v1); + + glm_quat_axis(q1, v2); + a1 = glm_quat_angle(q1); + + ASSERT(test_eq(a1, glm_rad(60.0f))) + + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}; + vec3 v1, v2; + float a1; + + test_rand_vec3(v1); + GLM(quat)(q1, glm_rad(60.0f), v1[0], v1[1], v1[2]); + + glm_quat_axis(q1, v2); + a1 = glm_quat_angle(q1); + + ASSERT(test_eq(a1, glm_rad(60.0f))) + + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_copy) { + versor v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + versor v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(quat_copy)(v1, v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_from_vecs) { + versor q1, q2, q3, q4, q5, q6, q7; + vec3 v1 = {1.f, 0.f, 0.f}, v2 = {1.f, 0.f, 0.f}; /* parallel */ + vec3 v3 = {0.f, 1.f, 0.f}, v4 = {1.f, 0.f, 0.f}; /* perpendicular */ + vec3 v5 = {0.f, 0.f, 1.f}, v6 = {0.f, 0.f, -1.f}; /* straight */ + vec3 v7, v8; /* random */ + vec3 v9 = {0.57735026f, 0.57735026f, 0.57735026f}, /* acute */ + v10 = {0.70710678f, 0.70710678f, 0.f}; + vec3 v11 = {0.87287156f, 0.21821789f, 0.43643578f}, /* obtuse */ + v12 = {-0.87287156f, 0.21821789f, 0.43643578f}; + vec3 v13 = GLM_VEC3_ZERO_INIT; /* zero */ + + GLM(quat_from_vecs)(v1, v2, q1); + ASSERTIFY(test_assert_quat_eq_identity(q1)) + + GLM(quat_from_vecs)(v3, v4, q2); + GLM(quat_rotatev)(q2, v3, v3); + ASSERT(test_eq(GLM(vec3_dot)(v3, v4), 1.f)) + ASSERT(test_eq(q2[0], 0.f)) + ASSERT(test_eq(q2[1], 0.f)) + ASSERT(test_eq(q2[2], -0.707106781187f)) + ASSERT(test_eq(q2[3], 0.707106781187f)) + + GLM(quat_from_vecs)(v5, v6, q3); + GLM(quat_rotatev)(q3, v5, v5); + ASSERT(test_eq(GLM(vec3_dot)(v5, v6), 1.f)) + ASSERT(test_eq(q3[0], 0.f)) + ASSERT(test_eq(q3[1], -1.f)) + ASSERT(test_eq(q3[2], 0.f)) + ASSERT(test_eq(q3[3], 0.f)) + + test_rand_vec3(v7); + test_rand_vec3(v8); + GLM(vec3_normalize(v7)); + GLM(vec3_normalize(v8)); + GLM(quat_from_vecs)(v7, v8, q4); + GLM(quat_rotatev)(q4, v7, v7); + ASSERT(test_eq(GLM(vec3_dot)(v7, v8), 1.f)) + + GLM(quat_from_vecs)(v9, v10, q5); + GLM(quat_rotatev)(q5, v9, v9); + ASSERT(test_eq(GLM(vec3_dot)(v9, v10), 1.f)) + + GLM(quat_from_vecs)(v11, v12, q6); + GLM(quat_rotatev)(q6, v11, v11); + ASSERT(test_eq(GLM(vec3_dot)(v11, v12), 1.f)) + + GLM(quat_from_vecs)(v13, v1, q7); + ASSERTIFY(test_assert_quat_eq_identity(q7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_norm) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(quat_norm)(a); + n2 = sqrtf(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_normalize_to) { + versor v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2; + float s = 1.0f; + float norm; + + GLM(quat_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm <= 0.0f) { + ASSERTIFY(test_assert_quat_eq_identity(v1)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + glm_vec4_zero(v1); + GLM(quat_normalize_to)(v1, v2); + ASSERTIFY(test_assert_quat_eq_identity(v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_normalize) { + versor v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2 = {2.0f, -3.0f, 4.0f, 5.0f}; + float s = 1.0f; + float norm; + + GLM(quat_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm <= 0.0f) { + ASSERTIFY(test_assert_quat_eq_identity(v1)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + glm_vec4_zero(v1); + GLM(quat_normalize)(v1); + ASSERTIFY(test_assert_quat_eq_identity(v1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_dot) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + float dot1, dot2; + + dot1 = GLM(quat_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_conjugate) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + versor d, e; + + GLM(quat_conjugate)(a, d); + GLM(quat_conjugate)(b, e); + + ASSERT(test_eq(d[0], -a[0])) + ASSERT(test_eq(d[1], -a[1])) + ASSERT(test_eq(d[2], -a[2])) + ASSERT(test_eq(d[3], a[3])) + + ASSERT(test_eq(e[0], -b[0])) + ASSERT(test_eq(e[1], -b[1])) + ASSERT(test_eq(e[2], -b[2])) + ASSERT(test_eq(e[3], b[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_inv) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + versor d, e; + float n1, n2; + + n1 = 1.0f / glm_vec4_norm2(a); + n2 = 1.0f / glm_vec4_norm2(b); + + GLM(quat_inv)(a, d); + GLM(quat_inv)(b, e); + + ASSERT(test_eq(d[0], -a[0] * n1)) + ASSERT(test_eq(d[1], -a[1] * n1)) + ASSERT(test_eq(d[2], -a[2] * n1)) + ASSERT(test_eq(d[3], a[3] * n1)) + + ASSERT(test_eq(e[0], -b[0] * n2)) + ASSERT(test_eq(e[1], -b[1] * n2)) + ASSERT(test_eq(e[2], -b[2] * n2)) + ASSERT(test_eq(e[3], b[3] * n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_add) { + versor a = {-10.0f, 9.0f, -8.0f, 56.0f}; + versor b = {12.0f, 19.0f, -18.0f, 1.0f}; + versor c, d; + + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + c[2] = a[2] + b[2]; + c[3] = a[3] + b[3]; + + GLM(quat_add)(a, b, d); + + ASSERTIFY(test_assert_quat_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_sub) { + vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f}; + vec4 b = {12.0f, 19.0f, -18.0f, 1.0f}; + vec4 c, d; + + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + c[2] = a[2] - b[2]; + c[3] = a[3] - b[3]; + + GLM(quat_sub)(a, b, d); + + ASSERTIFY(test_assert_quat_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_real) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + + ASSERT(test_eq(GLM(quat_real)(a), 78.0f)) + ASSERT(test_eq(GLM(quat_real)(b), 4.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_imag) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + vec3 d, e; + + GLM(quat_imag)(a, d); + GLM(quat_imag)(b, e); + + ASSERT(test_eq(d[0], a[0])) + ASSERT(test_eq(d[1], a[1])) + ASSERT(test_eq(d[2], a[2])) + + ASSERT(test_eq(e[0], b[0])) + ASSERT(test_eq(e[1], b[1])) + ASSERT(test_eq(e[2], b[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_imagn) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + vec3 d, e; + + GLM(quat_imagn)(a, d); + GLM(quat_imagn)(b, e); + + glm_vec3_normalize(a); + glm_vec3_normalize(b); + glm_vec3_normalize(d); + glm_vec3_normalize(e); + + ASSERT(test_eq(d[0], a[0])) + ASSERT(test_eq(d[1], a[1])) + ASSERT(test_eq(d[2], a[2])) + + ASSERT(test_eq(e[0], b[0])) + ASSERT(test_eq(e[1], b[1])) + ASSERT(test_eq(e[2], b[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_imaglen) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + + ASSERT(test_eq(GLM(quat_imaglen)(a), glm_vec3_norm(a))); + ASSERT(test_eq(GLM(quat_imaglen)(b), glm_vec3_norm(b))); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_angle) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}, q2, q3; + vec3 v1; + float a1, a2, a3; + + test_rand_vec3(v1); + GLM(quatv)(q1, glm_rad(60.140f), v1); + GLM(quatv)(q2, glm_rad(160.04f), v1); + GLM(quatv)(q3, glm_rad(20.350f), v1); + + a1 = GLM(quat_angle)(q1); + a2 = GLM(quat_angle)(q2); + a3 = GLM(quat_angle)(q3); + + ASSERT(test_eq(a1, glm_rad(60.140f))) + ASSERT(test_eq(a2, glm_rad(160.04f))) + ASSERT(test_eq(a3, glm_rad(20.350f))) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_axis) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}, q2, q3; + vec3 v1, v2; + + test_rand_vec3(v1); + GLM(quatv)(q1, glm_rad(60.0f), v1); + + glm_quat_axis(q1, v2); + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + test_rand_vec3(v1); + GLM(quatv)(q2, glm_rad(60.0f), v1); + + glm_quat_axis(q2, v2); + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + test_rand_vec3(v1); + GLM(quatv)(q3, glm_rad(60.0f), v1); + + glm_quat_axis(q3, v2); + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mul) { + versor q1 = {2.0f, 3.0f, 4.0f, 5.0f}; + versor q2 = {6.0f, 7.0f, 8.0f, 9.0f}; + versor q3; + versor q4; + vec3 v1 = {1.5f, 2.5f, 3.5f}; + + GLM(quat_mul)(q1, q2, q3); + + ASSERT(test_eq(q3[0], q1[3] * q2[0] + q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1])) + ASSERT(test_eq(q3[1], q1[3] * q2[1] - q1[0] * q2[2] + q1[1] * q2[3] + q1[2] * q2[0])) + ASSERT(test_eq(q3[2], q1[3] * q2[2] + q1[0] * q2[1] - q1[1] * q2[0] + q1[2] * q2[3])) + ASSERT(test_eq(q3[3], q1[3] * q2[3] - q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2])) + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(20.0f), v1); + glm_quatv(q3, glm_rad(50.0f), v1); + + GLM(quat_mul)(q1, q2, q4); + + ASSERTIFY(test_assert_quat_eq(q3, q4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mat4) { + mat4 m1, m2; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + int i; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + GLM(quat_mat4)(q1, m1); + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + /* 1. test quat to mat and mat to quat */ + for (i = 0; i < 1000; i++) { + test_rand_quat(q1); + + GLM(quat_mat4)(q1, m1); + GLM(mat4_quat)(m1, q2); + GLM(quat_mat4)(q2, m2); + + /* 2. test first quat and generated one equality */ + ASSERTIFY(test_assert_quat_eq_abs(q1, q2)); + + /* 3. test first rot and second rotation */ + /* almost equal */ + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f)); + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mat4t) { + mat4 m1, m2; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + int i; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + + GLM(quat_mat4t)(q1, m1); + glm_mat4_transpose(m1); + + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + /* 1. test quat to mat and mat to quat */ + for (i = 0; i < 1000; i++) { + test_rand_quat(q1); + + GLM(quat_mat4t)(q1, m1); + glm_mat4_transpose(m1); + + GLM(mat4_quat)(m1, q2); + + GLM(quat_mat4t)(q2, m2); + glm_mat4_transpose(m2); + + /* 2. test first quat and generated one equality */ + ASSERTIFY(test_assert_quat_eq_abs(q1, q2)); + + /* 3. test first rot and second rotation */ + /* almost equal */ + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f)); + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mat3) { + mat4 m1, m2; + mat3 m3; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + int i; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + GLM(quat_mat3)(q1, m3); + glm_mat4_identity(m1); + glm_mat4_ins3(m3, m1); + + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + /* 1. test quat to mat and mat to quat */ + for (i = 0; i < 1000; i++) { + test_rand_quat(q1); + + GLM(quat_mat3)(q1, m3); + glm_mat4_identity(m1); + glm_mat4_ins3(m3, m1); + + GLM(mat4_quat)(m1, q2); + + GLM(quat_mat3)(q2, m3); + glm_mat4_identity(m2); + glm_mat4_ins3(m3, m2); + + /* 2. test first quat and generated one equality */ + ASSERTIFY(test_assert_quat_eq_abs(q1, q2)); + + /* 3. test first rot and second rotation */ + /* almost equal */ + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f)); + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mat3t) { + mat4 m1, m2; + mat3 m3; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + int i; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + + GLM(quat_mat3t)(q1, m3); + glm_mat3_transpose(m3); + glm_mat4_identity(m1); + glm_mat4_ins3(m3, m1); + + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + /* 1. test quat to mat and mat to quat */ + for (i = 0; i < 1000; i++) { + test_rand_quat(q1); + + GLM(quat_mat3t)(q1, m3); + glm_mat3_transpose(m3); + glm_mat4_identity(m1); + glm_mat4_ins3(m3, m1); + + GLM(mat4_quat)(m1, q2); + + GLM(quat_mat3t)(q2, m3); + glm_mat3_transpose(m3); + glm_mat4_identity(m2); + glm_mat4_ins3(m3, m2); + + /* 2. test first quat and generated one equality */ + ASSERTIFY(test_assert_quat_eq_abs(q1, q2)); + + /* 3. test first rot and second rotation */ + /* almost equal */ + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f)); + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_lerp) { + versor v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + versor v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + versor v3; + + GLM(quat_lerp)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(quat_lerp)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_lerpc) { + versor v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + versor v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + versor v3; + + GLM(quat_lerpc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(quat_lerpc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + GLM(quat_lerpc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + ASSERT(test_eq(v3[3], -10.0f)) + + GLM(quat_lerpc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + ASSERT(test_eq(v3[3], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_nlerp) { + versor q1, q2, q3, q4; + vec3 v1 = {10.0f, 0.0f, 0.0f}, v2; + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(90.0f), v1); + + GLM(quat_nlerp)(q1, q2, 1.0f, q3); + glm_quat_normalize(q2); + ASSERTIFY(test_assert_quat_eq(q2, q3)); + + glm_quatv(q1, glm_rad(30.001f), v1); + glm_quatv(q2, glm_rad(30.002f), v1); + GLM(quat_nlerp)(q1, q2, 0.7f, q3); + glm_quat_lerp(q1, q2, 0.7f, q4); + ASSERTIFY(test_assert_quat_eq(q3, q4)); + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(90.0f), v1); + GLM(quat_nlerp)(q1, q2, 0.5f, q3); + + glm_quat_axis(q3, v2); + glm_vec3_normalize(v1); + glm_vec3_normalize(v2); + + ASSERT(glm_quat_angle(q3) > glm_rad(30.0f)); + ASSERT(glm_quat_angle(q3) < glm_rad(90.0f)); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_slerp) { + versor q1, q2, q3, q4; + vec3 v1 = {10.0f, 0.0f, 0.0f}, v2; + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(90.0f), v1); + + q1[0] = 10.0f; + GLM(quat_slerp)(q1, q2, 1.0f, q3); + ASSERTIFY(test_assert_quat_eq(q1, q3)); + + glm_quatv(q1, glm_rad(30.001f), v1); + glm_quatv(q2, glm_rad(30.002f), v1); + GLM(quat_slerp)(q1, q2, 0.7f, q3); + glm_quat_lerp(q1, q2, 0.7f, q4); + ASSERTIFY(test_assert_quat_eq(q3, q4)); + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(90.0f), v1); + GLM(quat_slerp)(q1, q2, 0.5f, q3); + + glm_quat_axis(q3, v2); + glm_vec3_normalize(v1); + glm_vec3_normalize(v2); + + ASSERT(glm_quat_angle(q3) > glm_rad(30.0f)); + ASSERT(glm_quat_angle(q3) < glm_rad(90.0f)); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_look) { + versor q1; + vec3 v1 = {0.0f, 1.0f, 0.0f}; + mat4 m1, m2; + + glm_quat(q1, glm_rad(90.0f), 0.0f, 1.0f, 0.0f); + GLM(quat_look)(v1, q1, m1); + + glm_look(v1, (vec3){-1.0f, 0.0f, 0.0f}, GLM_YUP, m2); + ASSERTIFY(test_assert_mat4_eq(m1, m2)); + + glm_quat(q1, glm_rad(180.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_look)(v1, q1, m1); + + glm_look(v1, (vec3){0.0f, 0.0f, 1.0f}, (vec3){0.0f, -1.0f, 0.0f}, m2); + + ASSERTIFY(test_assert_mat4_eq(m1, m2)); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_for) { + versor q1, q2; + + glm_quat(q1, glm_rad(90.0f), 0.0f, 1.0f, 0.0f); + GLM(quat_for)((vec3){-1.0f, 0.0f, 0.0f}, (vec3){0.0f, 1.0f, 0.0f}, q2); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + glm_quat(q2, glm_rad(90.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_for)((vec3){0.0f, 1.0f, 0.0f}, (vec3){0.0f, 0.0f, 1.0f}, q1); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + glm_quat(q2, glm_rad(180.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_for)((vec3){0.0f, 0.0f, 1.0f}, (vec3){0.0f, -1.0f, 0.0f}, q1); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_forp) { + versor q1, q2; + + glm_quat(q1, glm_rad(90.0f), 0.0f, 1.0f, 0.0f); + GLM(quat_forp)((vec3){2.0f, 0.0f, 0.0f}, + (vec3){1.0f, 0.0f, 0.0f}, + (vec3){0.0f, 1.0f, 0.0f}, + q2); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + glm_quat(q2, glm_rad(90.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_forp)((vec3){0.0f, 1.0f, 0.0f}, + (vec3){0.0f, 2.0f, 0.0f}, + (vec3){0.0f, 0.0f, 1.0f}, + q1); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + glm_quat(q2, glm_rad(180.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_forp)((vec3){0.0f, 1.0f, 1.0f}, + (vec3){0.0f, 1.0f, 2.0f}, + (vec3){0.0f, -1.0f, 0.0f}, + q1); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_rotatev) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, v2 = {1.0f, 1.0f, 1.0f}; + versor q; + + /* rotate X around Y = -Z */ + glm_quatv(q, GLM_PI_2f, GLM_YUP); + GLM(quat_rotatev)(q, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + glm_quatv(q, GLM_PI_2f, GLM_XUP); + GLM(quat_rotatev)(q, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around Z = -X */ + glm_quatv(q, GLM_PI_2f, GLM_ZUP); + GLM(quat_rotatev)(q, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate v2 around Y by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_YUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_YUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_YUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around X by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_XUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around Z by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_ZUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_rotate) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT, m2; + versor q1; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + /* rotate X around Y = -Z */ + glm_quatv(q1, GLM_PI_2f, GLM_YUP); + GLM(quat_rotate)(m1, q1, m1); + glm_rotate_make(m2, GLM_PI_2f, GLM_YUP); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + glm_mat4_identity(m1); + glm_mat4_identity(m2); + + /* rotate -Z around X = Y */ + glm_quatv(q1, GLM_PI_2f, GLM_XUP); + GLM(quat_rotate)(m1, q1, m1); + glm_rotate(m2, GLM_PI_2f, GLM_XUP); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_mat4_identity(m1); + glm_mat4_identity(m2); + + /* rotate Y around X = +Z */ + glm_quatv(q1, GLM_PI_2f, GLM_XUP); + GLM(quat_rotate)(m1, q1, m1); + glm_rotate(m2, GLM_PI_2f, GLM_XUP); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_rotate_at) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + versor q1; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + glm_quatv(q1, GLM_PI_2f, GLM_YUP); + GLM(quat_rotate_at)(m1, q1, (vec3){0.5f, 0.0f, 0.0f}); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.5f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_mat4_identity(m1); + + glm_quatv(q1, GLM_PI_2f, GLM_ZUP); + GLM(quat_rotate_at)(m1, q1, (vec3){0.0f, 0.0f, 0.0f}); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.5f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_mat4_identity(m1); + + v1[0] = 1.0f; + v1[1] = 1.0f; + v1[2] = 1.0f; + + glm_quatv(q1, GLM_PI_2f, GLM_XUP); + GLM(quat_rotate_at)(m1, q1, GLM_VEC3_ZERO); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_rotate_atm) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + versor q1; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + glm_quatv(q1, GLM_PI_2f, GLM_YUP); + GLM(quat_rotate_atm)(m1, q1, (vec3){0.5f, 0.0f, 0.0f}); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.5f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_quatv(q1, GLM_PI_2f, GLM_ZUP); + GLM(quat_rotate_atm)(m1, q1, (vec3){0.0f, 0.0f, 0.0f}); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.5f)) + ASSERT(test_eq(v1[2], -0.5f)) + + v1[0] = 1.0f; + v1[1] = 1.0f; + v1[2] = 1.0f; + + glm_quatv(q1, GLM_PI_2f, GLM_XUP); + GLM(quat_rotate_atm)(m1, q1, GLM_VEC3_ZERO); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_ray.h b/libs/cglm/test/src/test_ray.h new file mode 100644 index 0000000..c1b0281 --- /dev/null +++ b/libs/cglm/test/src/test_ray.h @@ -0,0 +1,34 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, ray_triangle) { + /* Check whether a simple hit is recognized with the right distance */ + vec3 origin = { 0.0f, 0.0f, 0.0f}; + vec3 direction = { 1.0f, 0.0f, 0.0f}; + vec3 opposite = {-1.0f, 0.0f, 0.0f}; + vec3 v0 = { 5.0f, -1.0f, 1.0f}; + vec3 v1 = { 5.0f, -1.0f, -1.0f}; + vec3 v2 = { 5.0f, 1.0f, 0.0f}; + float d; + bool hit; + + hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, &d); + ASSERT(hit); + ASSERT(fabsf(d - 5.0f) <= 0.0000009); + + /* Check whether a simple miss works */ + hit = GLM(ray_triangle)(origin, opposite, v0, v1, v2, &d); + ASSERT(!hit); + + /* Check that we can disregard distance and pass NULL pointer instead */ + hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, NULL); + ASSERT(hit); + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_struct.c b/libs/cglm/test/src/test_struct.c new file mode 100644 index 0000000..ce79356 --- /dev/null +++ b/libs/cglm/test/src/test_struct.c @@ -0,0 +1,78 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(mat3s_identity_init) { + mat3s mat3_identity = GLMS_MAT3_IDENTITY_INIT; + mat3 mat3_identity_a = GLM_MAT3_IDENTITY_INIT; + test_assert_mat3_eq(mat3_identity.raw, mat3_identity_a); + TEST_SUCCESS +} + +TEST_IMPL(mat3s_zero_init) { + mat3s mat3_zero = GLMS_MAT3_ZERO_INIT; + mat3 mat3_zero_a = GLM_MAT3_ZERO_INIT; + test_assert_mat3_eq(mat3_zero.raw, mat3_zero_a); + TEST_SUCCESS +} + +TEST_IMPL(mat4s_identity_init) { + mat4s mat4_identity = GLMS_MAT4_IDENTITY_INIT; + mat4 mat4_identity_a = GLM_MAT4_IDENTITY_INIT; + test_assert_mat4_eq(mat4_identity.raw, mat4_identity_a); + TEST_SUCCESS +} + +TEST_IMPL(mat4s_zero_init) { + mat4s mat4_zero = GLMS_MAT4_ZERO_INIT; + mat4 mat4_zero_a = GLM_MAT4_ZERO_INIT; + test_assert_mat4_eq(mat4_zero.raw, mat4_zero_a); + TEST_SUCCESS +} + +TEST_IMPL(quats_zero_init) { + versors quat_zero = GLMS_QUAT_IDENTITY_INIT; + versor quat_zero_a = GLM_QUAT_IDENTITY_INIT; + test_assert_quat_eq(quat_zero.raw, quat_zero_a); + TEST_SUCCESS +} + +TEST_IMPL(vec3s_one_init) { + vec3s vec3_one = GLMS_VEC3_ONE_INIT; + vec3 vec3_one_a = GLM_VEC3_ONE_INIT; + test_assert_vec3_eq(vec3_one.raw, vec3_one_a); + TEST_SUCCESS +} + +TEST_IMPL(vec3s_zero_init) { + vec3s vec3_zero = GLMS_VEC3_ZERO_INIT; + vec3 vec3_zero_a = GLM_VEC3_ZERO_INIT; + test_assert_vec3_eq(vec3_zero.raw, vec3_zero_a); + TEST_SUCCESS +} + +TEST_IMPL(vec4s_black_init) { + vec4s vec4_black = GLMS_VEC4_BLACK_INIT; + vec4 vec4_black_a = GLM_VEC4_BLACK_INIT; + test_assert_vec4_eq(vec4_black.raw, vec4_black_a); + TEST_SUCCESS +} + +TEST_IMPL(vec4s_one_init) { + vec4s vec4_one = GLMS_VEC4_ONE_INIT; + vec4 vec4_one_a = GLM_VEC4_ONE_INIT; + test_assert_vec4_eq(vec4_one.raw, vec4_one_a); + TEST_SUCCESS +} + +TEST_IMPL(vec4s_zero_init) { + vec4s vec4_zero = GLMS_VEC4_ZERO_INIT; + vec4 vec4_zero_a = GLM_VEC4_ZERO_INIT; + test_assert_vec4_eq(vec4_zero.raw, vec4_zero_a); + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_vec2.h b/libs/cglm/test/src/test_vec2.h new file mode 100644 index 0000000..9e53f72 --- /dev/null +++ b/libs/cglm/test/src/test_vec2.h @@ -0,0 +1,625 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#ifndef CGLM_TEST_VEC2_ONCE +#define CGLM_TEST_VEC2_ONCE + +/* Macros */ + +TEST_IMPL(MACRO_GLM_VEC2_ONE_INIT) { + vec2 v = GLM_VEC2_ONE_INIT; + + ASSERT(test_eq(v[0], 1.0f)) + ASSERT(test_eq(v[1], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC2_ZERO_INIT) { + vec2 v = GLM_VEC2_ZERO_INIT; + + ASSERT(test_eq(v[0], 0.0f)) + ASSERT(test_eq(v[1], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC2_ONE) { + ASSERT(test_eq(GLM_VEC2_ONE[0], 1.0f)) + ASSERT(test_eq(GLM_VEC2_ONE[1], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC2_ZERO) { + ASSERT(test_eq(GLM_VEC2_ZERO[0], 0.0f)) + ASSERT(test_eq(GLM_VEC2_ZERO[0], 0.0f)) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_VEC2_ONCE */ + +TEST_IMPL(GLM_PREFIX, vec2) { + vec4 v4 = {10.0f, 9.0f, 8.0f, 7.0f}; + vec3 v3 = {11.0f, 12.0f, 13.0f}; + vec2 v2; + + GLM(vec2)(v4, v2); + ASSERT(test_eq(v2[0], v4[0])) + ASSERT(test_eq(v2[1], v4[1])) + + GLM(vec2)(v3, v2); + ASSERT(test_eq(v2[0], v3[0])) + ASSERT(test_eq(v2[1], v3[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_copy) { + vec2 v1 = {10.0f, 9.0f}; + vec2 v2 = {1.0f, 2.0f}; + + GLM(vec2_copy)(v1, v2); + + ASSERTIFY(test_assert_vec2_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_zero) { + vec2 v1 = {10.0f, 9.0f}; + vec2 v2 = {1.0f, 2.0f}; + + GLM(vec2_zero)(v1); + GLM(vec2_zero)(v2); + + ASSERTIFY(test_assert_vec2_eq(v1, GLM_VEC2_ZERO)) + ASSERTIFY(test_assert_vec2_eq(v2, GLM_VEC2_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_one) { + vec2 v1 = {10.0f, 9.0f}; + vec2 v2 = {1.0f, 2.0f}; + + GLM(vec2_one)(v1); + GLM(vec2_one)(v2); + + ASSERTIFY(test_assert_vec2_eq(v1, GLM_VEC2_ONE)) + ASSERTIFY(test_assert_vec2_eq(v2, GLM_VEC2_ONE)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_dot) { + vec2 a = {10.0f, 9.0f}; + vec2 b = {1.0f, 2.0f}; + float dot1, dot2; + + dot1 = GLM(vec2_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_cross) { + vec2 a = {10.0f, 9.0f}; + vec2 b = {1.0f, 2.0f}; + float cprod; + + cprod = a[0] * b[1] - a[1] * b[0]; + + ASSERT(test_eq(glm_vec2_cross(a, b), cprod)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_norm2) { + vec2 a = {10.0f, 9.0f}; + float n1, n2; + + n1 = GLM(vec2_norm2)(a); + n2 = a[0] * a[0] + a[1] * a[1]; + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_norm) { + vec2 a = {10.0f, 9.0f}; + float n1, n2; + + n1 = GLM(vec2_norm)(a); + n2 = sqrtf(a[0] * a[0] + a[1] * a[1]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_add) { + vec2 a = {-10.0f, 9.0f}; + vec2 b = {12.0f, 19.0f}; + vec2 c, d; + + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + + GLM(vec2_add)(a, b, d); + + ASSERTIFY(test_assert_vec2_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_adds) { + vec4 a = {-10.0f, 9.0f}; + vec4 c, d; + float s = 7.0f; + + c[0] = a[0] + s; + c[1] = a[1] + s; + + GLM(vec2_adds)(a, s, d); + + ASSERTIFY(test_assert_vec2_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_sub) { + vec2 a = {-10.0f, 9.0f}; + vec2 b = {12.0f, 19.0f}; + vec2 c, d; + + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + + GLM(vec2_sub)(a, b, d); + + ASSERTIFY(test_assert_vec2_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_subs) { + vec2 a = {-10.0f, 9.0f}; + vec2 c, d; + float s = 7.0f; + + c[0] = a[0] - s; + c[1] = a[1] - s; + + GLM(vec2_subs)(a, s, d); + + ASSERTIFY(test_assert_vec2_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_mul) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3; + + GLM(vec2_mul)(v1, v2, v3); + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_scale) { + vec2 v1 = {2.0f, -3.0f}, v2; + float s = 7.0f; + + GLM(vec2_scale)(v1, s, v2); + + ASSERT(test_eq(v1[0] * s, v2[0])) + ASSERT(test_eq(v1[1] * s, v2[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_scale_as) { + vec2 v1 = {2.0f, -3.0f}, v2; + float s = 7.0f; + float norm; + + GLM(vec2_scale_as)(v1, s, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_div) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3; + + GLM(vec2_div)(v1, v2, v3); + + ASSERT(test_eq(v1[0] / v2[0], v3[0])) + ASSERT(test_eq(v1[1] / v2[1], v3[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_divs) { + vec2 v1 = {2.0f, -3.0f}, v2; + float s = 7.0f; + + GLM(vec2_divs)(v1, s, v2); + + ASSERT(test_eq(v1[0] / s, v2[0])) + ASSERT(test_eq(v1[1] / s, v2[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_addadd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_addadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] + v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] + v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_subadd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_subadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] - v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] - v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_muladd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_muladd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] * v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] * v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_muladds) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {1.0f, 2.0f}, + v3 = {1.0f, 2.0f}; + float s = 9.0f; + + GLM(vec2_muladds)(v1, s, v3); + + ASSERT(test_eq(v2[0] + v1[0] * s, v3[0])) + ASSERT(test_eq(v2[1] + v1[1] * s, v3[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_maxadd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_maxadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_max(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_max(v1[1], v2[1]), v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_minadd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_minadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_min(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_min(v1[1], v2[1]), v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_negate_to) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3, v4; + + GLM(vec2_negate_to)(v1, v3); + GLM(vec2_negate_to)(v2, v4); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_negate) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {2.0f, -3.0f}, + v4 = {-3.0f, 4.0f}; + + GLM(vec2_negate)(v1); + GLM(vec2_negate)(v2); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_normalize) { + vec2 v1 = {2.0f, -3.0f}, v2 = {2.0f, -3.0f}; + float s = 1.0f; + float norm; + + GLM(vec2_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + + glm_vec2_zero(v1); + GLM(vec2_normalize)(v1); + ASSERTIFY(test_assert_vec2_eq(v1, GLM_VEC2_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_normalize_to) { + vec2 v1 = {2.0f, -3.0f}, v2; + float s = 1.0f; + float norm; + + GLM(vec2_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + + glm_vec2_zero(v1); + GLM(vec2_normalize_to)(v1, v2); + ASSERTIFY(test_assert_vec2_eq(v2, GLM_VEC2_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_rotate) { + vec2 v1 = {1.0f, 0.0f}; + + GLM(vec2_rotate)(v1, GLM_PI_2f, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + + GLM(vec2_rotate)(v1, GLM_PI_2f, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + GLM(vec2_rotate)(v1, GLM_PI_2f, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + + GLM(vec2_rotate)(v1, GLM_PI_2f, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_distance2) { + vec2 v1 = {30.0f, 0.0f}, + v2 = {0.0f, 0.0f}, + v3 = {3.0f, 10.0f}, + v4 = {0.46f, 4.0f}; + float d; + + d = GLM(vec2_distance2)(v1, v2); + ASSERT(test_eq(d, 30.0f * 30.0f)) + + d = GLM(vec2_distance2)(v3, v4); + ASSERT(test_eq(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_distance) { + vec2 v1 = {30.0f, 0.0f}, + v2 = {0.0f, 0.0f}, + v3 = {3.0f, 10.0f}, + v4 = {0.46f, 4.0f}; + float d; + + d = GLM(vec2_distance)(v1, v2); + ASSERT(test_eq(d, 30.0f)) + + d = GLM(vec2_distance)(v3, v4); + ASSERT(test_eq(sqrtf(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f)), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_maxv) { + vec2 v1, v2, v3; + vec2 v5 = {-1.456f, -1.456f}; + vec2 v6 = {11.0f, 11.0f}; + vec2 v7 = {78.0f, -78.0f}; + + GLM(vec2_maxv)(v5, v6, v1); + GLM(vec2_maxv)(v5, v7, v2); + GLM(vec2_maxv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], 11.0f)) + ASSERT(test_eq(v1[1], 11.0f)) + + ASSERT(test_eq(v2[0], 78.0f)) + ASSERT(test_eq(v2[1], -1.456f)) + + ASSERT(test_eq(v3[0], 78.0f)) + ASSERT(test_eq(v3[1], 11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_minv) { + vec2 v1, v2, v3; + vec2 v5 = {-1.456f, -1.456f}; + vec2 v6 = {11.0f, 11.0f}; + vec2 v7 = {78.0f, -78.0f}; + + GLM(vec2_minv)(v5, v6, v1); + GLM(vec2_minv)(v5, v7, v2); + GLM(vec2_minv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], -1.456f)) + ASSERT(test_eq(v1[1], -1.456f)) + + ASSERT(test_eq(v2[0], -1.456f)) + ASSERT(test_eq(v2[1], -78.0f)) + + ASSERT(test_eq(v3[0], 11.0f)) + ASSERT(test_eq(v3[1], -78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_clamp) { + vec2 v1 = {-1.456f, -11.456f}; + vec2 v2 = {0.110f, 111.0f}; + vec2 v3 = {78.0f, 32.0f}; + + GLM(vec2_clamp)(v1, -1.03f, 30.0f); + GLM(vec2_clamp)(v2, 0.11f, 111.0f); + GLM(vec2_clamp)(v3, -88.0f, 70.0f); + + ASSERT(test_eq(v1[0], -1.03f)) + ASSERT(test_eq(v1[1], -1.03f)) + + ASSERT(test_eq(v2[0], 0.11f)) + ASSERT(test_eq(v2[1], 111.0f)) + + ASSERT(test_eq(v3[0], 70.0f)) + ASSERT(test_eq(v3[1], 32.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_lerp) { + vec2 v1 = {-100.0f, -200.0f}; + vec2 v2 = {100.0f, 200.0f}; + vec2 v3; + + GLM(vec2_lerp)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + + GLM(vec2_lerp)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_complex_mul) { + vec2 v1 = { 3.0f, 5.0f }, + v2 = { 7.0f, 11.0f }, + v3 = { cosf(M_PI/4.0f), sinf(M_PI/4.0f) }; + + GLM(vec2_complex_mul)(v1, v2, v2); + ASSERTIFY(test_assert_vec2_eq(v2, (vec2){ -34, 68 })) + + GLM(vec2_complex_mul)(v3, v3, v3); + ASSERTIFY(test_assert_vec2_eq(v3, (vec2){ 0.0f, 1.0f })) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_complex_div) { + vec2 v1 = { -34.0f, 68.0f }, + v2 = { 3.0f, 5.0f }, + v3 = { cosf(M_PI/4.0f), sinf(M_PI/4.0f) }, + v4 = { cosf(M_PI/4.0f), -sinf(M_PI/4.0f) }; + + GLM(vec2_complex_div)(v1, v2, v2); + ASSERTIFY(test_assert_vec2_eq(v2, (vec2){ 7.0f, 11.0f })) + + GLM(vec2_complex_div)(v3, v4, v4); + ASSERTIFY(test_assert_vec2_eq(v4, (vec2){ 0.0f, 1.0f })) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_vec3.h b/libs/cglm/test/src/test_vec3.h new file mode 100644 index 0000000..44a9847 --- /dev/null +++ b/libs/cglm/test/src/test_vec3.h @@ -0,0 +1,1731 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#define TEST_GLM_SHUFFLE3(z, y, x) (((z) << 4) | ((y) << 2) | (x)) + +#ifndef CGLM_TEST_VEC3_ONCE +#define CGLM_TEST_VEC3_ONCE + +/* Macros */ + +TEST_IMPL(MACRO_GLM_VEC3_ONE_INIT) { + vec3 v = GLM_VEC3_ONE_INIT; + + ASSERT(test_eq(v[0], 1.0f)) + ASSERT(test_eq(v[1], 1.0f)) + ASSERT(test_eq(v[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC3_ZERO_INIT) { + vec3 v = GLM_VEC3_ZERO_INIT; + + ASSERT(test_eq(v[0], 0.0f)) + ASSERT(test_eq(v[1], 0.0f)) + ASSERT(test_eq(v[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC3_ONE) { + ASSERT(test_eq(GLM_VEC3_ONE[0], 1.0f)) + ASSERT(test_eq(GLM_VEC3_ONE[1], 1.0f)) + ASSERT(test_eq(GLM_VEC3_ONE[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC3_ZERO) { + ASSERT(test_eq(GLM_VEC3_ZERO[0], 0.0f)) + ASSERT(test_eq(GLM_VEC3_ZERO[1], 0.0f)) + ASSERT(test_eq(GLM_VEC3_ZERO[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_YUP) { + ASSERT(test_eq(GLM_YUP[0], 0.0f)) + ASSERT(test_eq(GLM_YUP[1], 1.0f)) + ASSERT(test_eq(GLM_YUP[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_ZUP) { + ASSERT(test_eq(GLM_ZUP[0], 0.0f)) + ASSERT(test_eq(GLM_ZUP[1], 0.0f)) + ASSERT(test_eq(GLM_ZUP[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_XUP) { + ASSERT(test_eq(GLM_XUP[0], 1.0f)) + ASSERT(test_eq(GLM_XUP[1], 0.0f)) + ASSERT(test_eq(GLM_XUP[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_FORWARD_RH) { + ASSERT(test_eq(GLM_FORWARD[0], 0.0f)) + ASSERT(test_eq(GLM_FORWARD[1], 0.0f)) + ASSERT(test_eq(GLM_FORWARD[2], -1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_SHUFFLE3) { + ASSERT(TEST_GLM_SHUFFLE3(1, 0, 0) == GLM_SHUFFLE3(1, 0, 0)) + ASSERT(TEST_GLM_SHUFFLE3(0, 1, 0) == GLM_SHUFFLE3(0, 1, 0)) + ASSERT(TEST_GLM_SHUFFLE3(0, 0, 1) == GLM_SHUFFLE3(0, 0, 1)) + ASSERT(TEST_GLM_SHUFFLE3(1, 0, 0) == GLM_SHUFFLE3(1, 0, 0)) + ASSERT(TEST_GLM_SHUFFLE3(1, 0, 1) == GLM_SHUFFLE3(1, 0, 1)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_XXX) { + ASSERT(TEST_GLM_SHUFFLE3(0, 0, 0) == GLM_XXX) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_YYY) { + ASSERT(TEST_GLM_SHUFFLE3(1, 1, 1) == GLM_YYY) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_ZZZ) { + ASSERT(TEST_GLM_SHUFFLE3(2, 2, 2) == GLM_ZZZ) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_ZYX) { + ASSERT(TEST_GLM_SHUFFLE3(0, 1, 2) == GLM_ZYX) + TEST_SUCCESS +} + +/* Deprecated */ + +TEST_IMPL(MACRO_glm_vec3_dup) { + vec3 v1 = {13.0f, 12.0f, 11.0f}, v2; + + glm_vec3_dup(v1, v2); + + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_flipsign) { + vec3 v1 = {13.0f, -12.0f, 11.0f}, + v2 = {13.0f, -12.0f, 11.0f}, + v3 = {-13.0f, 12.0f, -11.0f}; + + glm_vec3_flipsign(v1); + glmc_vec3_flipsign(v2); + + ASSERTIFY(test_assert_vec3_eq(v1, v3)) + ASSERTIFY(test_assert_vec3_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_flipsign_to) { + vec3 v1 = {13.0f, -12.0f, 11.0f}, + v2 = {-13.0f, 12.0f, -11.0f}, + v3, v4; + + glm_vec3_flipsign_to(v1, v3); + glmc_vec3_flipsign_to(v1, v4); + + ASSERTIFY(test_assert_vec3_eq(v2, v3)) + ASSERTIFY(test_assert_vec3_eq(v2, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_inv) { + vec3 v1 = {13.0f, -12.0f, 11.0f}, + v2 = {13.0f, -12.0f, 11.0f}, + v3 = {-13.0f, 12.0f, -11.0f}; + + glm_vec3_inv(v1); + glmc_vec3_inv(v2); + + ASSERTIFY(test_assert_vec3_eq(v1, v3)) + ASSERTIFY(test_assert_vec3_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_inv_to) { + vec3 v1 = {13.0f, -12.0f, 11.0f}, + v2 = {-13.0f, 12.0f, -11.0f}, + v3, v4; + + glm_vec3_inv_to(v1, v3); + glmc_vec3_inv_to(v1, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + ASSERTIFY(test_assert_vec3_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_mulv) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3, v4; + + glm_vec3_mulv(v1, v2, v3); + glmc_vec3_mulv(v1, v2, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + ASSERT(test_eq(v1[2] * v2[2], v3[2])) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_VEC3_ONCE */ + +/* --- */ + +TEST_IMPL(GLM_PREFIX, vec3) { + vec4 v4 = {10.0f, 9.0f, 8.0f, 7.0f}; + vec3 v3; + + GLM(vec3)(v4, v3); + + ASSERT(test_eq(v3[0], v4[0])) + ASSERT(test_eq(v3[1], v4[1])) + ASSERT(test_eq(v3[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_copy) { + vec3 v1 = {10.0f, 9.0f, 8.0f}; + vec3 v2 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_copy)(v1, v2); + + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_zero) { + vec3 v1 = {10.0f, 9.0f, 8.0f}; + vec3 v2 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_zero)(v1); + GLM(vec3_zero)(v2); + + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ZERO)) + ASSERTIFY(test_assert_vec3_eq(v2, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_one) { + vec3 v1 = {10.0f, 9.0f, 8.0f}; + vec3 v2 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_one)(v1); + GLM(vec3_one)(v2); + + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ONE)) + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ONE)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_dot) { + vec3 a = {10.0f, 9.0f, 8.0f}; + vec3 b = {1.0f, 2.0f, 3.0f}; + float dot1, dot2; + + dot1 = GLM(vec3_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + + +TEST_IMPL(GLM_PREFIX, dot) { + /* SAME AS VEC3_DOT */ + + vec3 a = {10.0f, 9.0f, 8.0f}; + vec3 b = {1.0f, 2.0f, 3.0f}; + float dot1, dot2; + + dot1 = GLM(vec3_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_norm2) { + vec3 a = {10.0f, 9.0f, 8.0f}; + float n1, n2; + + n1 = GLM(vec3_norm2)(a); + n2 = a[0] * a[0] + a[1] * a[1] + a[2] * a[2]; + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_norm) { + vec3 a = {10.0f, 9.0f, 8.0f}; + float n1, n2; + + n1 = GLM(vec3_norm)(a); + n2 = sqrtf(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_norm_one) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + float n1, n2; + + n1 = GLM(vec3_norm_one)(a); + n2 = fabsf(a[0]) + fabsf(a[1]) + fabsf(a[2]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_norm_inf) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + float n1, n2; + + n1 = GLM(vec3_norm_inf)(a); + n2 = fabsf(a[0]); + + if (n2 < fabsf(a[1])) + n2 = fabsf(a[1]); + + if (n2 < fabsf(a[2])) + n2 = fabsf(a[2]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_add) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + vec3 b = {12.0f, 19.0f, -18.0f}; + vec3 c, d; + + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + c[2] = a[2] + b[2]; + + GLM(vec3_add)(a, b, d); + + ASSERTIFY(test_assert_vec3_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_adds) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + vec3 c, d; + float s = 7.0f; + + c[0] = a[0] + s; + c[1] = a[1] + s; + c[2] = a[2] + s; + + GLM(vec3_adds)(a, s, d); + + ASSERTIFY(test_assert_vec3_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_sub) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + vec3 b = {12.0f, 19.0f, -18.0f}; + vec3 c, d; + + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + c[2] = a[2] - b[2]; + + GLM(vec3_sub)(a, b, d); + + ASSERTIFY(test_assert_vec3_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_subs) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + vec3 c, d; + float s = 7.0f; + + c[0] = a[0] - s; + c[1] = a[1] - s; + c[2] = a[2] - s; + + GLM(vec3_subs)(a, s, d); + + ASSERTIFY(test_assert_vec3_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_mul) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3; + + GLM(vec3_mul)(v1, v2, v3); + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + ASSERT(test_eq(v1[2] * v2[2], v3[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_scale) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 7.0f; + + GLM(vec3_scale)(v1, s, v2); + + ASSERT(test_eq(v1[0] * s, v2[0])) + ASSERT(test_eq(v1[1] * s, v2[1])) + ASSERT(test_eq(v1[2] * s, v2[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_scale_as) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 7.0f; + float norm; + + GLM(vec3_scale_as)(v1, s, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_div) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3; + + GLM(vec3_div)(v1, v2, v3); + + ASSERT(test_eq(v1[0] / v2[0], v3[0])) + ASSERT(test_eq(v1[1] / v2[1], v3[1])) + ASSERT(test_eq(v1[2] / v2[2], v3[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_divs) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 7.0f; + + GLM(vec3_divs)(v1, s, v2); + + ASSERT(test_eq(v1[0] / s, v2[0])) + ASSERT(test_eq(v1[1] / s, v2[1])) + ASSERT(test_eq(v1[2] / s, v2[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_addadd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_addadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] + v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] + v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] + v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_subadd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_subadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] - v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] - v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] - v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_muladd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_muladd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] * v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] * v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] * v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_muladds) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {1.0f, 2.0f, 3.0f}, + v3 = {1.0f, 2.0f, 3.0f}; + float s = 9.0f; + + GLM(vec3_muladds)(v1, s, v3); + + ASSERT(test_eq(v2[0] + v1[0] * s, v3[0])) + ASSERT(test_eq(v2[1] + v1[1] * s, v3[1])) + ASSERT(test_eq(v2[2] + v1[2] * s, v3[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_maxadd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_maxadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_max(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_max(v1[1], v2[1]), v4[1])) + ASSERT(test_eq(v3[2] + glm_max(v1[2], v2[2]), v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_minadd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_minadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_min(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_min(v1[1], v2[1]), v4[1])) + ASSERT(test_eq(v3[2] + glm_min(v1[2], v2[2]), v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_negate_to) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3, v4; + + GLM(vec3_negate_to)(v1, v3); + GLM(vec3_negate_to)(v2, v4); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + ASSERT(test_eq(-v1[2], v3[2])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + ASSERT(test_eq(-v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_negate) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {2.0f, -3.0f, 4.0f}, + v4 = {-3.0f, 4.0f, -5.0f}; + + GLM(vec3_negate)(v1); + GLM(vec3_negate)(v2); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + ASSERT(test_eq(-v1[2], v3[2])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + ASSERT(test_eq(-v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_normalize) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {2.0f, -3.0f, 4.0f}; + float s = 1.0f; + float norm; + + GLM(vec3_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + glm_vec3_zero(v1); + GLM(vec3_normalize)(v1); + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_normalize_to) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 1.0f; + float norm; + + GLM(vec3_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + glm_vec3_zero(v1); + GLM(vec3_normalize_to)(v1, v2); + ASSERTIFY(test_assert_vec3_eq(v2, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, normalize) { + /* SAME AS VEC3_NORMALIZE */ + + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {2.0f, -3.0f, 4.0f}; + float s = 1.0f; + float norm; + + GLM(vec3_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + glm_vec3_zero(v1); + GLM(vec3_normalize)(v1); + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, normalize_to) { + /* SAME AS VEC3_NORMALIZE_TO */ + + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 1.0f; + float norm; + + GLM(vec3_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + glm_vec3_zero(v1); + GLM(vec3_normalize_to)(v1, v2); + ASSERTIFY(test_assert_vec3_eq(v2, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_cross) { + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {12.0f, -31.0f, 43.0f}, v3, v4; + + GLM(vec3_cross)(v1, v2, v3); + + v4[0] = v1[1] * v2[2] - v1[2] * v2[1]; + v4[1] = v1[2] * v2[0] - v1[0] * v2[2]; + v4[2] = v1[0] * v2[1] - v1[1] * v2[0]; + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_crossn) { + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {12.0f, -31.0f, 43.0f}, v3, v4; + + GLM(vec3_crossn)(v1, v2, v3); + + v4[0] = v1[1] * v2[2] - v1[2] * v2[1]; + v4[1] = v1[2] * v2[0] - v1[0] * v2[2]; + v4[2] = v1[0] * v2[1] - v1[1] * v2[0]; + + glm_normalize(v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, cross) { + /* SAME AS VEC3_CROSS */ + + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {12.0f, -31.0f, 43.0f}, v3, v4; + + GLM(vec3_cross)(v1, v2, v3); + + v4[0] = v1[1] * v2[2] - v1[2] * v2[1]; + v4[1] = v1[2] * v2[0] - v1[0] * v2[2]; + v4[2] = v1[0] * v2[1] - v1[1] * v2[0]; + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_angle) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, + v2 = {1.0f, 0.0f, 1.0f}, + v3 = {0.0f, 1.0f, 0.0f}; + float a; + + a = GLM(vec3_angle)(v1, v1); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, 0.0f)) + + a = GLM(vec3_angle)(v1, v2); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_4f)) + + a = GLM(vec3_angle)(v1, v3); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_rotate) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, v2 = {1.0f, 1.0f, 1.0f}; + + /* rotate X around Y = -Z */ + GLM(vec3_rotate)(v1, GLM_PI_2f, GLM_YUP); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + GLM(vec3_rotate)(v1, GLM_PI_2f, GLM_XUP); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around Z = -X */ + GLM(vec3_rotate)(v1, GLM_PI_2f, GLM_ZUP); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_YUP); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_YUP); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_YUP); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around X by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_XUP); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around Z by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_ZUP); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_rotate_m4) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, v2 = {1.0f, 1.0f, 1.0f}; + mat4 x, y, z; + + glm_rotate_make(x, GLM_PI_2f, GLM_XUP); + glm_rotate_make(y, GLM_PI_2f, GLM_YUP); + glm_rotate_make(z, GLM_PI_2f, GLM_ZUP); + + /* rotate X around Y = -Z */ + GLM(vec3_rotate_m4)(y, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + GLM(vec3_rotate_m4)(x, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around X = -X */ + GLM(vec3_rotate_m4)(z, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m4)(y, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m4)(y, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m4)(y, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around X by 90deg */ + GLM(vec3_rotate_m4)(x, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around Z by 90deg */ + GLM(vec3_rotate_m4)(z, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_rotate_m3) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, v2 = {1.0f, 1.0f, 1.0f}; + mat4 x0, y0, z0; + mat3 x, y, z; + + glm_rotate_make(x0, GLM_PI_2f, GLM_XUP); + glm_rotate_make(y0, GLM_PI_2f, GLM_YUP); + glm_rotate_make(z0, GLM_PI_2f, GLM_ZUP); + + glm_mat4_pick3(x0, x); + glm_mat4_pick3(y0, y); + glm_mat4_pick3(z0, z); + + /* rotate X around Y = -Z */ + GLM(vec3_rotate_m3)(y, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + GLM(vec3_rotate_m3)(x, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around Z = -X */ + GLM(vec3_rotate_m3)(z, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m3)(y, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m3)(y, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m3)(y, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around X by 90deg */ + GLM(vec3_rotate_m3)(x, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around Z by 90deg */ + GLM(vec3_rotate_m3)(z, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_proj) { + vec3 v1 = {3.0f, 4.0f, 0.0f}, + v2 = {10.0f, 0.0f, 0.0f}, + v3 = {0.0f, 10.0f, 0.0f}, + v4 = {3.0f, 0.0f, 0.0f}, + v5 = {0.0f, 4.0f, 0.0f}, + v6; + + GLM(vec3_proj)(v1, v2, v6); + ASSERTIFY(test_assert_vec3_eq(v4, v6)) + + GLM(vec3_proj)(v1, v3, v6); + ASSERTIFY(test_assert_vec3_eq(v5, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_center) { + vec3 v1 = {30.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f}, + v3 = {15.0f, 0.0f, 0.0f}, + v4 = {3.0f, 10.0f, 120.0f}, + v5 = {0.46f, 4.0f, 14.0f}, + v6; + + GLM(vec3_center)(v1, v2, v6); + ASSERTIFY(test_assert_vec3_eq(v3, v6)) + + GLM(vec3_center)(v4, v5, v6); + ASSERT(test_eq((v4[0] + v5[0]) * 0.5f, v6[0])) + ASSERT(test_eq((v4[1] + v5[1]) * 0.5f, v6[1])) + ASSERT(test_eq((v4[2] + v5[2]) * 0.5f, v6[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_distance2) { + vec3 v1 = {30.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f}, + v3 = {3.0f, 10.0f, 120.0f}, + v4 = {0.46f, 4.0f, 14.0f}; + float d; + + d = GLM(vec3_distance2)(v1, v2); + ASSERT(test_eq(d, 30.0f * 30.0f)) + + d = GLM(vec3_distance2)(v3, v4); + ASSERT(test_eq(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f) + + powf(v3[2] - v4[2], 2.0f), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_distance) { + vec3 v1 = {30.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f}, + v3 = {3.0f, 10.0f, 120.0f}, + v4 = {0.46f, 4.0f, 14.0f}; + float d; + + d = GLM(vec3_distance)(v1, v2); + ASSERT(test_eq(d, 30.0f)) + + d = GLM(vec3_distance)(v3, v4); + ASSERT(test_eq(sqrtf(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f) + + powf(v3[2] - v4[2], 2.0f)), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_maxv) { + vec3 v1, v2, v3; + vec3 v5 = {-1.456f, -1.456f, 241.456f}; + vec3 v6 = {11.0f, 11.0f, 11.0f}; + vec3 v7 = {78.0f, -78.0f, 7.0f}; + + GLM(vec3_maxv)(v5, v6, v1); + GLM(vec3_maxv)(v5, v7, v2); + GLM(vec3_maxv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], 11.0f)) + ASSERT(test_eq(v1[1], 11.0f)) + ASSERT(test_eq(v1[2], 241.456f)) + + ASSERT(test_eq(v2[0], 78.0f)) + ASSERT(test_eq(v2[1], -1.456f)) + ASSERT(test_eq(v2[2], 241.456f)) + + ASSERT(test_eq(v3[0], 78.0f)) + ASSERT(test_eq(v3[1], 11.0f)) + ASSERT(test_eq(v3[2], 11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_minv) { + vec3 v1, v2, v3; + vec3 v5 = {-1.456f, -1.456f, 241.456f}; + vec3 v6 = {11.0f, 11.0f, 11.0f}; + vec3 v7 = {78.0f, -78.0f, 7.0f}; + + GLM(vec3_minv)(v5, v6, v1); + GLM(vec3_minv)(v5, v7, v2); + GLM(vec3_minv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], -1.456f)) + ASSERT(test_eq(v1[1], -1.456f)) + ASSERT(test_eq(v1[2], 11.0f)) + + ASSERT(test_eq(v2[0], -1.456f)) + ASSERT(test_eq(v2[1], -78.0f)) + ASSERT(test_eq(v2[2], 7.0f)) + + ASSERT(test_eq(v3[0], 11.0f)) + ASSERT(test_eq(v3[1], -78.0f)) + ASSERT(test_eq(v3[2], 7.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_ortho) { + vec3 v1, v2, v3, v4 = {1.f, 1.f, 1.f}; + vec3 v5, v6, v7, v8; + float a; + + test_rand_vec3(v1); + test_rand_vec3(v2); + test_rand_vec3(v3); + + GLM(vec3_ortho)(v1, v5); + GLM(vec3_ortho)(v2, v6); + GLM(vec3_ortho)(v3, v7); + GLM(vec3_ortho)(v4, v8); + + a = glm_vec3_angle(v1, v5); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + a = glm_vec3_angle(v2, v6); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + a = glm_vec3_angle(v3, v7); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + a = glm_vec3_angle(v4, v8); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_clamp) { + vec3 v1 = {-1.456f, -11.456f, 31.456f}; + vec3 v2 = {0.110f, 111.0f, 11.0f}; + vec3 v3 = {78.0f, 32.0f, -78.0f}; + + GLM(vec3_clamp)(v1, -1.03f, 30.0f); + GLM(vec3_clamp)(v2, 0.11f, 111.0f); + GLM(vec3_clamp)(v3, -88.0f, 70.0f); + + ASSERT(test_eq(v1[0], -1.03f)) + ASSERT(test_eq(v1[1], -1.03f)) + ASSERT(test_eq(v1[2], 30.0f)) + + ASSERT(test_eq(v2[0], 0.11f)) + ASSERT(test_eq(v2[1], 111.0f)) + ASSERT(test_eq(v2[2], 11.0f)) + + ASSERT(test_eq(v3[0], 70.0f)) + ASSERT(test_eq(v3[1], 32.0f)) + ASSERT(test_eq(v3[2], -78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_lerp) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2 = {100.0f, 200.0f, 10.0f}; + vec3 v3; + + GLM(vec3_lerp)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + + GLM(vec3_lerp)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_lerpc) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2 = {100.0f, 200.0f, 10.0f}; + vec3 v3; + + GLM(vec3_lerpc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + + GLM(vec3_lerpc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + + GLM(vec3_lerpc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + + GLM(vec3_lerpc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_mix) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2 = {100.0f, 200.0f, 10.0f}; + vec3 v3; + + GLM(vec3_mix)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + + GLM(vec3_mix)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_mixc) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2 = {100.0f, 200.0f, 10.0f}; + vec3 v3; + + GLM(vec3_mixc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + + GLM(vec3_mixc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + + GLM(vec3_mixc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + + GLM(vec3_mixc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_step_uni) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2; + + GLM(vec3_step_uni)(-2.5f, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + + GLM(vec3_step_uni)(-10.0f, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + GLM(vec3_step_uni)(-1000.0f, v1, v2); + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_step) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 s1 = {-100.0f, 0.0f, 10.0f}; + vec3 s2 = {100.0f, -220.0f, -10.0f}; + vec3 s3 = {100.0f, 200.0f, 10.0f}; + vec3 v2; + + GLM(vec3_step)(s1, v1, v2); + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + + GLM(vec3_step)(s2, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + GLM(vec3_step)(s3, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_smoothstep_uni) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2; + + GLM(vec3_smoothstep_uni)(-200.0f, -100.0f, v1, v2); + ASSERT(test_eq_th(v2[0], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + + GLM(vec3_smoothstep_uni)(-250.0f, -200.0f, v1, v2); + ASSERT(test_eq_th(v2[0], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + + GLM(vec3_smoothstep_uni)(-200.0f, 200, v1, v2); + ASSERT(v2[0] > 0.0f && v2[0] < 0.25f) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(v2[2] > 0.0f && v2[2] < 0.5f) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_smoothstep) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 e1_0 = {-100.0f, 0.0f, -11.0f}; + vec3 e1_1 = {50.0f, 10.0f, 20.0f}; + vec3 e2_0 = {-180.0f, -300.0f, -93.0f}; + vec3 e2_1 = {100.0f, 120.0f, -10.0f}; + vec3 e3_0 = {-12.0f, 100.0f, 0.0f}; + vec3 e3_1 = {100.0f, 200.0f, 10.0f}; + vec3 v2; + + GLM(vec3_smoothstep)(e1_0, e1_1, v1, v2); + ASSERT(test_eq_th(v2[0], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(v2[2] > 0.0f && v2[2] < 0.1f) + + GLM(vec3_smoothstep)(e2_0, e2_1, v1, v2); + ASSERT(v2[0] > 0.0f && v2[0] < 0.25f) + ASSERT(v2[1] > 0.0f && v2[1] < 0.15f) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + + GLM(vec3_smoothstep)(e3_0, e3_1, v1, v2); + ASSERT(test_eq_th(v2[0], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 0.0f, 1e-5f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_smoothinterp) { + vec3 e1_0 = {-100.0f, 0.0f, -11.0f}; + vec3 e1_1 = {50.0f, 10.0f, 20.0f}; + vec3 e2_0 = {80.0f, -220.0f, -19.0f}; + vec3 e2_1 = {100.0f, -200.0f, -10.0f}; + vec3 e3_0 = {-12.0f, 100.0f, 0.0f}; + vec3 e3_1 = {100.0f, 200.0f, 10.0f}; + vec3 v2; + + GLM(vec3_smoothinterp)(e1_0, e1_1, 0.5f, v2); + ASSERT(v2[0] >= e1_0[0] && v2[0] <= e1_1[0]) + ASSERT(v2[1] >= e1_0[1] && v2[1] <= e1_1[1]) + ASSERT(v2[2] >= e1_0[2] && v2[2] <= e1_1[2]) + + GLM(vec3_smoothinterp)(e2_0, e2_1, 0.5, v2); + ASSERT(v2[0] >= e2_0[0] && v2[0] <= e2_1[0]) + ASSERT(v2[1] >= e2_0[1] && v2[1] <= e2_1[1]) + ASSERT(v2[2] >= e2_0[2] && v2[2] <= e2_1[2]) + + GLM(vec3_smoothinterp)(e3_0, e3_1, 1.0, v2); + ASSERT(v2[0] >= e3_0[0] && v2[0] <= e3_1[0]) + ASSERT(v2[1] >= e3_0[1] && v2[1] <= e3_1[1]) + ASSERT(v2[2] >= e3_0[2] && v2[2] <= e3_1[2]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_smoothinterpc) { + vec3 e1_0 = {-100.0f, 0.0f, -11.0f}; + vec3 e1_1 = {50.0f, 10.0f, 20.0f}; + vec3 e2_0 = {80.0f, -220.0f, -19.0f}; + vec3 e2_1 = {100.0f, -200.0f, -10.0f}; + vec3 e3_0 = {-12.0f, 100.0f, 0.0f}; + vec3 e3_1 = {100.0f, 200.0f, 10.0f}; + vec3 v2; + + GLM(vec3_smoothinterpc)(e1_0, e1_1, -0.5f, v2); + ASSERT(v2[0] >= e1_0[0] && v2[0] <= e1_1[0]) + ASSERT(v2[1] >= e1_0[1] && v2[1] <= e1_1[1]) + ASSERT(v2[2] >= e1_0[2] && v2[2] <= e1_1[2]) + + GLM(vec3_smoothinterpc)(e2_0, e2_1, 0.5f, v2); + ASSERT(v2[0] >= e2_0[0] && v2[0] <= e2_1[0]) + ASSERT(v2[1] >= e2_0[1] && v2[1] <= e2_1[1]) + ASSERT(v2[2] >= e2_0[2] && v2[2] <= e2_1[2]) + + GLM(vec3_smoothinterpc)(e3_0, e3_1, 2.0f, v2); + ASSERT(v2[0] >= e3_0[0] && v2[0] <= e3_1[0]) + ASSERT(v2[1] >= e3_0[1] && v2[1] <= e3_1[1]) + ASSERT(v2[2] >= e3_0[2] && v2[2] <= e3_1[2]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_swizzle) { + vec3 v; + + /* ZYX */ + v[0] = 1; + v[1] = 2; + v[2] = 3; + + glm_vec3_swizzle(v, GLM_ZYX, v); + ASSERTIFY(test_assert_vec3_eq(v, (vec3){3, 2, 1})) + + glm_vec3_swizzle(v, GLM_XXX, v); + ASSERTIFY(test_assert_vec3_eq(v, (vec3){3, 3, 3})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + + glm_vec3_swizzle(v, GLM_YYY, v); + ASSERTIFY(test_assert_vec3_eq(v, (vec3){2, 2, 2})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + + glm_vec3_swizzle(v, GLM_ZZZ, v); + ASSERTIFY(test_assert_vec3_eq(v, (vec3){3, 3, 3})) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_broadcast) { + vec3 v1, v2, v3; + vec3 v5 = {-1.456f, -1.456f, -1.456f}; + vec3 v6 = {11.0f, 11.0f, 11.0f}; + vec3 v7 = {78.0f, 78.0f, 78.0f}; + + GLM(vec3_broadcast)(-1.456f, v1); + GLM(vec3_broadcast)(11.0f, v2); + GLM(vec3_broadcast)(78.0f, v3); + + ASSERTIFY(test_assert_vec3_eq(v1, v5)) + ASSERTIFY(test_assert_vec3_eq(v2, v6)) + ASSERTIFY(test_assert_vec3_eq(v3, v7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_fill) { + vec3 v1, v2, v3; + vec3 v5 = {-1.456f, -1.456f, -1.456f}; + vec3 v6 = {11.0f, 11.0f, 11.0f}; + vec3 v7 = {78.0f, 78.0f, 78.0f}; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.0f); + + ASSERTIFY(test_assert_vec3_eq(v1, v5)) + ASSERTIFY(test_assert_vec3_eq(v2, v6)) + ASSERTIFY(test_assert_vec3_eq(v3, v7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eq) { + vec3 v1, v2, v3; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.1f); + + ASSERT(GLM(vec3_eq)(v1, -1.456f)) + ASSERT(GLM(vec3_eq)(v2, 11.0f)) + ASSERT(!GLM(vec3_eq)(v3, 78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eq_eps) { + vec3 v1, v2, v3; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.1f); + + ASSERT(GLM(vec3_eq_eps)(v1, -1.456f)) + ASSERT(GLM(vec3_eq_eps)(v2, 11.0f)) + ASSERT(!GLM(vec3_eq_eps)(v3, 78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eq_all) { + vec3 v1, v2, v3; + vec3 v4 = {2.104f, -3.012f, -4.10f}; + vec3 v5 = {-12.35f, -31.140f, -43.502f}; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.0f); + + ASSERT(GLM(vec3_eq_all)(v1)) + ASSERT(GLM(vec3_eq_all)(v2)) + ASSERT(GLM(vec3_eq_all)(v3)) + ASSERT(!GLM(vec3_eq_all)(v4)) + ASSERT(!GLM(vec3_eq_all)(v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eqv) { + vec3 v1, v2, v3, v4, v5; + vec3 v6 = {-1.456f, -1.456f, -1.456f}; + vec3 v7 = {11.0f, 11.0f, 11.0f}; + vec3 v8 = {78.0f, 78.0f, -43.502f}; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.0f); + + test_rand_vec3(v4); + test_rand_vec3(v5); + + ASSERT(GLM(vec3_eqv)(v1, v6)) + ASSERT(GLM(vec3_eqv)(v2, v7)) + ASSERT(!GLM(vec3_eqv)(v3, v8)) + ASSERT(!GLM(vec3_eqv)(v4, v5)) + ASSERT(GLM(vec3_eqv)(v5, v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eqv_eps) { + vec3 v1, v2, v3, v4, v5; + vec3 v6 = {-1.456f, -1.456f, -1.456f}; + vec3 v7 = {11.0f, 11.0f, 11.0f}; + vec3 v8 = {78.0f, 78.0f, -43.502f}; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.0f); + + test_rand_vec3(v4); + test_rand_vec3(v5); + + ASSERT(GLM(vec3_eqv_eps)(v1, v6)) + ASSERT(GLM(vec3_eqv_eps)(v2, v7)) + ASSERT(!GLM(vec3_eqv_eps)(v3, v8)) + ASSERT(!GLM(vec3_eqv_eps)(v4, v5)) + ASSERT(GLM(vec3_eqv_eps)(v5, v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_max) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -11.0f, 11.0f}; + + ASSERT(test_eq(GLM(vec3_max)(v1), 2.104f)) + ASSERT(test_eq(GLM(vec3_max)(v2), -12.35f)) + ASSERT(isinf(GLM(vec3_max)(v3))) + ASSERT(isnan(GLM(vec3_max)(v4))) + ASSERT(isnan(GLM(vec3_max)(v5))) + ASSERT(test_eq(GLM(vec3_max)(v6), 11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_min) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -11.0f, 11.0f}; + + ASSERT(test_eq(GLM(vec3_min)(v1), -4.10f)) + ASSERT(test_eq(GLM(vec3_min)(v2), -43.502f)) + ASSERT(test_eq(GLM(vec3_min)(v3), 0.0f)) + ASSERT(isnan(GLM(vec3_min)(v4))) + ASSERT(isnan(GLM(vec3_min)(v5))) + ASSERT(test_eq(GLM(vec3_min)(v6), -11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_isnan) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -1.0f, 11.0f}; + + ASSERT(!GLM(vec3_isnan)(v1)) + ASSERT(!GLM(vec3_isnan)(v2)) + ASSERT(!GLM(vec3_isnan)(v3)) + ASSERT(GLM(vec3_isnan)(v4)) + ASSERT(GLM(vec3_isnan)(v5)) + ASSERT(!GLM(vec3_isnan)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_isinf) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -1.0f, 11.0f}; + + ASSERT(!GLM(vec3_isinf)(v1)) + ASSERT(!GLM(vec3_isinf)(v2)) + ASSERT(GLM(vec3_isinf)(v3)) + ASSERT(GLM(vec3_isinf)(v4)) + ASSERT(!GLM(vec3_isinf)(v5)) + ASSERT(!GLM(vec3_isinf)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_isvalid) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -1.0f, 11.0f}; + + ASSERT(GLM(vec3_isvalid)(v1)) + ASSERT(GLM(vec3_isvalid)(v2)) + ASSERT(!GLM(vec3_isvalid)(v3)) + ASSERT(!GLM(vec3_isvalid)(v4)) + ASSERT(!GLM(vec3_isvalid)(v5)) + ASSERT(GLM(vec3_isvalid)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_sign) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3, v4; + vec3 v5 = {1.0f, -1.0f, -1.0f}, v6 = {-1.0f, -1.0f, -1.0f}; + + GLM(vec3_sign)(v1, v3); + GLM(vec3_sign)(v2, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v5)) + ASSERTIFY(test_assert_vec3_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_abs) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3, v4; + vec3 v5 = {2.104f, 3.012f, 4.10f}, v6 = {12.35f, 31.140f, 43.502f}; + + GLM(vec3_abs)(v1, v3); + GLM(vec3_abs)(v2, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v5)) + ASSERTIFY(test_assert_vec3_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_fract) { + vec3 v1 = {2.104f, 3.012f, 4.10f}, v2 = {12.35f, 31.140f, 43.502f}, v3, v4; + vec3 v5 = {0.104f, 0.012f, 0.10f}, v6 = {0.35f, 0.140f, 0.502f}; + + GLM(vec3_fract)(v1, v3); + GLM(vec3_fract)(v2, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v5)) + ASSERTIFY(test_assert_vec3_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_hadd) { + vec3 v1 = {2.0f, 3.0f, 4.0f}, v2 = {12.0f, 31.0f, 43.0f}; + float r1, r2, r3, r4; + + r1 = GLM(vec3_hadd)(v1); + r2 = GLM(vec3_hadd)(v2); + + r3 = v1[0] + v1[1] + v1[2]; + r4 = v2[0] + v2[1] + v2[2]; + + ASSERT(test_eq(r1, r3)) + ASSERT(test_eq(r2, r4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_sqrt) { + vec3 v1 = {2.0f, 3.0f, 4.0f}, v2 = {12.0f, 31.0f, 43.0f}, v3, v4; + + GLM(vec3_sqrt)(v1, v3); + GLM(vec3_sqrt)(v2, v4); + + ASSERT(test_eq(sqrtf(v1[0]), v3[0])) + ASSERT(test_eq(sqrtf(v1[1]), v3[1])) + ASSERT(test_eq(sqrtf(v1[2]), v3[2])) + + ASSERT(test_eq(sqrtf(v2[0]), v4[0])) + ASSERT(test_eq(sqrtf(v2[1]), v4[1])) + ASSERT(test_eq(sqrtf(v2[2]), v4[2])) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_vec4.h b/libs/cglm/test/src/test_vec4.h new file mode 100644 index 0000000..abb882f --- /dev/null +++ b/libs/cglm/test/src/test_vec4.h @@ -0,0 +1,1420 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#define TEST_GLM_SHUFFLE4(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2)|(w)) + +#ifndef CGLM_TEST_VEC4_ONCE +#define CGLM_TEST_VEC4_ONCE + +/* Macros */ + +TEST_IMPL(MACRO_GLM_VEC4_ONE_INIT) { + vec4 v = GLM_VEC4_ONE_INIT; + + ASSERT(test_eq(v[0], 1.0f)) + ASSERT(test_eq(v[1], 1.0f)) + ASSERT(test_eq(v[2], 1.0f)) + ASSERT(test_eq(v[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC4_ZERO_INIT) { + vec4 v = GLM_VEC4_ZERO_INIT; + + ASSERT(test_eq(v[0], 0.0f)) + ASSERT(test_eq(v[1], 0.0f)) + ASSERT(test_eq(v[2], 0.0f)) + ASSERT(test_eq(v[3], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC4_ONE) { + ASSERT(test_eq(GLM_VEC4_ONE[0], 1.0f)) + ASSERT(test_eq(GLM_VEC4_ONE[1], 1.0f)) + ASSERT(test_eq(GLM_VEC4_ONE[2], 1.0f)) + ASSERT(test_eq(GLM_VEC4_ONE[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC4_ZERO) { + ASSERT(test_eq(GLM_VEC4_ZERO[0], 0.0f)) + ASSERT(test_eq(GLM_VEC4_ZERO[1], 0.0f)) + ASSERT(test_eq(GLM_VEC4_ZERO[2], 0.0f)) + ASSERT(test_eq(GLM_VEC4_ZERO[3], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_XXXX) { + ASSERT(TEST_GLM_SHUFFLE4(0, 0, 0, 0) == GLM_XXXX) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_YYYY) { + ASSERT(TEST_GLM_SHUFFLE4(1, 1, 1, 1) == GLM_YYYY) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_ZZZZ) { + ASSERT(TEST_GLM_SHUFFLE4(2, 2, 2, 2) == GLM_ZZZZ) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_WZYX) { + ASSERT(TEST_GLM_SHUFFLE4(0, 1, 2, 3) == GLM_WZYX) + TEST_SUCCESS +} + +/* Deprecated */ + +TEST_IMPL(MACRO_glm_vec4_dup) { + vec4 v1 = {13.0f, 12.0f, 11.0f, 56.0f}, v2; + + glm_vec4_dup(v1, v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_flipsign) { + vec4 v1 = {13.0f, -12.0f, 11.0f, 56.0f}, + v2 = {13.0f, -12.0f, 11.0f, 56.0f}, + v3 = {-13.0f, 12.0f, -11.0f, -56.0f}; + + glm_vec4_flipsign(v1); + glmc_vec4_flipsign(v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v3)) + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_flipsign_to) { + vec4 v1 = {13.0f, -12.0f, 11.0f, 56.0f}, + v2 = {-13.0f, 12.0f, -11.0f, -56.0f}, + v3, v4; + + glm_vec4_flipsign_to(v1, v3); + glmc_vec4_flipsign_to(v1, v4); + + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + ASSERTIFY(test_assert_vec4_eq(v2, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_inv) { + vec4 v1 = {13.0f, -12.0f, 11.0f, 56.0f}, + v2 = {13.0f, -12.0f, 11.0f, 56.0f}, + v3 = {-13.0f, 12.0f, -11.0f, -56.0f}; + + glm_vec4_inv(v1); + glmc_vec4_inv(v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v3)) + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_inv_to) { + vec4 v1 = {13.0f, -12.0f, 11.0f, 56.0f}, + v2 = {-13.0f, 12.0f, -11.0f, -56.0f}, + v3, v4; + + glm_vec4_inv_to(v1, v3); + glmc_vec4_inv_to(v1, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v4)) + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_mulv) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 56.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 56.0f}, + v3, v4; + + glm_vec4_mulv(v1, v2, v3); + glmc_vec4_mulv(v1, v2, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v4)) + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + ASSERT(test_eq(v1[2] * v2[2], v3[2])) + ASSERT(test_eq(v1[3] * v2[3], v3[3])) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_VEC4_ONCE */ + +/* --- */ + +TEST_IMPL(GLM_PREFIX, vec4) { + vec4 v1 = {10.0f, 9.0f, 8.0f}; + vec4 v2 = {10.0f, 9.0f, 8.0f, 7.0f}; + vec4 v3; + + GLM(vec4)(v1, 7.0f, v3); + + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_copy3) { + vec4 v4 = {10.0f, 9.0f, 8.0f, 7.0f}; + vec3 v3; + + GLM(vec4_copy3)(v4, v3); + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_copy) { + vec4 v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(vec4_copy)(v1, v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_ucopy) { + vec4 v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(vec4_ucopy)(v1, v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_zero) { + vec4 v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(vec4_zero)(v1); + GLM(vec4_zero)(v2); + + ASSERTIFY(test_assert_vec4_eq(v1, GLM_VEC4_ZERO)) + ASSERTIFY(test_assert_vec4_eq(v2, GLM_VEC4_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_one) { + vec4 v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(vec4_one)(v1); + GLM(vec4_one)(v2); + + ASSERTIFY(test_assert_vec4_eq(v1, GLM_VEC4_ONE)) + ASSERTIFY(test_assert_vec4_eq(v2, GLM_VEC4_ONE)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_dot) { + vec4 a = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 b = {1.0f, 2.0f, 3.0f, 4.0f}; + float dot1, dot2; + + dot1 = GLM(vec4_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_norm2) { + vec4 a = {10.0f, 9.0f, 8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(vec4_norm2)(a); + n2 = a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]; + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_norm) { + vec4 a = {10.0f, 9.0f, 8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(vec4_norm)(a); + n2 = sqrtf(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_norm_one) { + vec4 a = {-10.0f, 9.0f, -8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(vec4_norm_one)(a); + n2 = fabsf(a[0]) + fabsf(a[1]) + fabsf(a[2]) + fabsf(a[3]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_norm_inf) { + vec4 a = {-10.0f, 9.0f, -8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(vec4_norm_inf)(a); + n2 = fabsf(a[0]); + + if (n2 < fabsf(a[1])) + n2 = fabsf(a[1]); + + if (n2 < fabsf(a[2])) + n2 = fabsf(a[2]); + + if (n2 < fabsf(a[3])) + n2 = fabsf(a[3]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_add) { + vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f}; + vec4 b = {12.0f, 19.0f, -18.0f, 1.0f}; + vec4 c, d; + + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + c[2] = a[2] + b[2]; + c[3] = a[3] + b[3]; + + GLM(vec4_add)(a, b, d); + + ASSERTIFY(test_assert_vec4_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_adds) { + vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f}; + vec4 c, d; + float s = 7.0f; + + c[0] = a[0] + s; + c[1] = a[1] + s; + c[2] = a[2] + s; + c[3] = a[3] + s; + + GLM(vec4_adds)(a, s, d); + + ASSERTIFY(test_assert_vec4_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_sub) { + vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f}; + vec4 b = {12.0f, 19.0f, -18.0f, 1.0f}; + vec4 c, d; + + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + c[2] = a[2] - b[2]; + c[3] = a[3] - b[3]; + + GLM(vec4_sub)(a, b, d); + + ASSERTIFY(test_assert_vec4_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_subs) { + vec4 a = {-10.0f, 9.0f, -8.0f, 74.0f}; + vec4 c, d; + float s = 7.0f; + + c[0] = a[0] - s; + c[1] = a[1] - s; + c[2] = a[2] - s; + c[3] = a[3] - s; + + GLM(vec4_subs)(a, s, d); + + ASSERTIFY(test_assert_vec4_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_mul) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 56.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 46.0f}, + v3; + + GLM(vec4_mul)(v1, v2, v3); + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + ASSERT(test_eq(v1[2] * v2[2], v3[2])) + ASSERT(test_eq(v1[3] * v2[3], v3[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_scale) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2; + float s = 7.0f; + + GLM(vec4_scale)(v1, s, v2); + + ASSERT(test_eq(v1[0] * s, v2[0])) + ASSERT(test_eq(v1[1] * s, v2[1])) + ASSERT(test_eq(v1[2] * s, v2[2])) + ASSERT(test_eq(v1[3] * s, v2[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_scale_as) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2; + float s = 7.0f; + float norm; + + GLM(vec4_scale_as)(v1, s, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + ASSERT(test_eq(v1[3], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_div) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 40.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 2.0f}, + v3; + + GLM(vec4_div)(v1, v2, v3); + + ASSERT(test_eq(v1[0] / v2[0], v3[0])) + ASSERT(test_eq(v1[1] / v2[1], v3[1])) + ASSERT(test_eq(v1[2] / v2[2], v3[2])) + ASSERT(test_eq(v1[3] / v2[3], v3[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_divs) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 40.0f}, v2; + float s = 7.0f; + + GLM(vec4_divs)(v1, s, v2); + + ASSERT(test_eq(v1[0] / s, v2[0])) + ASSERT(test_eq(v1[1] / s, v2[1])) + ASSERT(test_eq(v1[2] / s, v2[2])) + ASSERT(test_eq(v1[3] / s, v2[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_addadd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_addadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] + v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] + v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] + v2[2], v4[2])) + ASSERT(test_eq(v3[3] + v1[3] + v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_subadd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_subadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] - v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] - v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] - v2[2], v4[2])) + ASSERT(test_eq(v3[3] + v1[3] - v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_muladd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_muladd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] * v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] * v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] * v2[2], v4[2])) + ASSERT(test_eq(v3[3] + v1[3] * v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_muladds) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {-3.0f, 4.0f, -5.0f, 20.0f}; + float s = 9.0f; + + GLM(vec4_muladds)(v1, s, v3); + + ASSERT(test_eq(v2[0] + v1[0] * s, v3[0])) + ASSERT(test_eq(v2[1] + v1[1] * s, v3[1])) + ASSERT(test_eq(v2[2] + v1[2] * s, v3[2])) + ASSERT(test_eq(v2[3] + v1[3] * s, v3[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_maxadd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_maxadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_max(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_max(v1[1], v2[1]), v4[1])) + ASSERT(test_eq(v3[2] + glm_max(v1[2], v2[2]), v4[2])) + ASSERT(test_eq(v3[3] + glm_max(v1[3], v2[3]), v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_minadd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_minadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_min(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_min(v1[1], v2[1]), v4[1])) + ASSERT(test_eq(v3[2] + glm_min(v1[2], v2[2]), v4[2])) + ASSERT(test_eq(v3[3] + glm_min(v1[3], v2[3]), v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_negate_to) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 60.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 34.0f}, + v3, v4; + + GLM(vec4_negate_to)(v1, v3); + GLM(vec4_negate_to)(v2, v4); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + ASSERT(test_eq(-v1[2], v3[2])) + ASSERT(test_eq(-v1[3], v3[3])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + ASSERT(test_eq(-v2[2], v4[2])) + ASSERT(test_eq(-v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_negate) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 60.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 34.0f}, + v3 = {2.0f, -3.0f, 4.0f, 60.0f}, + v4 = {-3.0f, 4.0f, -5.0f, 34.0f}; + + GLM(vec4_negate)(v1); + GLM(vec4_negate)(v2); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + ASSERT(test_eq(-v1[2], v3[2])) + ASSERT(test_eq(-v1[3], v3[3])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + ASSERT(test_eq(-v2[2], v4[2])) + ASSERT(test_eq(-v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_normalize) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2 = {2.0f, -3.0f, 4.0f, 5.0f}; + float s = 1.0f; + float norm; + + GLM(vec4_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + ASSERT(test_eq(v1[3], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + glm_vec4_zero(v1); + GLM(vec4_normalize)(v1); + ASSERTIFY(test_assert_vec4_eq(v1, GLM_VEC4_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_normalize_to) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2; + float s = 1.0f; + float norm; + + GLM(vec4_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + ASSERT(test_eq(v1[3], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + glm_vec4_zero(v1); + GLM(vec4_normalize_to)(v1, v2); + ASSERTIFY(test_assert_vec4_eq(v2, GLM_VEC4_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_distance2) { + vec4 v1 = {30.0f, 0.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f, 0.0f}, + v3 = {3.0f, 10.0f, 120.0f, 140.0f}, + v4 = {0.46f, 4.0f, 14.0f, 10.0f}; + float d; + + d = GLM(vec4_distance2)(v1, v2); + ASSERT(test_eq(d, 30.0f * 30.0f)) + + d = GLM(vec4_distance2)(v3, v4); + ASSERT(test_eq(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f) + + powf(v3[2] - v4[2], 2.0f) + + powf(v3[3] - v4[3], 2.0f), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_distance) { + vec4 v1 = {30.0f, 0.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f, 0.0f}, + v3 = {3.0f, 10.0f, 120.0f, 140.0f}, + v4 = {0.46f, 4.0f, 14.0f, 10.0f}; + float d; + + d = GLM(vec4_distance)(v1, v2); + ASSERT(test_eq(d, 30.0f)) + + d = GLM(vec4_distance)(v3, v4); + ASSERT(test_eq(sqrtf(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f) + + powf(v3[2] - v4[2], 2.0f) + + powf(v3[3] - v4[3], 2.0f)), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_maxv) { + vec4 v1, v2, v3; + vec4 v5 = {-1.456f, -1.456f, 241.456f, 10.0f}; + vec4 v6 = {11.0f, 11.0f, 11.0f, 90.0f}; + vec4 v7 = {78.0f, -78.0f, 7.0f, 5.0f}; + + GLM(vec4_maxv)(v5, v6, v1); + GLM(vec4_maxv)(v5, v7, v2); + GLM(vec4_maxv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], 11.0f)) + ASSERT(test_eq(v1[1], 11.0f)) + ASSERT(test_eq(v1[2], 241.456f)) + ASSERT(test_eq(v1[3], 90.0f)) + + ASSERT(test_eq(v2[0], 78.0f)) + ASSERT(test_eq(v2[1], -1.456f)) + ASSERT(test_eq(v2[2], 241.456f)) + ASSERT(test_eq(v2[3], 10.0f)) + + ASSERT(test_eq(v3[0], 78.0f)) + ASSERT(test_eq(v3[1], 11.0f)) + ASSERT(test_eq(v3[2], 11.0f)) + ASSERT(test_eq(v3[3], 90.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_minv) { + vec4 v1, v2, v3; + vec4 v5 = {-1.456f, -1.456f, 241.456f, 10.0f}; + vec4 v6 = {11.0f, 11.0f, 11.0f, 90.0f}; + vec4 v7 = {78.0f, -78.0f, 7.0f, 5.0f}; + + GLM(vec4_minv)(v5, v6, v1); + GLM(vec4_minv)(v5, v7, v2); + GLM(vec4_minv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], -1.456f)) + ASSERT(test_eq(v1[1], -1.456f)) + ASSERT(test_eq(v1[2], 11.0f)) + ASSERT(test_eq(v1[3], 10.0f)) + + ASSERT(test_eq(v2[0], -1.456f)) + ASSERT(test_eq(v2[1], -78.0f)) + ASSERT(test_eq(v2[2], 7.0f)) + ASSERT(test_eq(v2[3], 5.0f)) + + ASSERT(test_eq(v3[0], 11.0f)) + ASSERT(test_eq(v3[1], -78.0f)) + ASSERT(test_eq(v3[2], 7.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_clamp) { + vec4 v1 = {-1.456f, -11.456f, 31.456f, 67.04f}; + vec4 v2 = {0.110f, 111.0f, 11.0f, 90.0f}; + vec4 v3 = {78.0f, 32.0f, -78.0f, 3.0f}; + + GLM(vec4_clamp)(v1, -1.03f, 30.0f); + GLM(vec4_clamp)(v2, 0.11f, 111.0f); + GLM(vec4_clamp)(v3, -88.0f, 70.0f); + + ASSERT(test_eq(v1[0], -1.03f)) + ASSERT(test_eq(v1[1], -1.03f)) + ASSERT(test_eq(v1[2], 30.0f)) + ASSERT(test_eq(v1[3], 30.0f)) + + ASSERT(test_eq(v2[0], 0.11f)) + ASSERT(test_eq(v2[1], 111.0f)) + ASSERT(test_eq(v2[2], 11.0f)) + ASSERT(test_eq(v2[3], 90.0f)) + + ASSERT(test_eq(v3[0], 70.0f)) + ASSERT(test_eq(v3[1], 32.0f)) + ASSERT(test_eq(v3[2], -78.0f)) + ASSERT(test_eq(v3[3], 3.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_lerp) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v3; + + GLM(vec4_lerp)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(vec4_lerp)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_lerpc) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v3; + + GLM(vec4_lerpc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(vec4_lerpc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + GLM(vec4_lerpc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + ASSERT(test_eq(v3[3], -10.0f)) + + GLM(vec4_lerpc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + ASSERT(test_eq(v3[3], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_mix) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v3; + + GLM(vec4_mix)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(vec4_mix)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_mixc) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v3; + + GLM(vec4_mixc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(vec4_mixc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + GLM(vec4_mixc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + ASSERT(test_eq(v3[3], -10.0f)) + + GLM(vec4_mixc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + ASSERT(test_eq(v3[3], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_step_uni) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2; + + GLM(vec4_step_uni)(-2.5f, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + ASSERT(test_eq(v2[3], 0.0f)) + + GLM(vec4_step_uni)(-10.0f, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + GLM(vec4_step_uni)(-1000.0f, v1, v2); + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_step) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 s1 = {-100.0f, 0.0f, 10.0f, 10.0f}; + vec4 s2 = {100.0f, -220.0f, -10.0f, -10.0f}; + vec4 s3 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v2; + + GLM(vec4_step)(s1, v1, v2); + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + ASSERT(test_eq(v2[3], 0.0f)) + + GLM(vec4_step)(s2, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + GLM(vec4_step)(s3, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + ASSERT(test_eq(v2[3], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_smoothstep_uni) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2; + + GLM(vec4_smoothstep_uni)(-200.0f, -100.0f, v1, v2); + ASSERT(test_eq_th(v2[0], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[3], 1.0f, 1e-5f)) + + GLM(vec4_smoothstep_uni)(-250.0f, -200.0f, v1, v2); + ASSERT(test_eq_th(v2[0], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[3], 1.0f, 1e-5f)) + + GLM(vec4_smoothstep_uni)(-200.0f, 200.0f, v1, v2); + ASSERT(v2[0] > 0.0f && v2[0] < 0.25f) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(v2[2] > 0.0f && v2[2] < 0.5f) + ASSERT(v2[3] > 0.0f && v2[3] < 0.5f) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_smoothstep) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 e1_0 = {-100.0f, 0.0f, -11.0f, -11.0f}; + vec4 e1_1 = {50.0f, 10.0f, 20.0f, 20.0f}; + vec4 e2_0 = {-180.0f, -300.0f, -93.0f, -93.0f}; + vec4 e2_1 = {100.0f, 120.0f, -10.0f, -10.0f}; + vec4 e3_0 = {-12.0f, 100.0f, 0.0f, 0.0f}; + vec4 e3_1 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v2; + + GLM(vec4_smoothstep)(e1_0, e1_1, v1, v2); + ASSERT(test_eq_th(v2[0], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(v2[2] > 0.0f && v2[2] < 0.1f) + ASSERT(v2[3] > 0.0f && v2[3] < 0.1f) + + GLM(vec4_smoothstep)(e2_0, e2_1, v1, v2); + ASSERT(v2[0] > 0.0f && v2[0] < 0.25f) + ASSERT(v2[1] > 0.0f && v2[1] < 0.15f) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[3], 1.0f, 1e-5f)) + + GLM(vec4_smoothstep)(e3_0, e3_1, v1, v2); + ASSERT(test_eq_th(v2[0], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[3], 0.0f, 1e-5f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_smoothinterp) { + vec4 e1_0 = {-100.0f, 0.0f, -11.0f, -11.0f}; + vec4 e1_1 = {50.0f, 10.0f, 20.0f, 20.0f}; + vec4 e2_0 = {80.0f, -220.0f, -19.0f, -19.0f}; + vec4 e2_1 = {100.0f, -200.0f, -10.0f, -10.0f}; + vec4 e3_0 = {-12.0f, 100.0f, 0.0f, 0.0f}; + vec4 e3_1 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v2; + + GLM(vec4_smoothinterp)(e1_0, e1_1, 0.5f, v2); + ASSERT(v2[0] >= e1_0[0] && v2[0] <= e1_1[0]) + ASSERT(v2[1] >= e1_0[1] && v2[1] <= e1_1[1]) + ASSERT(v2[2] >= e1_0[2] && v2[2] <= e1_1[2]) + ASSERT(v2[3] >= e1_0[3] && v2[3] <= e1_1[3]) + + GLM(vec4_smoothinterp)(e2_0, e2_1, 0.5f, v2); + ASSERT(v2[0] >= e2_0[0] && v2[0] <= e2_1[0]) + ASSERT(v2[1] >= e2_0[1] && v2[1] <= e2_1[1]) + ASSERT(v2[2] >= e2_0[2] && v2[2] <= e2_1[2]) + ASSERT(v2[3] >= e2_0[3] && v2[3] <= e2_1[3]) + + GLM(vec4_smoothinterp)(e3_0, e3_1, 1.0f, v2); + ASSERT(v2[0] >= e3_0[0] && v2[0] <= e3_1[0]) + ASSERT(v2[1] >= e3_0[1] && v2[1] <= e3_1[1]) + ASSERT(v2[2] >= e3_0[2] && v2[2] <= e3_1[2]) + ASSERT(v2[3] >= e3_0[3] && v2[3] <= e3_1[3]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_smoothinterpc) { + vec4 e1_0 = {-100.0f, 0.0f, -11.0f, -11.0f}; + vec4 e1_1 = {50.0f, 10.0f, 20.0f, 20.0f}; + vec4 e2_0 = {80.0f, -220.0f, -19.0f, -19.0f}; + vec4 e2_1 = {100.0f, -200.0f, -10.0f, -10.0f}; + vec4 e3_0 = {-12.0f, 100.0f, 0.0f, 0.0f}; + vec4 e3_1 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v2; + + GLM(vec4_smoothinterpc)(e1_0, e1_1, -0.5f, v2); + ASSERT(v2[0] >= e1_0[0] && v2[0] <= e1_1[0]) + ASSERT(v2[1] >= e1_0[1] && v2[1] <= e1_1[1]) + ASSERT(v2[2] >= e1_0[2] && v2[2] <= e1_1[2]) + ASSERT(v2[3] >= e1_0[3] && v2[3] <= e1_1[3]) + + GLM(vec4_smoothinterpc)(e2_0, e2_1, 0.5f, v2); + ASSERT(v2[0] >= e2_0[0] && v2[0] <= e2_1[0]) + ASSERT(v2[1] >= e2_0[1] && v2[1] <= e2_1[1]) + ASSERT(v2[2] >= e2_0[2] && v2[2] <= e2_1[2]) + ASSERT(v2[3] >= e2_0[3] && v2[3] <= e2_1[3]) + + GLM(vec4_smoothinterpc)(e3_0, e3_1, 2.0f, v2); + ASSERT(v2[0] >= e3_0[0] && v2[0] <= e3_1[0]) + ASSERT(v2[1] >= e3_0[1] && v2[1] <= e3_1[1]) + ASSERT(v2[2] >= e3_0[2] && v2[2] <= e3_1[2]) + ASSERT(v2[3] >= e3_0[3] && v2[3] <= e3_1[3]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_cubic) { + vec4 v1 = {125.0f, 25.0f, 5.0f, 1.0f}; + vec4 v2 = {216.0f, 36.0f, 6.0f, 1.0f}; + vec4 v3, v4; + + ASSERT(test_eq(v1[0], v1[2] * v1[2] * v1[2])) + ASSERT(test_eq(v1[1], v1[2] * v1[2])) + ASSERT(test_eq(v1[3], 1.0f)) + + ASSERT(test_eq(v2[0], v2[2] * v2[2] * v2[2])) + ASSERT(test_eq(v2[1], v2[2] * v2[2])) + ASSERT(test_eq(v2[3], 1.0f)) + + GLM(vec4_cubic)(test_rand(), v3); + ASSERT(test_eq(v3[0], v3[2] * v3[2] * v3[2])) + ASSERT(test_eq(v3[1], v3[2] * v3[2])) + ASSERT(test_eq(v3[3], 1.0f)) + + GLM(vec4_cubic)(test_rand(), v4); + ASSERT(test_eq(v4[0], v4[2] * v4[2] * v4[2])) + ASSERT(test_eq(v4[1], v4[2] * v4[2])) + ASSERT(test_eq(v4[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_swizzle) { + vec4 v; + + /* ZYX */ + v[0] = 1; + v[1] = 2; + v[2] = 3; + v[3] = 4; + + glm_vec4_swizzle(v, GLM_WZYX, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){4, 3, 2, 1})) + + glm_vec4_swizzle(v, GLM_XXXX, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){4, 4, 4, 4})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + v[3] = 4; + + glm_vec4_swizzle(v, GLM_YYYY, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){2, 2, 2, 2})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + v[3] = 4; + + glm_vec4_swizzle(v, GLM_ZZZZ, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){3, 3, 3, 3})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + v[3] = 4; + + glm_vec4_swizzle(v, GLM_WWWW, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){4, 4, 4, 4})) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_broadcast) { + vec4 v1, v2, v3; + vec4 v5 = {-1.456f, -1.456f, -1.456f, -1.456f}; + vec4 v6 = {11.0f, 11.0f, 11.0f, 11.0f}; + vec4 v7 = {78.0f, 78.0f, 78.0f, 78.0f}; + + GLM(vec4_broadcast)(-1.456f, v1); + GLM(vec4_broadcast)(11.0f, v2); + GLM(vec4_broadcast)(78.0f, v3); + + ASSERTIFY(test_assert_vec4_eq(v1, v5)) + ASSERTIFY(test_assert_vec4_eq(v2, v6)) + ASSERTIFY(test_assert_vec4_eq(v3, v7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_fill) { + vec4 v1, v2, v3; + vec4 v5 = {-1.456f, -1.456f, -1.456f, -1.456f}; + vec4 v6 = {11.0f, 11.0f, 11.0f, 11.0f}; + vec4 v7 = {78.0f, 78.0f, 78.0f, 78.0f}; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.0f); + + ASSERTIFY(test_assert_vec4_eq(v1, v5)) + ASSERTIFY(test_assert_vec4_eq(v2, v6)) + ASSERTIFY(test_assert_vec4_eq(v3, v7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eq) { + vec4 v1, v2, v3; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.1f); + + ASSERT(GLM(vec4_eq)(v1, -1.456f)) + ASSERT(GLM(vec4_eq)(v2, 11.0f)) + ASSERT(!GLM(vec4_eq)(v3, 78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eq_eps) { + vec4 v1, v2, v3; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.1f); + + ASSERT(GLM(vec4_eq_eps)(v1, -1.456f)) + ASSERT(GLM(vec4_eq_eps)(v2, 11.0f)) + ASSERT(!GLM(vec4_eq_eps)(v3, 78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eq_all) { + vec4 v1, v2, v3; + vec4 v4 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v5 = {-12.35f, -31.140f, -43.502f, -43.502f}; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.0f); + + ASSERT(GLM(vec4_eq_all)(v1)) + ASSERT(GLM(vec4_eq_all)(v2)) + ASSERT(GLM(vec4_eq_all)(v3)) + ASSERT(!GLM(vec4_eq_all)(v4)) + ASSERT(!GLM(vec4_eq_all)(v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eqv) { + vec4 v1, v2, v3, v4, v5; + vec4 v6 = {-1.456f, -1.456f, -1.456f, -1.456f}; + vec4 v7 = {11.0f, 11.0f, 11.0f, 11.0f}; + vec4 v8 = {78.0f, 78.0f, -43.502f, -43.502f}; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.0f); + + test_rand_vec4(v4); + test_rand_vec4(v5); + + ASSERT(GLM(vec4_eqv)(v1, v6)) + ASSERT(GLM(vec4_eqv)(v2, v7)) + ASSERT(!GLM(vec4_eqv)(v3, v8)) + ASSERT(!GLM(vec4_eqv)(v4, v5)) + ASSERT(GLM(vec4_eqv)(v5, v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eqv_eps) { + vec4 v1, v2, v3, v4, v5; + vec4 v6 = {-1.456f, -1.456f, -1.456f, -1.456f}; + vec4 v7 = {11.0f, 11.0f, 11.0f, 11.0f}; + vec4 v8 = {78.0f, 78.0f, -43.502f, -43.502f}; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.0f); + + test_rand_vec4(v4); + test_rand_vec4(v5); + + ASSERT(GLM(vec4_eqv_eps)(v1, v6)) + ASSERT(GLM(vec4_eqv_eps)(v2, v7)) + ASSERT(!GLM(vec4_eqv_eps)(v3, v8)) + ASSERT(!GLM(vec4_eqv_eps)(v4, v5)) + ASSERT(GLM(vec4_eqv_eps)(v5, v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_max) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -11.0f, 11.0f, 11.0f}; + + ASSERT(test_eq(GLM(vec4_max)(v1), 2.104f)) + ASSERT(test_eq(GLM(vec4_max)(v2), -12.35f)) + ASSERT(isinf(GLM(vec4_max)(v3))) + ASSERT(isnan(GLM(vec4_max)(v4))) + ASSERT(isnan(GLM(vec4_max)(v5))) + ASSERT(test_eq(GLM(vec4_max)(v6), 11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_min) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -11.0f, 11.0f, 11.0f}; + + ASSERT(test_eq(GLM(vec4_min)(v1), -4.10f)) + ASSERT(test_eq(GLM(vec4_min)(v2), -43.502f)) + ASSERT(test_eq(GLM(vec4_min)(v3), 0.0f)) + ASSERT(isnan(GLM(vec4_min)(v4))) + ASSERT(isnan(GLM(vec4_min)(v5))) + ASSERT(test_eq(GLM(vec4_min)(v6), -11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_isnan) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -1.0f, 11.0f, 11.0f}; + + ASSERT(!GLM(vec4_isnan)(v1)) + ASSERT(!GLM(vec4_isnan)(v2)) + ASSERT(!GLM(vec4_isnan)(v3)) + ASSERT(GLM(vec4_isnan)(v4)) + ASSERT(GLM(vec4_isnan)(v5)) + ASSERT(!GLM(vec4_isnan)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_isinf) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -1.0f, 11.0f, 11.0f}; + + ASSERT(!GLM(vec4_isinf)(v1)) + ASSERT(!GLM(vec4_isinf)(v2)) + ASSERT(GLM(vec4_isinf)(v3)) + ASSERT(GLM(vec4_isinf)(v4)) + ASSERT(!GLM(vec4_isinf)(v5)) + ASSERT(!GLM(vec4_isinf)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_isvalid) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -1.0f, 11.0f, 11.0f}; + + ASSERT(GLM(vec4_isvalid)(v1)) + ASSERT(GLM(vec4_isvalid)(v2)) + ASSERT(!GLM(vec4_isvalid)(v3)) + ASSERT(!GLM(vec4_isvalid)(v4)) + ASSERT(!GLM(vec4_isvalid)(v5)) + ASSERT(GLM(vec4_isvalid)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_sign) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3, v4; + vec4 v5 = {1.0f, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -1.0f, -1.0f, -1.0f}; + + GLM(vec4_sign)(v1, v3); + GLM(vec4_sign)(v2, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v5)) + ASSERTIFY(test_assert_vec4_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_abs) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3, v4; + vec4 v5 = {2.104f, 3.012f, 4.10f, 4.10f}; + vec4 v6 = {12.35f, 31.140f, 43.502f, 43.502f}; + + GLM(vec4_abs)(v1, v3); + GLM(vec4_abs)(v2, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v5)) + ASSERTIFY(test_assert_vec4_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_fract) { + vec4 v1 = {2.104f, 3.012f, 4.10f, 4.10f}; + vec4 v2 = {12.35f, 31.140f, 43.502f, 43.502f}; + vec4 v3, v4; + vec4 v5 = {0.104f, 0.012f, 0.10f, 0.10f}; + vec4 v6 = {0.35f, 0.140f, 0.502f, 0.502f}; + + GLM(vec4_fract)(v1, v3); + GLM(vec4_fract)(v2, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v5)) + ASSERTIFY(test_assert_vec4_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_hadd) { + vec4 v1 = {2.0f, 3.0f, 4.0f, 4.0f}, v2 = {12.0f, 31.0f, 43.0f, 43.0f}; + float r1, r2, r3, r4; + + r1 = GLM(vec4_hadd)(v1); + r2 = GLM(vec4_hadd)(v2); + + r3 = v1[0] + v1[1] + v1[2] + v1[3]; + r4 = v2[0] + v2[1] + v2[2] + v2[3]; + + ASSERT(test_eq(r1, r3)) + ASSERT(test_eq(r2, r4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_sqrt) { + vec4 v1 = {2.0f, 3.0f, 4.0f, 4.0f}, v2 = {12.0f, 31.0f, 43.0f, 43.0f}; + vec4 v3, v4; + + GLM(vec4_sqrt)(v1, v3); + GLM(vec4_sqrt)(v2, v4); + + ASSERT(test_eq(sqrtf(v1[0]), v3[0])) + ASSERT(test_eq(sqrtf(v1[1]), v3[1])) + ASSERT(test_eq(sqrtf(v1[2]), v3[2])) + ASSERT(test_eq(sqrtf(v1[3]), v3[3])) + + ASSERT(test_eq(sqrtf(v2[0]), v4[0])) + ASSERT(test_eq(sqrtf(v2[1]), v4[1])) + ASSERT(test_eq(sqrtf(v2[2]), v4[2])) + ASSERT(test_eq(sqrtf(v2[3]), v4[3])) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/tests.c b/libs/cglm/test/src/tests.c new file mode 100644 index 0000000..1505e32 --- /dev/null +++ b/libs/cglm/test/src/tests.c @@ -0,0 +1,63 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* test inline */ +/*---------------------------------------------------------------------------*/ + + +#define GLM_PREFIX glm_ +#define GLM(X) (glm_ ## X) + +#include "test_vec2.h" +#include "test_vec3.h" +#include "test_vec4.h" +#include "test_ivec2.h" +#include "test_ivec3.h" +#include "test_ivec4.h" +#include "test_mat2.h" +#include "test_mat3.h" +#include "test_mat4.h" +#include "test_quat.h" +#include "test_project.h" +#include "test_plane.h" +#include "test_affine.h" +#include "test_affine2d.h" +#include "test_affine_mat.h" +#include "test_ray.h" +#include "test_camera.h" + +#undef GLM +#undef GLM_PREFIX + +/* test pre-compiled */ +/*---------------------------------------------------------------------------*/ + +#define GLM_PREFIX glmc_ +#define GLM(X) (glmc_ ## X) + +#include "test_vec2.h" +#include "test_vec3.h" +#include "test_vec4.h" +#include "test_ivec2.h" +#include "test_ivec3.h" +#include "test_ivec4.h" +#include "test_mat2.h" +#include "test_mat3.h" +#include "test_mat4.h" +#include "test_quat.h" +#include "test_project.h" +#include "test_plane.h" +#include "test_affine.h" +#include "test_affine2d.h" +#include "test_affine_mat.h" +#include "test_ray.h" +#include "test_camera.h" + +#undef GLM +#undef GLM_PREFIX + +/*---------------------------------------------------------------------------*/ diff --git a/libs/cglm/test/tests.h b/libs/cglm/test/tests.h new file mode 100644 index 0000000..361b485 --- /dev/null +++ b/libs/cglm/test/tests.h @@ -0,0 +1,1672 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef tests_h +#define tests_h + +#include "include/common.h" + +/* + * To register a test: + * 1. use TEST_DECLARE() to forward declare test + * 2. use TEST_ENTRY() to add test to list + */ + +/* affine mat */ +TEST_DECLARE(glm_mul) +TEST_DECLARE(glm_mul) +TEST_DECLARE(glm_inv_tr) + +TEST_DECLARE(glmc_mul) +TEST_DECLARE(glmc_mul_rot) +TEST_DECLARE(glmc_inv_tr) + +/* affine */ +TEST_DECLARE(glm_translate) +TEST_DECLARE(glm_translate_to) +TEST_DECLARE(glm_translate_x) +TEST_DECLARE(glm_translate_y) +TEST_DECLARE(glm_translate_z) +TEST_DECLARE(glm_translate_make) +TEST_DECLARE(glm_scale_to) +TEST_DECLARE(glm_scale_make) +TEST_DECLARE(glm_scale) +TEST_DECLARE(glm_scale_uni) +TEST_DECLARE(glm_rotate_x) +TEST_DECLARE(glm_rotate_y) +TEST_DECLARE(glm_rotate_z) +TEST_DECLARE(glm_rotate_make) +TEST_DECLARE(glm_rotate) +TEST_DECLARE(glm_rotate_at) +TEST_DECLARE(glm_rotate_atm) +TEST_DECLARE(glm_decompose_scalev) +TEST_DECLARE(glm_uniscaled) +TEST_DECLARE(glm_decompose_rs) +TEST_DECLARE(glm_decompose) + +TEST_DECLARE(glmc_translate) +TEST_DECLARE(glmc_translate_to) +TEST_DECLARE(glmc_translate_x) +TEST_DECLARE(glmc_translate_y) +TEST_DECLARE(glmc_translate_z) +TEST_DECLARE(glmc_translate_make) +TEST_DECLARE(glmc_scale_to) +TEST_DECLARE(glmc_scale_make) +TEST_DECLARE(glmc_scale) +TEST_DECLARE(glmc_scale_uni) +TEST_DECLARE(glmc_rotate_x) +TEST_DECLARE(glmc_rotate_y) +TEST_DECLARE(glmc_rotate_z) +TEST_DECLARE(glmc_rotate_make) +TEST_DECLARE(glmc_rotate) +TEST_DECLARE(glmc_rotate_at) +TEST_DECLARE(glmc_rotate_atm) +TEST_DECLARE(glmc_decompose_scalev) +TEST_DECLARE(glmc_uniscaled) +TEST_DECLARE(glmc_decompose_rs) +TEST_DECLARE(glmc_decompose) + +/* affine 2d */ +TEST_DECLARE(glm_translate2d) +TEST_DECLARE(glm_translate2d_to) +TEST_DECLARE(glm_translate2d_x) +TEST_DECLARE(glm_translate2d_y) +TEST_DECLARE(glm_translate2d_make) +TEST_DECLARE(glm_scale2d_to) +TEST_DECLARE(glm_scale2d_make) +TEST_DECLARE(glm_scale2d) +TEST_DECLARE(glm_scale2d_uni) +TEST_DECLARE(glm_rotate2d_make) +TEST_DECLARE(glm_rotate2d) +TEST_DECLARE(glm_rotate2d_to) + +TEST_DECLARE(glmc_translate2d) +TEST_DECLARE(glmc_translate2d_to) +TEST_DECLARE(glmc_translate2d_x) +TEST_DECLARE(glmc_translate2d_y) +TEST_DECLARE(glmc_translate2d_make) +TEST_DECLARE(glmc_scale2d_to) +TEST_DECLARE(glmc_scale2d_make) +TEST_DECLARE(glmc_scale2d) +TEST_DECLARE(glmc_scale2d_uni) +TEST_DECLARE(glmc_rotate2d_make) +TEST_DECLARE(glmc_rotate2d) +TEST_DECLARE(glmc_rotate2d_to) + +/* mat4 */ +TEST_DECLARE(glm_mat4_ucopy) +TEST_DECLARE(glm_mat4_copy) +TEST_DECLARE(glm_mat4_identity) +TEST_DECLARE(glm_mat4_identity_array) +TEST_DECLARE(glm_mat4_zero) +TEST_DECLARE(glm_mat4_pick3) +TEST_DECLARE(glm_mat4_pick3t) +TEST_DECLARE(glm_mat4_ins3) +TEST_DECLARE(glm_mat4_mul) +TEST_DECLARE(glm_mat4_mulN) +TEST_DECLARE(glm_mat4_mulv) +TEST_DECLARE(glm_mat4_mulv3) +TEST_DECLARE(glm_mat4_trace) +TEST_DECLARE(glm_mat4_trace3) +TEST_DECLARE(glm_mat4_quat) +TEST_DECLARE(glm_mat4_transpose_to) +TEST_DECLARE(glm_mat4_transpose) +TEST_DECLARE(glm_mat4_scale_p) +TEST_DECLARE(glm_mat4_scale) +TEST_DECLARE(glm_mat4_det) +TEST_DECLARE(glm_mat4_inv) +TEST_DECLARE(glm_mat4_inv_fast) +TEST_DECLARE(glm_mat4_inv_precise) +TEST_DECLARE(glm_mat4_swap_col) +TEST_DECLARE(glm_mat4_swap_row) +TEST_DECLARE(glm_mat4_rmc) + +TEST_DECLARE(glmc_mat4_ucopy) +TEST_DECLARE(glmc_mat4_copy) +TEST_DECLARE(glmc_mat4_identity) +TEST_DECLARE(glmc_mat4_identity_array) +TEST_DECLARE(glmc_mat4_zero) +TEST_DECLARE(glmc_mat4_pick3) +TEST_DECLARE(glmc_mat4_pick3t) +TEST_DECLARE(glmc_mat4_ins3) +TEST_DECLARE(glmc_mat4_mul) +TEST_DECLARE(glmc_mat4_mulN) +TEST_DECLARE(glmc_mat4_mulv) +TEST_DECLARE(glmc_mat4_mulv3) +TEST_DECLARE(glmc_mat4_trace) +TEST_DECLARE(glmc_mat4_trace3) +TEST_DECLARE(glmc_mat4_quat) +TEST_DECLARE(glmc_mat4_transpose_to) +TEST_DECLARE(glmc_mat4_transpose) +TEST_DECLARE(glmc_mat4_scale_p) +TEST_DECLARE(glmc_mat4_scale) +TEST_DECLARE(glmc_mat4_det) +TEST_DECLARE(glmc_mat4_inv) +TEST_DECLARE(glmc_mat4_inv_fast) +TEST_DECLARE(glmc_mat4_swap_col) +TEST_DECLARE(glmc_mat4_swap_row) +TEST_DECLARE(glmc_mat4_rmc) + +/* mat3 */ +TEST_DECLARE(glm_mat3_copy) +TEST_DECLARE(glm_mat3_identity) +TEST_DECLARE(glm_mat3_identity_array) +TEST_DECLARE(glm_mat3_zero) +TEST_DECLARE(glm_mat3_mul) +TEST_DECLARE(glm_mat3_mulv) +TEST_DECLARE(glm_mat3_trace) +TEST_DECLARE(glm_mat3_quat) +TEST_DECLARE(glm_mat3_transpose_to) +TEST_DECLARE(glm_mat3_transpose) +TEST_DECLARE(glm_mat3_scale) +TEST_DECLARE(glm_mat3_det) +TEST_DECLARE(glm_mat3_inv) +TEST_DECLARE(glm_mat3_swap_col) +TEST_DECLARE(glm_mat3_swap_row) +TEST_DECLARE(glm_mat3_rmc) + +TEST_DECLARE(glmc_mat3_copy) +TEST_DECLARE(glmc_mat3_identity) +TEST_DECLARE(glmc_mat3_identity_array) +TEST_DECLARE(glmc_mat3_zero) +TEST_DECLARE(glmc_mat3_mul) +TEST_DECLARE(glmc_mat3_mulv) +TEST_DECLARE(glmc_mat3_trace) +TEST_DECLARE(glmc_mat3_quat) +TEST_DECLARE(glmc_mat3_transpose_to) +TEST_DECLARE(glmc_mat3_transpose) +TEST_DECLARE(glmc_mat3_scale) +TEST_DECLARE(glmc_mat3_det) +TEST_DECLARE(glmc_mat3_inv) +TEST_DECLARE(glmc_mat3_swap_col) +TEST_DECLARE(glmc_mat3_swap_row) +TEST_DECLARE(glmc_mat3_rmc) + +TEST_DECLARE(MACRO_GLM_MAT2_IDENTITY_INIT) +TEST_DECLARE(MACRO_GLM_MAT2_ZERO_INIT) +TEST_DECLARE(MACRO_GLM_MAT2_IDENTITY) +TEST_DECLARE(MACRO_GLM_MAT2_ZERO) +TEST_DECLARE(glm_mat2_copy) +TEST_DECLARE(glm_mat2_identity) +TEST_DECLARE(glm_mat2_identity_array) +TEST_DECLARE(glm_mat2_zero) +TEST_DECLARE(glm_mat2_mul) +TEST_DECLARE(glm_mat2_transpose_to) +TEST_DECLARE(glm_mat2_transpose) +TEST_DECLARE(glm_mat2_mulv) +TEST_DECLARE(glm_mat2_trace) +TEST_DECLARE(glm_mat2_scale) +TEST_DECLARE(glm_mat2_det) +TEST_DECLARE(glm_mat2_inv) +TEST_DECLARE(glm_mat2_swap_col) +TEST_DECLARE(glm_mat2_swap_row) +TEST_DECLARE(glm_mat2_rmc) + +TEST_DECLARE(glmc_mat2_copy) +TEST_DECLARE(glmc_mat2_identity) +TEST_DECLARE(glmc_mat2_identity_array) +TEST_DECLARE(glmc_mat2_zero) +TEST_DECLARE(glmc_mat2_mul) +TEST_DECLARE(glmc_mat2_transpose_to) +TEST_DECLARE(glmc_mat2_transpose) +TEST_DECLARE(glmc_mat2_mulv) +TEST_DECLARE(glmc_mat2_trace) +TEST_DECLARE(glmc_mat2_scale) +TEST_DECLARE(glmc_mat2_det) +TEST_DECLARE(glmc_mat2_inv) +TEST_DECLARE(glmc_mat2_swap_col) +TEST_DECLARE(glmc_mat2_swap_row) +TEST_DECLARE(glmc_mat2_rmc) + +/* camera (incl [LR]H cross [NZ]O) */ +TEST_DECLARE(perspective_lh_zo) +TEST_DECLARE(perspective_rh_zo) +TEST_DECLARE(perspective_lh_no) +TEST_DECLARE(perspective_rh_no) +TEST_DECLARE(camera_lookat) +TEST_DECLARE(camera_decomp) + +TEST_DECLARE(glm_frustum) + +TEST_DECLARE(glmc_frustum) + +/* project */ +TEST_DECLARE(glm_unprojecti) +TEST_DECLARE(glm_unproject) +TEST_DECLARE(glm_project) + +TEST_DECLARE(glmc_unprojecti) +TEST_DECLARE(glmc_unproject) +TEST_DECLARE(glmc_project) + +/* plane */ +TEST_DECLARE(glm_plane_normalize) +TEST_DECLARE(glmc_plane_normalize) + +/* utils */ +TEST_DECLARE(clamp) + +/* euler */ +TEST_DECLARE(euler) + +/* ray */ +TEST_DECLARE(glm_ray_triangle) +TEST_DECLARE(glmc_ray_triangle) + +/* quat */ +TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY_INIT) +TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY) + +TEST_DECLARE(glm_quat_identity) +TEST_DECLARE(glm_quat_identity_array) +TEST_DECLARE(glm_quat_init) +TEST_DECLARE(glm_quatv) +TEST_DECLARE(glm_quat) +TEST_DECLARE(glm_quat_copy) +TEST_DECLARE(glm_quat_norm) +TEST_DECLARE(glm_quat_normalize_to) +TEST_DECLARE(glm_quat_normalize) +TEST_DECLARE(glm_quat_dot) +TEST_DECLARE(glm_quat_conjugate) +TEST_DECLARE(glm_quat_inv) +TEST_DECLARE(glm_quat_add) +TEST_DECLARE(glm_quat_sub) +TEST_DECLARE(glm_quat_real) +TEST_DECLARE(glm_quat_imag) +TEST_DECLARE(glm_quat_imagn) +TEST_DECLARE(glm_quat_imaglen) +TEST_DECLARE(glm_quat_angle) +TEST_DECLARE(glm_quat_axis) +TEST_DECLARE(glm_quat_mul) +TEST_DECLARE(glm_quat_mat4) +TEST_DECLARE(glm_quat_mat4t) +TEST_DECLARE(glm_quat_mat3) +TEST_DECLARE(glm_quat_mat3t) +TEST_DECLARE(glm_quat_lerp) +TEST_DECLARE(glm_quat_lerpc) +TEST_DECLARE(glm_quat_nlerp) +TEST_DECLARE(glm_quat_slerp) +TEST_DECLARE(glm_quat_look) +TEST_DECLARE(glm_quat_for) +TEST_DECLARE(glm_quat_forp) +TEST_DECLARE(glm_quat_rotatev) +TEST_DECLARE(glm_quat_rotate) +TEST_DECLARE(glm_quat_rotate_at) +TEST_DECLARE(glm_quat_rotate_atm) +TEST_DECLARE(glm_quat_from_vecs) + +TEST_DECLARE(glmc_quat_identity) +TEST_DECLARE(glmc_quat_identity_array) +TEST_DECLARE(glmc_quat_init) +TEST_DECLARE(glmc_quatv) +TEST_DECLARE(glmc_quat) +TEST_DECLARE(glmc_quat_copy) +TEST_DECLARE(glmc_quat_norm) +TEST_DECLARE(glmc_quat_normalize_to) +TEST_DECLARE(glmc_quat_normalize) +TEST_DECLARE(glmc_quat_dot) +TEST_DECLARE(glmc_quat_conjugate) +TEST_DECLARE(glmc_quat_inv) +TEST_DECLARE(glmc_quat_add) +TEST_DECLARE(glmc_quat_sub) +TEST_DECLARE(glmc_quat_real) +TEST_DECLARE(glmc_quat_imag) +TEST_DECLARE(glmc_quat_imagn) +TEST_DECLARE(glmc_quat_imaglen) +TEST_DECLARE(glmc_quat_angle) +TEST_DECLARE(glmc_quat_axis) +TEST_DECLARE(glmc_quat_mul) +TEST_DECLARE(glmc_quat_mat4) +TEST_DECLARE(glmc_quat_mat4t) +TEST_DECLARE(glmc_quat_mat3) +TEST_DECLARE(glmc_quat_mat3t) +TEST_DECLARE(glmc_quat_lerp) +TEST_DECLARE(glmc_quat_lerpc) +TEST_DECLARE(glmc_quat_nlerp) +TEST_DECLARE(glmc_quat_slerp) +TEST_DECLARE(glmc_quat_look) +TEST_DECLARE(glmc_quat_for) +TEST_DECLARE(glmc_quat_forp) +TEST_DECLARE(glmc_quat_rotatev) +TEST_DECLARE(glmc_quat_rotate) +TEST_DECLARE(glmc_quat_rotate_at) +TEST_DECLARE(glmc_quat_rotate_atm) +TEST_DECLARE(glmc_quat_from_vecs) + +/* bezier */ +TEST_DECLARE(bezier) + +/* vec2 */ +TEST_DECLARE(MACRO_GLM_VEC2_ONE_INIT) +TEST_DECLARE(MACRO_GLM_VEC2_ZERO_INIT) +TEST_DECLARE(MACRO_GLM_VEC2_ONE) +TEST_DECLARE(MACRO_GLM_VEC2_ZERO) + +TEST_DECLARE(glm_vec2) +TEST_DECLARE(glm_vec2_copy) +TEST_DECLARE(glm_vec2_zero) +TEST_DECLARE(glm_vec2_one) +TEST_DECLARE(glm_vec2_dot) +TEST_DECLARE(glm_vec2_cross) +TEST_DECLARE(glm_vec2_norm2) +TEST_DECLARE(glm_vec2_norm) +TEST_DECLARE(glm_vec2_add) +TEST_DECLARE(glm_vec2_adds) +TEST_DECLARE(glm_vec2_sub) +TEST_DECLARE(glm_vec2_subs) +TEST_DECLARE(glm_vec2_mul) +TEST_DECLARE(glm_vec2_scale) +TEST_DECLARE(glm_vec2_scale_as) +TEST_DECLARE(glm_vec2_div) +TEST_DECLARE(glm_vec2_divs) +TEST_DECLARE(glm_vec2_addadd) +TEST_DECLARE(glm_vec2_subadd) +TEST_DECLARE(glm_vec2_muladd) +TEST_DECLARE(glm_vec2_muladds) +TEST_DECLARE(glm_vec2_maxadd) +TEST_DECLARE(glm_vec2_minadd) +TEST_DECLARE(glm_vec2_negate_to) +TEST_DECLARE(glm_vec2_negate) +TEST_DECLARE(glm_vec2_normalize) +TEST_DECLARE(glm_vec2_normalize_to) +TEST_DECLARE(glm_vec2_rotate) +TEST_DECLARE(glm_vec2_distance2) +TEST_DECLARE(glm_vec2_distance) +TEST_DECLARE(glm_vec2_maxv) +TEST_DECLARE(glm_vec2_minv) +TEST_DECLARE(glm_vec2_clamp) +TEST_DECLARE(glm_vec2_lerp) +TEST_DECLARE(glm_vec2_complex_mul) +TEST_DECLARE(glm_vec2_complex_div) + +TEST_DECLARE(glmc_vec2) +TEST_DECLARE(glmc_vec2_copy) +TEST_DECLARE(glmc_vec2_zero) +TEST_DECLARE(glmc_vec2_one) +TEST_DECLARE(glmc_vec2_dot) +TEST_DECLARE(glmc_vec2_cross) +TEST_DECLARE(glmc_vec2_norm2) +TEST_DECLARE(glmc_vec2_norm) +TEST_DECLARE(glmc_vec2_add) +TEST_DECLARE(glmc_vec2_adds) +TEST_DECLARE(glmc_vec2_sub) +TEST_DECLARE(glmc_vec2_subs) +TEST_DECLARE(glmc_vec2_mul) +TEST_DECLARE(glmc_vec2_scale) +TEST_DECLARE(glmc_vec2_scale_as) +TEST_DECLARE(glmc_vec2_div) +TEST_DECLARE(glmc_vec2_divs) +TEST_DECLARE(glmc_vec2_addadd) +TEST_DECLARE(glmc_vec2_subadd) +TEST_DECLARE(glmc_vec2_muladd) +TEST_DECLARE(glmc_vec2_muladds) +TEST_DECLARE(glmc_vec2_maxadd) +TEST_DECLARE(glmc_vec2_minadd) +TEST_DECLARE(glmc_vec2_negate_to) +TEST_DECLARE(glmc_vec2_negate) +TEST_DECLARE(glmc_vec2_normalize) +TEST_DECLARE(glmc_vec2_normalize_to) +TEST_DECLARE(glmc_vec2_rotate) +TEST_DECLARE(glmc_vec2_distance2) +TEST_DECLARE(glmc_vec2_distance) +TEST_DECLARE(glmc_vec2_maxv) +TEST_DECLARE(glmc_vec2_minv) +TEST_DECLARE(glmc_vec2_clamp) +TEST_DECLARE(glmc_vec2_lerp) +TEST_DECLARE(glmc_vec2_complex_mul) +TEST_DECLARE(glmc_vec2_complex_div) + +/* vec3 */ +TEST_DECLARE(MACRO_GLM_VEC3_ONE_INIT) +TEST_DECLARE(MACRO_GLM_VEC3_ZERO_INIT) +TEST_DECLARE(MACRO_GLM_VEC3_ONE) +TEST_DECLARE(MACRO_GLM_VEC3_ZERO) +TEST_DECLARE(MACRO_GLM_YUP) +TEST_DECLARE(MACRO_GLM_ZUP) +TEST_DECLARE(MACRO_GLM_XUP) +TEST_DECLARE(MACRO_GLM_FORWARD_RH) +TEST_DECLARE(MACRO_GLM_SHUFFLE3) +TEST_DECLARE(MACRO_GLM_XXX) +TEST_DECLARE(MACRO_GLM_YYY) +TEST_DECLARE(MACRO_GLM_ZZZ) +TEST_DECLARE(MACRO_GLM_ZYX) + +TEST_DECLARE(MACRO_glm_vec3_dup) +TEST_DECLARE(MACRO_glm_vec3_flipsign) +TEST_DECLARE(MACRO_glm_vec3_flipsign_to) +TEST_DECLARE(MACRO_glm_vec3_inv) +TEST_DECLARE(MACRO_glm_vec3_inv_to) +TEST_DECLARE(MACRO_glm_vec3_mulv) + +TEST_DECLARE(glm_vec3) +TEST_DECLARE(glm_vec3_copy) +TEST_DECLARE(glm_vec3_zero) +TEST_DECLARE(glm_vec3_one) +TEST_DECLARE(glm_vec3_dot) +TEST_DECLARE(glm_dot) +TEST_DECLARE(glm_vec3_norm2) +TEST_DECLARE(glm_vec3_norm) +TEST_DECLARE(glm_vec3_norm_one) +TEST_DECLARE(glm_vec3_norm_inf) +TEST_DECLARE(glm_vec3_add) +TEST_DECLARE(glm_vec3_adds) +TEST_DECLARE(glm_vec3_sub) +TEST_DECLARE(glm_vec3_subs) +TEST_DECLARE(glm_vec3_mul) +TEST_DECLARE(glm_vec3_scale) +TEST_DECLARE(glm_vec3_scale_as) +TEST_DECLARE(glm_vec3_div) +TEST_DECLARE(glm_vec3_divs) +TEST_DECLARE(glm_vec3_addadd) +TEST_DECLARE(glm_vec3_subadd) +TEST_DECLARE(glm_vec3_muladd) +TEST_DECLARE(glm_vec3_muladds) +TEST_DECLARE(glm_vec3_maxadd) +TEST_DECLARE(glm_vec3_minadd) +TEST_DECLARE(glm_vec3_negate_to) +TEST_DECLARE(glm_vec3_negate) +TEST_DECLARE(glm_vec3_normalize) +TEST_DECLARE(glm_vec3_normalize_to) +TEST_DECLARE(glm_normalize) +TEST_DECLARE(glm_normalize_to) +TEST_DECLARE(glm_vec3_cross) +TEST_DECLARE(glm_vec3_crossn) +TEST_DECLARE(glm_cross) +TEST_DECLARE(glm_vec3_angle) +TEST_DECLARE(glm_vec3_rotate) +TEST_DECLARE(glm_vec3_rotate_m4) +TEST_DECLARE(glm_vec3_rotate_m3) +TEST_DECLARE(glm_vec3_proj) +TEST_DECLARE(glm_vec3_center) +TEST_DECLARE(glm_vec3_distance2) +TEST_DECLARE(glm_vec3_distance) +TEST_DECLARE(glm_vec3_maxv) +TEST_DECLARE(glm_vec3_minv) +TEST_DECLARE(glm_vec3_ortho) +TEST_DECLARE(glm_vec3_clamp) +TEST_DECLARE(glm_vec3_mix) +TEST_DECLARE(glm_vec3_mixc) +TEST_DECLARE(glm_vec3_step_uni) +TEST_DECLARE(glm_vec3_step) +TEST_DECLARE(glm_vec3_smoothstep_uni) +TEST_DECLARE(glm_vec3_smoothstep) +TEST_DECLARE(glm_vec3_smoothinterp) +TEST_DECLARE(glm_vec3_smoothinterpc) +TEST_DECLARE(glm_vec3_swizzle) +TEST_DECLARE(glm_vec3_broadcast) +TEST_DECLARE(glm_vec3_fill) +TEST_DECLARE(glm_vec3_eq) +TEST_DECLARE(glm_vec3_eq_eps) +TEST_DECLARE(glm_vec3_eq_all) +TEST_DECLARE(glm_vec3_eqv) +TEST_DECLARE(glm_vec3_eqv_eps) +TEST_DECLARE(glm_vec3_max) +TEST_DECLARE(glm_vec3_min) +TEST_DECLARE(glm_vec3_isnan) +TEST_DECLARE(glm_vec3_isinf) +TEST_DECLARE(glm_vec3_isvalid) +TEST_DECLARE(glm_vec3_sign) +TEST_DECLARE(glm_vec3_abs) +TEST_DECLARE(glm_vec3_fract) +TEST_DECLARE(glm_vec3_hadd) +TEST_DECLARE(glm_vec3_sqrt) + +TEST_DECLARE(glmc_vec3) +TEST_DECLARE(glmc_vec3_copy) +TEST_DECLARE(glmc_vec3_zero) +TEST_DECLARE(glmc_vec3_one) +TEST_DECLARE(glmc_vec3_dot) +TEST_DECLARE(glmc_vec3_norm2) +TEST_DECLARE(glmc_vec3_norm) +TEST_DECLARE(glmc_vec3_norm_one) +TEST_DECLARE(glmc_vec3_norm_inf) +TEST_DECLARE(glmc_vec3_add) +TEST_DECLARE(glmc_vec3_adds) +TEST_DECLARE(glmc_vec3_sub) +TEST_DECLARE(glmc_vec3_subs) +TEST_DECLARE(glmc_vec3_mul) +TEST_DECLARE(glmc_vec3_scale) +TEST_DECLARE(glmc_vec3_scale_as) +TEST_DECLARE(glmc_vec3_div) +TEST_DECLARE(glmc_vec3_divs) +TEST_DECLARE(glmc_vec3_addadd) +TEST_DECLARE(glmc_vec3_subadd) +TEST_DECLARE(glmc_vec3_muladd) +TEST_DECLARE(glmc_vec3_muladds) +TEST_DECLARE(glmc_vec3_maxadd) +TEST_DECLARE(glmc_vec3_minadd) +TEST_DECLARE(glmc_vec3_negate_to) +TEST_DECLARE(glmc_vec3_negate) +TEST_DECLARE(glmc_vec3_normalize) +TEST_DECLARE(glmc_vec3_normalize_to) +TEST_DECLARE(glmc_vec3_cross) +TEST_DECLARE(glmc_vec3_crossn) +TEST_DECLARE(glmc_vec3_angle) +TEST_DECLARE(glmc_vec3_rotate) +TEST_DECLARE(glmc_vec3_rotate_m4) +TEST_DECLARE(glmc_vec3_rotate_m3) +TEST_DECLARE(glmc_vec3_proj) +TEST_DECLARE(glmc_vec3_center) +TEST_DECLARE(glmc_vec3_distance2) +TEST_DECLARE(glmc_vec3_distance) +TEST_DECLARE(glmc_vec3_maxv) +TEST_DECLARE(glmc_vec3_minv) +TEST_DECLARE(glmc_vec3_ortho) +TEST_DECLARE(glmc_vec3_clamp) +TEST_DECLARE(glmc_vec3_mix) +TEST_DECLARE(glmc_vec3_mixc) +TEST_DECLARE(glmc_vec3_step_uni) +TEST_DECLARE(glmc_vec3_step) +TEST_DECLARE(glmc_vec3_smoothstep_uni) +TEST_DECLARE(glmc_vec3_smoothstep) +TEST_DECLARE(glmc_vec3_smoothinterp) +TEST_DECLARE(glmc_vec3_smoothinterpc) +TEST_DECLARE(glmc_vec3_swizzle) +TEST_DECLARE(glmc_vec3_broadcast) +TEST_DECLARE(glmc_vec3_fill) +TEST_DECLARE(glmc_vec3_eq) +TEST_DECLARE(glmc_vec3_eq_eps) +TEST_DECLARE(glmc_vec3_eq_all) +TEST_DECLARE(glmc_vec3_eqv) +TEST_DECLARE(glmc_vec3_eqv_eps) +TEST_DECLARE(glmc_vec3_max) +TEST_DECLARE(glmc_vec3_min) +TEST_DECLARE(glmc_vec3_isnan) +TEST_DECLARE(glmc_vec3_isinf) +TEST_DECLARE(glmc_vec3_isvalid) +TEST_DECLARE(glmc_vec3_sign) +TEST_DECLARE(glmc_vec3_abs) +TEST_DECLARE(glmc_vec3_fract) +TEST_DECLARE(glmc_vec3_hadd) +TEST_DECLARE(glmc_vec3_sqrt) + +/* vec4 */ +TEST_DECLARE(MACRO_GLM_VEC4_ONE_INIT) +TEST_DECLARE(MACRO_GLM_VEC4_ZERO_INIT) +TEST_DECLARE(MACRO_GLM_VEC4_ONE) +TEST_DECLARE(MACRO_GLM_VEC4_ZERO) +TEST_DECLARE(MACRO_GLM_XXXX) +TEST_DECLARE(MACRO_GLM_YYYY) +TEST_DECLARE(MACRO_GLM_ZZZZ) +TEST_DECLARE(MACRO_GLM_WZYX) +TEST_DECLARE(MACRO_glm_vec4_dup) +TEST_DECLARE(MACRO_glm_vec4_flipsign) +TEST_DECLARE(MACRO_glm_vec4_flipsign_to) +TEST_DECLARE(MACRO_glm_vec4_inv) +TEST_DECLARE(MACRO_glm_vec4_inv_to) +TEST_DECLARE(MACRO_glm_vec4_mulv) + +TEST_DECLARE(glm_vec4) +TEST_DECLARE(glm_vec4_copy3) +TEST_DECLARE(glm_vec4_copy) +TEST_DECLARE(glm_vec4_ucopy) +TEST_DECLARE(glm_vec4_zero) +TEST_DECLARE(glm_vec4_one) +TEST_DECLARE(glm_vec4_dot) +TEST_DECLARE(glm_vec4_norm2) +TEST_DECLARE(glm_vec4_norm) +TEST_DECLARE(glm_vec4_norm_one) +TEST_DECLARE(glm_vec4_norm_inf) +TEST_DECLARE(glm_vec4_add) +TEST_DECLARE(glm_vec4_adds) +TEST_DECLARE(glm_vec4_sub) +TEST_DECLARE(glm_vec4_subs) +TEST_DECLARE(glm_vec4_mul) +TEST_DECLARE(glm_vec4_scale) +TEST_DECLARE(glm_vec4_scale_as) +TEST_DECLARE(glm_vec4_div) +TEST_DECLARE(glm_vec4_divs) +TEST_DECLARE(glm_vec4_addadd) +TEST_DECLARE(glm_vec4_subadd) +TEST_DECLARE(glm_vec4_muladd) +TEST_DECLARE(glm_vec4_muladds) +TEST_DECLARE(glm_vec4_maxadd) +TEST_DECLARE(glm_vec4_minadd) +TEST_DECLARE(glm_vec4_negate_to) +TEST_DECLARE(glm_vec4_negate) +TEST_DECLARE(glm_vec4_normalize) +TEST_DECLARE(glm_vec4_normalize_to) +TEST_DECLARE(glm_vec4_distance2) +TEST_DECLARE(glm_vec4_distance) +TEST_DECLARE(glm_vec4_maxv) +TEST_DECLARE(glm_vec4_minv) +TEST_DECLARE(glm_vec4_clamp) +TEST_DECLARE(glm_vec4_lerp) +TEST_DECLARE(glm_vec4_lerpc) +TEST_DECLARE(glm_vec4_mix) +TEST_DECLARE(glm_vec4_mixc) +TEST_DECLARE(glm_vec4_step_uni) +TEST_DECLARE(glm_vec4_step) +TEST_DECLARE(glm_vec4_smoothstep_uni) +TEST_DECLARE(glm_vec4_smoothstep) +TEST_DECLARE(glm_vec4_smoothinterp) +TEST_DECLARE(glm_vec4_smoothinterpc) +TEST_DECLARE(glm_vec4_cubic) +TEST_DECLARE(glm_vec4_swizzle) +TEST_DECLARE(glm_vec4_broadcast) +TEST_DECLARE(glm_vec4_fill) +TEST_DECLARE(glm_vec4_eq) +TEST_DECLARE(glm_vec4_eq_eps) +TEST_DECLARE(glm_vec4_eq_all) +TEST_DECLARE(glm_vec4_eqv) +TEST_DECLARE(glm_vec4_eqv_eps) +TEST_DECLARE(glm_vec4_max) +TEST_DECLARE(glm_vec4_min) +TEST_DECLARE(glm_vec4_isnan) +TEST_DECLARE(glm_vec4_isinf) +TEST_DECLARE(glm_vec4_isvalid) +TEST_DECLARE(glm_vec4_sign) +TEST_DECLARE(glm_vec4_abs) +TEST_DECLARE(glm_vec4_fract) +TEST_DECLARE(glm_vec4_hadd) +TEST_DECLARE(glm_vec4_sqrt) + +TEST_DECLARE(glmc_vec4) +TEST_DECLARE(glmc_vec4_copy3) +TEST_DECLARE(glmc_vec4_copy) +TEST_DECLARE(glmc_vec4_ucopy) +TEST_DECLARE(glmc_vec4_zero) +TEST_DECLARE(glmc_vec4_one) +TEST_DECLARE(glmc_vec4_dot) +TEST_DECLARE(glmc_vec4_norm2) +TEST_DECLARE(glmc_vec4_norm) +TEST_DECLARE(glmc_vec4_norm_one) +TEST_DECLARE(glmc_vec4_norm_inf) +TEST_DECLARE(glmc_vec4_add) +TEST_DECLARE(glmc_vec4_adds) +TEST_DECLARE(glmc_vec4_sub) +TEST_DECLARE(glmc_vec4_subs) +TEST_DECLARE(glmc_vec4_mul) +TEST_DECLARE(glmc_vec4_scale) +TEST_DECLARE(glmc_vec4_scale_as) +TEST_DECLARE(glmc_vec4_div) +TEST_DECLARE(glmc_vec4_divs) +TEST_DECLARE(glmc_vec4_addadd) +TEST_DECLARE(glmc_vec4_subadd) +TEST_DECLARE(glmc_vec4_muladd) +TEST_DECLARE(glmc_vec4_muladds) +TEST_DECLARE(glmc_vec4_maxadd) +TEST_DECLARE(glmc_vec4_minadd) +TEST_DECLARE(glmc_vec4_negate_to) +TEST_DECLARE(glmc_vec4_negate) +TEST_DECLARE(glmc_vec4_normalize) +TEST_DECLARE(glmc_vec4_normalize_to) +TEST_DECLARE(glmc_vec4_distance2) +TEST_DECLARE(glmc_vec4_distance) +TEST_DECLARE(glmc_vec4_maxv) +TEST_DECLARE(glmc_vec4_minv) +TEST_DECLARE(glmc_vec4_clamp) +TEST_DECLARE(glmc_vec4_lerp) +TEST_DECLARE(glmc_vec4_lerpc) +TEST_DECLARE(glmc_vec4_mix) +TEST_DECLARE(glmc_vec4_mixc) +TEST_DECLARE(glmc_vec4_step_uni) +TEST_DECLARE(glmc_vec4_step) +TEST_DECLARE(glmc_vec4_smoothstep_uni) +TEST_DECLARE(glmc_vec4_smoothstep) +TEST_DECLARE(glmc_vec4_smoothinterp) +TEST_DECLARE(glmc_vec4_smoothinterpc) +TEST_DECLARE(glmc_vec4_cubic) +TEST_DECLARE(glmc_vec4_swizzle) +TEST_DECLARE(glmc_vec4_broadcast) +TEST_DECLARE(glmc_vec4_fill) +TEST_DECLARE(glmc_vec4_eq) +TEST_DECLARE(glmc_vec4_eq_eps) +TEST_DECLARE(glmc_vec4_eq_all) +TEST_DECLARE(glmc_vec4_eqv) +TEST_DECLARE(glmc_vec4_eqv_eps) +TEST_DECLARE(glmc_vec4_max) +TEST_DECLARE(glmc_vec4_min) +TEST_DECLARE(glmc_vec4_isnan) +TEST_DECLARE(glmc_vec4_isinf) +TEST_DECLARE(glmc_vec4_isvalid) +TEST_DECLARE(glmc_vec4_sign) +TEST_DECLARE(glmc_vec4_abs) +TEST_DECLARE(glmc_vec4_fract) +TEST_DECLARE(glmc_vec4_hadd) +TEST_DECLARE(glmc_vec4_sqrt) + +/* ivec2 */ +TEST_DECLARE(glm_ivec2) +TEST_DECLARE(glm_ivec2_copy) +TEST_DECLARE(glm_ivec2_zero) +TEST_DECLARE(glm_ivec2_one) +TEST_DECLARE(glm_ivec2_add) +TEST_DECLARE(glm_ivec2_adds) +TEST_DECLARE(glm_ivec2_sub) +TEST_DECLARE(glm_ivec2_subs) +TEST_DECLARE(glm_ivec2_mul) +TEST_DECLARE(glm_ivec2_scale) +TEST_DECLARE(glm_ivec2_distance2) +TEST_DECLARE(glm_ivec2_distance) +TEST_DECLARE(glm_ivec2_maxv) +TEST_DECLARE(glm_ivec2_minv) +TEST_DECLARE(glm_ivec2_clamp) + +TEST_DECLARE(glmc_ivec2) +TEST_DECLARE(glmc_ivec2_copy) +TEST_DECLARE(glmc_ivec2_zero) +TEST_DECLARE(glmc_ivec2_one) +TEST_DECLARE(glmc_ivec2_add) +TEST_DECLARE(glmc_ivec2_adds) +TEST_DECLARE(glmc_ivec2_sub) +TEST_DECLARE(glmc_ivec2_subs) +TEST_DECLARE(glmc_ivec2_mul) +TEST_DECLARE(glmc_ivec2_scale) +TEST_DECLARE(glmc_ivec2_distance2) +TEST_DECLARE(glmc_ivec2_distance) +TEST_DECLARE(glmc_ivec2_maxv) +TEST_DECLARE(glmc_ivec2_minv) +TEST_DECLARE(glmc_ivec2_clamp) + +/* ivec3 */ +TEST_DECLARE(glm_ivec3) +TEST_DECLARE(glm_ivec3_copy) +TEST_DECLARE(glm_ivec3_zero) +TEST_DECLARE(glm_ivec3_one) +TEST_DECLARE(glm_ivec3_add) +TEST_DECLARE(glm_ivec3_adds) +TEST_DECLARE(glm_ivec3_sub) +TEST_DECLARE(glm_ivec3_subs) +TEST_DECLARE(glm_ivec3_mul) +TEST_DECLARE(glm_ivec3_scale) +TEST_DECLARE(glm_ivec3_distance2) +TEST_DECLARE(glm_ivec3_distance) +TEST_DECLARE(glm_ivec3_maxv) +TEST_DECLARE(glm_ivec3_minv) +TEST_DECLARE(glm_ivec3_clamp) + +TEST_DECLARE(glmc_ivec3) +TEST_DECLARE(glmc_ivec3_copy) +TEST_DECLARE(glmc_ivec3_zero) +TEST_DECLARE(glmc_ivec3_one) +TEST_DECLARE(glmc_ivec3_add) +TEST_DECLARE(glmc_ivec3_adds) +TEST_DECLARE(glmc_ivec3_sub) +TEST_DECLARE(glmc_ivec3_subs) +TEST_DECLARE(glmc_ivec3_mul) +TEST_DECLARE(glmc_ivec3_scale) +TEST_DECLARE(glmc_ivec3_distance2) +TEST_DECLARE(glmc_ivec3_distance) +TEST_DECLARE(glmc_ivec3_maxv) +TEST_DECLARE(glmc_ivec3_minv) +TEST_DECLARE(glmc_ivec3_clamp) + +/* ivec4 */ +TEST_DECLARE(glm_ivec4) +TEST_DECLARE(glm_ivec4_copy) +TEST_DECLARE(glm_ivec4_zero) +TEST_DECLARE(glm_ivec4_one) +TEST_DECLARE(glm_ivec4_add) +TEST_DECLARE(glm_ivec4_adds) +TEST_DECLARE(glm_ivec4_sub) +TEST_DECLARE(glm_ivec4_subs) +TEST_DECLARE(glm_ivec4_mul) +TEST_DECLARE(glm_ivec4_scale) +TEST_DECLARE(glm_ivec4_distance2) +TEST_DECLARE(glm_ivec4_distance) +TEST_DECLARE(glm_ivec4_maxv) +TEST_DECLARE(glm_ivec4_minv) +TEST_DECLARE(glm_ivec4_clamp) + +TEST_DECLARE(glmc_ivec4) +TEST_DECLARE(glmc_ivec4_copy) +TEST_DECLARE(glmc_ivec4_zero) +TEST_DECLARE(glmc_ivec4_one) +TEST_DECLARE(glmc_ivec4_add) +TEST_DECLARE(glmc_ivec4_adds) +TEST_DECLARE(glmc_ivec4_sub) +TEST_DECLARE(glmc_ivec4_subs) +TEST_DECLARE(glmc_ivec4_mul) +TEST_DECLARE(glmc_ivec4_scale) +TEST_DECLARE(glmc_ivec4_distance2) +TEST_DECLARE(glmc_ivec4_distance) +TEST_DECLARE(glmc_ivec4_maxv) +TEST_DECLARE(glmc_ivec4_minv) +TEST_DECLARE(glmc_ivec4_clamp) + +/* structs */ +TEST_DECLARE(mat3s_identity_init) +TEST_DECLARE(mat3s_zero_init) +TEST_DECLARE(mat4s_identity_init) +TEST_DECLARE(mat4s_zero_init) +TEST_DECLARE(quats_zero_init) +TEST_DECLARE(vec3s_one_init) +TEST_DECLARE(vec3s_zero_init) +TEST_DECLARE(vec4s_black_init) +TEST_DECLARE(vec4s_one_init) +TEST_DECLARE(vec4s_zero_init) + +/*****************************************************************************/ + +TEST_LIST { + /* affine mat */ + TEST_ENTRY(glm_mul) + TEST_ENTRY(glm_mul) + TEST_ENTRY(glm_inv_tr) + + TEST_ENTRY(glmc_mul) + TEST_ENTRY(glmc_mul_rot) + TEST_ENTRY(glmc_inv_tr) + + /* affine */ + TEST_ENTRY(glm_translate) + TEST_ENTRY(glm_translate_to) + TEST_ENTRY(glm_translate_x) + TEST_ENTRY(glm_translate_y) + TEST_ENTRY(glm_translate_z) + TEST_ENTRY(glm_translate_make) + TEST_ENTRY(glm_scale_to) + TEST_ENTRY(glm_scale_make) + TEST_ENTRY(glm_scale) + TEST_ENTRY(glm_scale_uni) + TEST_ENTRY(glm_rotate_x) + TEST_ENTRY(glm_rotate_y) + TEST_ENTRY(glm_rotate_z) + TEST_ENTRY(glm_rotate_make) + TEST_ENTRY(glm_rotate) + TEST_ENTRY(glm_rotate_at) + TEST_ENTRY(glm_rotate_atm) + TEST_ENTRY(glm_decompose_scalev) + TEST_ENTRY(glm_uniscaled) + TEST_ENTRY(glm_decompose_rs) + TEST_ENTRY(glm_decompose) + + TEST_ENTRY(glmc_translate) + TEST_ENTRY(glmc_translate_to) + TEST_ENTRY(glmc_translate_x) + TEST_ENTRY(glmc_translate_y) + TEST_ENTRY(glmc_translate_z) + TEST_ENTRY(glmc_translate_make) + TEST_ENTRY(glmc_scale_to) + TEST_ENTRY(glmc_scale_make) + TEST_ENTRY(glmc_scale) + TEST_ENTRY(glmc_scale_uni) + TEST_ENTRY(glmc_rotate_x) + TEST_ENTRY(glmc_rotate_y) + TEST_ENTRY(glmc_rotate_z) + TEST_ENTRY(glmc_rotate_make) + TEST_ENTRY(glmc_rotate) + TEST_ENTRY(glmc_rotate_at) + TEST_ENTRY(glmc_rotate_atm) + TEST_ENTRY(glmc_decompose_scalev) + TEST_ENTRY(glmc_uniscaled) + TEST_ENTRY(glmc_decompose_rs) + TEST_ENTRY(glmc_decompose) + + /* affine 2d */ + TEST_ENTRY(glm_translate2d) + TEST_ENTRY(glm_translate2d_to) + TEST_ENTRY(glm_translate2d_x) + TEST_ENTRY(glm_translate2d_y) + TEST_ENTRY(glm_translate2d_make) + TEST_ENTRY(glm_scale2d_to) + TEST_ENTRY(glm_scale2d_make) + TEST_ENTRY(glm_scale2d) + TEST_ENTRY(glm_scale2d_uni) + TEST_ENTRY(glm_rotate2d_make) + TEST_ENTRY(glm_rotate2d) + TEST_ENTRY(glm_rotate2d_to) + + TEST_ENTRY(glmc_translate2d) + TEST_ENTRY(glmc_translate2d_to) + TEST_ENTRY(glmc_translate2d_x) + TEST_ENTRY(glmc_translate2d_y) + TEST_ENTRY(glmc_translate2d_make) + TEST_ENTRY(glmc_scale2d_to) + TEST_ENTRY(glmc_scale2d_make) + TEST_ENTRY(glmc_scale2d) + TEST_ENTRY(glmc_scale2d_uni) + TEST_ENTRY(glmc_rotate2d_make) + TEST_ENTRY(glmc_rotate2d) + TEST_ENTRY(glmc_rotate2d_to) + + /* mat4 */ + TEST_ENTRY(glm_mat4_ucopy) + TEST_ENTRY(glm_mat4_copy) + TEST_ENTRY(glm_mat4_identity) + TEST_ENTRY(glm_mat4_identity_array) + TEST_ENTRY(glm_mat4_zero) + TEST_ENTRY(glm_mat4_pick3) + TEST_ENTRY(glm_mat4_pick3t) + TEST_ENTRY(glm_mat4_ins3) + TEST_ENTRY(glm_mat4_mul) + TEST_ENTRY(glm_mat4_mulN) + TEST_ENTRY(glm_mat4_mulv) + TEST_ENTRY(glm_mat4_mulv3) + TEST_ENTRY(glm_mat4_trace) + TEST_ENTRY(glm_mat4_trace3) + TEST_ENTRY(glm_mat4_quat) + TEST_ENTRY(glm_mat4_transpose_to) + TEST_ENTRY(glm_mat4_transpose) + TEST_ENTRY(glm_mat4_scale_p) + TEST_ENTRY(glm_mat4_scale) + TEST_ENTRY(glm_mat4_det) + TEST_ENTRY(glm_mat4_inv) + TEST_ENTRY(glm_mat4_inv_fast) + TEST_ENTRY(glm_mat4_inv_precise) + TEST_ENTRY(glm_mat4_swap_col) + TEST_ENTRY(glm_mat4_swap_row) + TEST_ENTRY(glm_mat4_rmc) + + TEST_ENTRY(glmc_mat4_ucopy) + TEST_ENTRY(glmc_mat4_copy) + TEST_ENTRY(glmc_mat4_identity) + TEST_ENTRY(glmc_mat4_identity_array) + TEST_ENTRY(glmc_mat4_zero) + TEST_ENTRY(glmc_mat4_pick3) + TEST_ENTRY(glmc_mat4_pick3t) + TEST_ENTRY(glmc_mat4_ins3) + TEST_ENTRY(glmc_mat4_mul) + TEST_ENTRY(glmc_mat4_mulN) + TEST_ENTRY(glmc_mat4_mulv) + TEST_ENTRY(glmc_mat4_mulv3) + TEST_ENTRY(glmc_mat4_trace) + TEST_ENTRY(glmc_mat4_trace3) + TEST_ENTRY(glmc_mat4_quat) + TEST_ENTRY(glmc_mat4_transpose_to) + TEST_ENTRY(glmc_mat4_transpose) + TEST_ENTRY(glmc_mat4_scale_p) + TEST_ENTRY(glmc_mat4_scale) + TEST_ENTRY(glmc_mat4_det) + TEST_ENTRY(glmc_mat4_inv) + TEST_ENTRY(glmc_mat4_inv_fast) + TEST_ENTRY(glmc_mat4_swap_col) + TEST_ENTRY(glmc_mat4_swap_row) + TEST_ENTRY(glmc_mat4_rmc) + + /* mat3 */ + TEST_ENTRY(glm_mat3_copy) + TEST_ENTRY(glm_mat3_identity) + TEST_ENTRY(glm_mat3_identity_array) + TEST_ENTRY(glm_mat3_zero) + TEST_ENTRY(glm_mat3_mul) + TEST_ENTRY(glm_mat3_mulv) + TEST_ENTRY(glm_mat3_trace) + TEST_ENTRY(glm_mat3_quat) + TEST_ENTRY(glm_mat3_transpose_to) + TEST_ENTRY(glm_mat3_transpose) + TEST_ENTRY(glm_mat3_scale) + TEST_ENTRY(glm_mat3_det) + TEST_ENTRY(glm_mat3_inv) + TEST_ENTRY(glm_mat3_swap_col) + TEST_ENTRY(glm_mat3_swap_row) + TEST_ENTRY(glm_mat3_rmc) + + TEST_ENTRY(glmc_mat3_copy) + TEST_ENTRY(glmc_mat3_identity) + TEST_ENTRY(glmc_mat3_identity_array) + TEST_ENTRY(glmc_mat3_zero) + TEST_ENTRY(glmc_mat3_mul) + TEST_ENTRY(glmc_mat3_mulv) + TEST_ENTRY(glmc_mat3_trace) + TEST_ENTRY(glmc_mat3_quat) + TEST_ENTRY(glmc_mat3_transpose_to) + TEST_ENTRY(glmc_mat3_transpose) + TEST_ENTRY(glmc_mat3_scale) + TEST_ENTRY(glmc_mat3_det) + TEST_ENTRY(glmc_mat3_inv) + TEST_ENTRY(glmc_mat3_swap_col) + TEST_ENTRY(glmc_mat3_swap_row) + TEST_ENTRY(glmc_mat3_rmc) + + TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY_INIT) + TEST_ENTRY(MACRO_GLM_MAT2_ZERO_INIT) + TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY) + TEST_ENTRY(MACRO_GLM_MAT2_ZERO) + TEST_ENTRY(glm_mat2_copy) + TEST_ENTRY(glm_mat2_identity) + TEST_ENTRY(glm_mat2_identity_array) + TEST_ENTRY(glm_mat2_zero) + TEST_ENTRY(glm_mat2_mul) + TEST_ENTRY(glm_mat2_transpose_to) + TEST_ENTRY(glm_mat2_transpose) + TEST_ENTRY(glm_mat2_mulv) + TEST_ENTRY(glm_mat2_trace) + TEST_ENTRY(glm_mat2_scale) + TEST_ENTRY(glm_mat2_det) + TEST_ENTRY(glm_mat2_inv) + TEST_ENTRY(glm_mat2_swap_col) + TEST_ENTRY(glm_mat2_swap_row) + TEST_ENTRY(glm_mat2_rmc) + + TEST_ENTRY(glmc_mat2_copy) + TEST_ENTRY(glmc_mat2_identity) + TEST_ENTRY(glmc_mat2_identity_array) + TEST_ENTRY(glmc_mat2_zero) + TEST_ENTRY(glmc_mat2_mul) + TEST_ENTRY(glmc_mat2_transpose_to) + TEST_ENTRY(glmc_mat2_transpose) + TEST_ENTRY(glmc_mat2_mulv) + TEST_ENTRY(glmc_mat2_trace) + TEST_ENTRY(glmc_mat2_scale) + TEST_ENTRY(glmc_mat2_det) + TEST_ENTRY(glmc_mat2_inv) + TEST_ENTRY(glmc_mat2_swap_col) + TEST_ENTRY(glmc_mat2_swap_row) + TEST_ENTRY(glmc_mat2_rmc) + + /* camera (incl [LR]H cross [NZ]O) */ + TEST_ENTRY(perspective_lh_zo) + TEST_ENTRY(perspective_rh_zo) + TEST_ENTRY(perspective_lh_no) + TEST_ENTRY(perspective_rh_no) + TEST_ENTRY(camera_lookat) + TEST_ENTRY(camera_decomp) + + TEST_ENTRY(glm_frustum) + + TEST_ENTRY(glmc_frustum) + + /* project */ + TEST_ENTRY(glm_unprojecti) + TEST_ENTRY(glm_unproject) + TEST_ENTRY(glm_project) + + TEST_ENTRY(glmc_unprojecti) + TEST_ENTRY(glmc_unproject) + TEST_ENTRY(glmc_project) + + /* plane */ + TEST_ENTRY(glm_plane_normalize) + TEST_ENTRY(glmc_plane_normalize) + + /* utils */ + TEST_ENTRY(clamp) + + /* euler */ + TEST_ENTRY(euler) + + /* ray */ + TEST_ENTRY(glm_ray_triangle) + TEST_ENTRY(glmc_ray_triangle) + + /* quat */ + TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY_INIT) + TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY) + + TEST_ENTRY(glm_quat_identity) + TEST_ENTRY(glm_quat_identity_array) + TEST_ENTRY(glm_quat_init) + TEST_ENTRY(glm_quatv) + TEST_ENTRY(glm_quat) + TEST_ENTRY(glm_quat_copy) + TEST_ENTRY(glm_quat_norm) + TEST_ENTRY(glm_quat_normalize_to) + TEST_ENTRY(glm_quat_normalize) + TEST_ENTRY(glm_quat_dot) + TEST_ENTRY(glm_quat_conjugate) + TEST_ENTRY(glm_quat_inv) + TEST_ENTRY(glm_quat_add) + TEST_ENTRY(glm_quat_sub) + TEST_ENTRY(glm_quat_real) + TEST_ENTRY(glm_quat_imag) + TEST_ENTRY(glm_quat_imagn) + TEST_ENTRY(glm_quat_imaglen) + TEST_ENTRY(glm_quat_angle) + TEST_ENTRY(glm_quat_axis) + TEST_ENTRY(glm_quat_mul) + TEST_ENTRY(glm_quat_mat4) + TEST_ENTRY(glm_quat_mat4t) + TEST_ENTRY(glm_quat_mat3) + TEST_ENTRY(glm_quat_mat3t) + TEST_ENTRY(glm_quat_lerp) + TEST_ENTRY(glm_quat_lerpc) + TEST_ENTRY(glm_quat_nlerp) + TEST_ENTRY(glm_quat_slerp) + TEST_ENTRY(glm_quat_look) + TEST_ENTRY(glm_quat_for) + TEST_ENTRY(glm_quat_forp) + TEST_ENTRY(glm_quat_rotatev) + TEST_ENTRY(glm_quat_rotate) + TEST_ENTRY(glm_quat_rotate_at) + TEST_ENTRY(glm_quat_rotate_atm) + TEST_ENTRY(glm_quat_from_vecs) + + TEST_ENTRY(glmc_quat_identity) + TEST_ENTRY(glmc_quat_identity_array) + TEST_ENTRY(glmc_quat_init) + TEST_ENTRY(glmc_quatv) + TEST_ENTRY(glmc_quat) + TEST_ENTRY(glmc_quat_copy) + TEST_ENTRY(glmc_quat_norm) + TEST_ENTRY(glmc_quat_normalize_to) + TEST_ENTRY(glmc_quat_normalize) + TEST_ENTRY(glmc_quat_dot) + TEST_ENTRY(glmc_quat_conjugate) + TEST_ENTRY(glmc_quat_inv) + TEST_ENTRY(glmc_quat_add) + TEST_ENTRY(glmc_quat_sub) + TEST_ENTRY(glmc_quat_real) + TEST_ENTRY(glmc_quat_imag) + TEST_ENTRY(glmc_quat_imagn) + TEST_ENTRY(glmc_quat_imaglen) + TEST_ENTRY(glmc_quat_angle) + TEST_ENTRY(glmc_quat_axis) + TEST_ENTRY(glmc_quat_mul) + TEST_ENTRY(glmc_quat_mat4) + TEST_ENTRY(glmc_quat_mat4t) + TEST_ENTRY(glmc_quat_mat3) + TEST_ENTRY(glmc_quat_mat3t) + TEST_ENTRY(glmc_quat_lerp) + TEST_ENTRY(glmc_quat_lerpc) + TEST_ENTRY(glmc_quat_nlerp) + TEST_ENTRY(glmc_quat_slerp) + TEST_ENTRY(glmc_quat_look) + TEST_ENTRY(glmc_quat_for) + TEST_ENTRY(glmc_quat_forp) + TEST_ENTRY(glmc_quat_rotatev) + TEST_ENTRY(glmc_quat_rotate) + TEST_ENTRY(glmc_quat_rotate_at) + TEST_ENTRY(glmc_quat_rotate_atm) + TEST_ENTRY(glmc_quat_from_vecs) + + /* bezier */ + TEST_ENTRY(bezier) + + /* vec2 */ + TEST_ENTRY(MACRO_GLM_VEC2_ONE_INIT) + TEST_ENTRY(MACRO_GLM_VEC2_ZERO_INIT) + TEST_ENTRY(MACRO_GLM_VEC2_ONE) + TEST_ENTRY(MACRO_GLM_VEC2_ZERO) + + TEST_ENTRY(glm_vec2) + TEST_ENTRY(glm_vec2_copy) + TEST_ENTRY(glm_vec2_zero) + TEST_ENTRY(glm_vec2_one) + TEST_ENTRY(glm_vec2_dot) + TEST_ENTRY(glm_vec2_cross) + TEST_ENTRY(glm_vec2_norm2) + TEST_ENTRY(glm_vec2_norm) + TEST_ENTRY(glm_vec2_add) + TEST_ENTRY(glm_vec2_adds) + TEST_ENTRY(glm_vec2_sub) + TEST_ENTRY(glm_vec2_subs) + TEST_ENTRY(glm_vec2_mul) + TEST_ENTRY(glm_vec2_scale) + TEST_ENTRY(glm_vec2_scale_as) + TEST_ENTRY(glm_vec2_div) + TEST_ENTRY(glm_vec2_divs) + TEST_ENTRY(glm_vec2_addadd) + TEST_ENTRY(glm_vec2_subadd) + TEST_ENTRY(glm_vec2_muladd) + TEST_ENTRY(glm_vec2_muladds) + TEST_ENTRY(glm_vec2_maxadd) + TEST_ENTRY(glm_vec2_minadd) + TEST_ENTRY(glm_vec2_negate_to) + TEST_ENTRY(glm_vec2_negate) + TEST_ENTRY(glm_vec2_normalize) + TEST_ENTRY(glm_vec2_normalize_to) + TEST_ENTRY(glm_vec2_rotate) + TEST_ENTRY(glm_vec2_distance2) + TEST_ENTRY(glm_vec2_distance) + TEST_ENTRY(glm_vec2_maxv) + TEST_ENTRY(glm_vec2_minv) + TEST_ENTRY(glm_vec2_clamp) + TEST_ENTRY(glm_vec2_lerp) + TEST_ENTRY(glm_vec2_complex_mul) + TEST_ENTRY(glm_vec2_complex_div) + + TEST_ENTRY(glmc_vec2) + TEST_ENTRY(glmc_vec2_copy) + TEST_ENTRY(glmc_vec2_zero) + TEST_ENTRY(glmc_vec2_one) + TEST_ENTRY(glmc_vec2_dot) + TEST_ENTRY(glmc_vec2_cross) + TEST_ENTRY(glmc_vec2_norm2) + TEST_ENTRY(glmc_vec2_norm) + TEST_ENTRY(glmc_vec2_add) + TEST_ENTRY(glmc_vec2_adds) + TEST_ENTRY(glmc_vec2_sub) + TEST_ENTRY(glmc_vec2_subs) + TEST_ENTRY(glmc_vec2_mul) + TEST_ENTRY(glmc_vec2_scale) + TEST_ENTRY(glmc_vec2_scale_as) + TEST_ENTRY(glmc_vec2_div) + TEST_ENTRY(glmc_vec2_divs) + TEST_ENTRY(glmc_vec2_addadd) + TEST_ENTRY(glmc_vec2_subadd) + TEST_ENTRY(glmc_vec2_muladd) + TEST_ENTRY(glmc_vec2_muladds) + TEST_ENTRY(glmc_vec2_maxadd) + TEST_ENTRY(glmc_vec2_minadd) + TEST_ENTRY(glmc_vec2_negate_to) + TEST_ENTRY(glmc_vec2_negate) + TEST_ENTRY(glmc_vec2_normalize) + TEST_ENTRY(glmc_vec2_normalize_to) + TEST_ENTRY(glmc_vec2_rotate) + TEST_ENTRY(glmc_vec2_distance2) + TEST_ENTRY(glmc_vec2_distance) + TEST_ENTRY(glmc_vec2_maxv) + TEST_ENTRY(glmc_vec2_minv) + TEST_ENTRY(glmc_vec2_clamp) + TEST_ENTRY(glmc_vec2_lerp) + TEST_ENTRY(glmc_vec2_complex_mul) + TEST_ENTRY(glmc_vec2_complex_div) + + /* vec3 */ + TEST_ENTRY(MACRO_GLM_VEC3_ONE_INIT) + TEST_ENTRY(MACRO_GLM_VEC3_ZERO_INIT) + TEST_ENTRY(MACRO_GLM_VEC3_ONE) + TEST_ENTRY(MACRO_GLM_VEC3_ZERO) + TEST_ENTRY(MACRO_GLM_YUP) + TEST_ENTRY(MACRO_GLM_ZUP) + TEST_ENTRY(MACRO_GLM_XUP) + TEST_ENTRY(MACRO_GLM_FORWARD_RH) + TEST_ENTRY(MACRO_GLM_SHUFFLE3) + TEST_ENTRY(MACRO_GLM_XXX) + TEST_ENTRY(MACRO_GLM_YYY) + TEST_ENTRY(MACRO_GLM_ZZZ) + TEST_ENTRY(MACRO_GLM_ZYX) + TEST_ENTRY(MACRO_glm_vec3_dup) + TEST_ENTRY(MACRO_glm_vec3_flipsign) + TEST_ENTRY(MACRO_glm_vec3_flipsign_to) + TEST_ENTRY(MACRO_glm_vec3_inv) + TEST_ENTRY(MACRO_glm_vec3_inv_to) + TEST_ENTRY(MACRO_glm_vec3_mulv) + + TEST_ENTRY(glm_vec3) + TEST_ENTRY(glm_vec3_copy) + TEST_ENTRY(glm_vec3_zero) + TEST_ENTRY(glm_vec3_one) + TEST_ENTRY(glm_vec3_dot) + TEST_ENTRY(glm_dot) + TEST_ENTRY(glm_vec3_norm2) + TEST_ENTRY(glm_vec3_norm) + TEST_ENTRY(glm_vec3_norm_one) + TEST_ENTRY(glm_vec3_norm_inf) + TEST_ENTRY(glm_vec3_add) + TEST_ENTRY(glm_vec3_adds) + TEST_ENTRY(glm_vec3_sub) + TEST_ENTRY(glm_vec3_subs) + TEST_ENTRY(glm_vec3_mul) + TEST_ENTRY(glm_vec3_scale) + TEST_ENTRY(glm_vec3_scale_as) + TEST_ENTRY(glm_vec3_div) + TEST_ENTRY(glm_vec3_divs) + TEST_ENTRY(glm_vec3_addadd) + TEST_ENTRY(glm_vec3_subadd) + TEST_ENTRY(glm_vec3_muladd) + TEST_ENTRY(glm_vec3_muladds) + TEST_ENTRY(glm_vec3_maxadd) + TEST_ENTRY(glm_vec3_minadd) + TEST_ENTRY(glm_vec3_negate_to) + TEST_ENTRY(glm_vec3_negate) + TEST_ENTRY(glm_vec3_normalize) + TEST_ENTRY(glm_vec3_normalize_to) + TEST_ENTRY(glm_normalize) + TEST_ENTRY(glm_normalize_to) + TEST_ENTRY(glm_vec3_cross) + TEST_ENTRY(glm_vec3_crossn) + TEST_ENTRY(glm_cross) + TEST_ENTRY(glm_vec3_angle) + TEST_ENTRY(glm_vec3_rotate) + TEST_ENTRY(glm_vec3_rotate_m4) + TEST_ENTRY(glm_vec3_rotate_m3) + TEST_ENTRY(glm_vec3_proj) + TEST_ENTRY(glm_vec3_center) + TEST_ENTRY(glmc_vec3_distance2) + TEST_ENTRY(glmc_vec3_distance) + TEST_ENTRY(glm_vec3_maxv) + TEST_ENTRY(glm_vec3_minv) + TEST_ENTRY(glm_vec3_ortho) + TEST_ENTRY(glm_vec3_clamp) + TEST_ENTRY(glm_vec3_mix) + TEST_ENTRY(glm_vec3_mixc) + TEST_ENTRY(glm_vec3_step_uni) + TEST_ENTRY(glm_vec3_step) + TEST_ENTRY(glm_vec3_smoothstep_uni) + TEST_ENTRY(glm_vec3_smoothstep) + TEST_ENTRY(glm_vec3_smoothinterp) + TEST_ENTRY(glm_vec3_smoothinterpc) + TEST_ENTRY(glm_vec3_swizzle) + TEST_ENTRY(glm_vec3_broadcast) + TEST_ENTRY(glm_vec3_fill) + TEST_ENTRY(glm_vec3_eq) + TEST_ENTRY(glm_vec3_eq_eps) + TEST_ENTRY(glm_vec3_eq_all) + TEST_ENTRY(glm_vec3_eqv) + TEST_ENTRY(glm_vec3_eqv_eps) + TEST_ENTRY(glm_vec3_max) + TEST_ENTRY(glm_vec3_min) + TEST_ENTRY(glm_vec3_isnan) + TEST_ENTRY(glm_vec3_isinf) + TEST_ENTRY(glm_vec3_isvalid) + TEST_ENTRY(glm_vec3_sign) + TEST_ENTRY(glm_vec3_abs) + TEST_ENTRY(glm_vec3_fract) + TEST_ENTRY(glm_vec3_hadd) + TEST_ENTRY(glm_vec3_sqrt) + + TEST_ENTRY(glmc_vec3) + TEST_ENTRY(glmc_vec3_copy) + TEST_ENTRY(glmc_vec3_zero) + TEST_ENTRY(glmc_vec3_one) + TEST_ENTRY(glmc_vec3_dot) + TEST_ENTRY(glmc_vec3_norm2) + TEST_ENTRY(glmc_vec3_norm) + TEST_ENTRY(glmc_vec3_norm_one) + TEST_ENTRY(glmc_vec3_norm_inf) + TEST_ENTRY(glmc_vec3_add) + TEST_ENTRY(glmc_vec3_adds) + TEST_ENTRY(glmc_vec3_sub) + TEST_ENTRY(glmc_vec3_subs) + TEST_ENTRY(glmc_vec3_mul) + TEST_ENTRY(glmc_vec3_scale) + TEST_ENTRY(glmc_vec3_scale_as) + TEST_ENTRY(glmc_vec3_div) + TEST_ENTRY(glmc_vec3_divs) + TEST_ENTRY(glmc_vec3_addadd) + TEST_ENTRY(glmc_vec3_subadd) + TEST_ENTRY(glmc_vec3_muladd) + TEST_ENTRY(glmc_vec3_muladds) + TEST_ENTRY(glmc_vec3_maxadd) + TEST_ENTRY(glmc_vec3_minadd) + TEST_ENTRY(glmc_vec3_negate_to) + TEST_ENTRY(glmc_vec3_negate) + TEST_ENTRY(glmc_vec3_normalize) + TEST_ENTRY(glmc_vec3_normalize_to) + TEST_ENTRY(glmc_vec3_cross) + TEST_ENTRY(glmc_vec3_crossn) + TEST_ENTRY(glmc_vec3_angle) + TEST_ENTRY(glmc_vec3_rotate) + TEST_ENTRY(glmc_vec3_rotate_m4) + TEST_ENTRY(glmc_vec3_rotate_m3) + TEST_ENTRY(glmc_vec3_proj) + TEST_ENTRY(glmc_vec3_center) + TEST_ENTRY(glmc_vec3_distance2) + TEST_ENTRY(glmc_vec3_distance) + TEST_ENTRY(glmc_vec3_maxv) + TEST_ENTRY(glmc_vec3_minv) + TEST_ENTRY(glmc_vec3_ortho) + TEST_ENTRY(glmc_vec3_clamp) + TEST_ENTRY(glmc_vec3_mix) + TEST_ENTRY(glmc_vec3_mixc) + TEST_ENTRY(glmc_vec3_step_uni) + TEST_ENTRY(glmc_vec3_step) + TEST_ENTRY(glmc_vec3_smoothstep_uni) + TEST_ENTRY(glmc_vec3_smoothstep) + TEST_ENTRY(glmc_vec3_smoothinterp) + TEST_ENTRY(glmc_vec3_smoothinterpc) + TEST_ENTRY(glmc_vec3_swizzle) + TEST_ENTRY(glmc_vec3_broadcast) + TEST_ENTRY(glmc_vec3_fill) + TEST_ENTRY(glmc_vec3_eq) + TEST_ENTRY(glmc_vec3_eq_eps) + TEST_ENTRY(glmc_vec3_eq_all) + TEST_ENTRY(glmc_vec3_eqv) + TEST_ENTRY(glmc_vec3_eqv_eps) + TEST_ENTRY(glmc_vec3_max) + TEST_ENTRY(glmc_vec3_min) + TEST_ENTRY(glmc_vec3_isnan) + TEST_ENTRY(glmc_vec3_isinf) + TEST_ENTRY(glmc_vec3_isvalid) + TEST_ENTRY(glmc_vec3_sign) + TEST_ENTRY(glmc_vec3_abs) + TEST_ENTRY(glmc_vec3_fract) + TEST_ENTRY(glmc_vec3_hadd) + TEST_ENTRY(glmc_vec3_sqrt) + + /* vec4 */ + TEST_ENTRY(MACRO_GLM_VEC4_ONE_INIT) + TEST_ENTRY(MACRO_GLM_VEC4_ZERO_INIT) + TEST_ENTRY(MACRO_GLM_VEC4_ONE) + TEST_ENTRY(MACRO_GLM_VEC4_ZERO) + TEST_ENTRY(MACRO_GLM_XXXX) + TEST_ENTRY(MACRO_GLM_YYYY) + TEST_ENTRY(MACRO_GLM_ZZZZ) + TEST_ENTRY(MACRO_GLM_WZYX) + TEST_ENTRY(MACRO_glm_vec4_dup) + TEST_ENTRY(MACRO_glm_vec4_flipsign) + TEST_ENTRY(MACRO_glm_vec4_flipsign_to) + TEST_ENTRY(MACRO_glm_vec4_inv) + TEST_ENTRY(MACRO_glm_vec4_inv_to) + TEST_ENTRY(MACRO_glm_vec4_mulv) + + TEST_ENTRY(glm_vec4) + TEST_ENTRY(glm_vec4_copy3) + TEST_ENTRY(glm_vec4_copy) + TEST_ENTRY(glm_vec4_ucopy) + TEST_ENTRY(glm_vec4_zero) + TEST_ENTRY(glm_vec4_one) + TEST_ENTRY(glm_vec4_dot) + TEST_ENTRY(glm_vec4_norm2) + TEST_ENTRY(glm_vec4_norm) + TEST_ENTRY(glm_vec4_norm_one) + TEST_ENTRY(glm_vec4_norm_inf) + TEST_ENTRY(glm_vec4_add) + TEST_ENTRY(glm_vec4_adds) + TEST_ENTRY(glm_vec4_sub) + TEST_ENTRY(glm_vec4_subs) + TEST_ENTRY(glm_vec4_mul) + TEST_ENTRY(glm_vec4_scale) + TEST_ENTRY(glm_vec4_scale_as) + TEST_ENTRY(glm_vec4_div) + TEST_ENTRY(glm_vec4_divs) + TEST_ENTRY(glm_vec4_addadd) + TEST_ENTRY(glm_vec4_subadd) + TEST_ENTRY(glm_vec4_muladd) + TEST_ENTRY(glm_vec4_muladds) + TEST_ENTRY(glm_vec4_maxadd) + TEST_ENTRY(glm_vec4_minadd) + TEST_ENTRY(glm_vec4_negate_to) + TEST_ENTRY(glm_vec4_negate) + TEST_ENTRY(glm_vec4_normalize) + TEST_ENTRY(glm_vec4_normalize_to) + TEST_ENTRY(glm_vec4_distance2) + TEST_ENTRY(glm_vec4_distance) + TEST_ENTRY(glm_vec4_maxv) + TEST_ENTRY(glm_vec4_minv) + TEST_ENTRY(glm_vec4_clamp) + TEST_ENTRY(glm_vec4_lerp) + TEST_ENTRY(glm_vec4_lerpc) + TEST_ENTRY(glm_vec4_mix) + TEST_ENTRY(glm_vec4_mixc) + TEST_ENTRY(glm_vec4_step_uni) + TEST_ENTRY(glm_vec4_step) + TEST_ENTRY(glm_vec4_smoothstep_uni) + TEST_ENTRY(glm_vec4_smoothstep) + TEST_ENTRY(glm_vec4_smoothinterp) + TEST_ENTRY(glm_vec4_smoothinterpc) + TEST_ENTRY(glm_vec4_cubic) + TEST_ENTRY(glm_vec4_swizzle) + TEST_ENTRY(glm_vec4_broadcast) + TEST_ENTRY(glm_vec4_fill) + TEST_ENTRY(glm_vec4_eq) + TEST_ENTRY(glm_vec4_eq_eps) + TEST_ENTRY(glm_vec4_eq_all) + TEST_ENTRY(glm_vec4_eqv) + TEST_ENTRY(glm_vec4_eqv_eps) + TEST_ENTRY(glm_vec4_max) + TEST_ENTRY(glm_vec4_min) + TEST_ENTRY(glm_vec4_isnan) + TEST_ENTRY(glm_vec4_isinf) + TEST_ENTRY(glm_vec4_isvalid) + TEST_ENTRY(glm_vec4_sign) + TEST_ENTRY(glm_vec4_abs) + TEST_ENTRY(glm_vec4_fract) + TEST_ENTRY(glm_vec4_hadd) + TEST_ENTRY(glm_vec4_sqrt) + + TEST_ENTRY(glmc_vec4) + TEST_ENTRY(glmc_vec4_copy3) + TEST_ENTRY(glmc_vec4_copy) + TEST_ENTRY(glmc_vec4_ucopy) + TEST_ENTRY(glmc_vec4_zero) + TEST_ENTRY(glmc_vec4_one) + TEST_ENTRY(glmc_vec4_dot) + TEST_ENTRY(glmc_vec4_norm2) + TEST_ENTRY(glmc_vec4_norm) + TEST_ENTRY(glmc_vec4_norm_one) + TEST_ENTRY(glmc_vec4_norm_inf) + TEST_ENTRY(glmc_vec4_add) + TEST_ENTRY(glmc_vec4_adds) + TEST_ENTRY(glmc_vec4_sub) + TEST_ENTRY(glmc_vec4_subs) + TEST_ENTRY(glmc_vec4_mul) + TEST_ENTRY(glmc_vec4_scale) + TEST_ENTRY(glmc_vec4_scale_as) + TEST_ENTRY(glmc_vec4_div) + TEST_ENTRY(glmc_vec4_divs) + TEST_ENTRY(glmc_vec4_addadd) + TEST_ENTRY(glmc_vec4_subadd) + TEST_ENTRY(glmc_vec4_muladd) + TEST_ENTRY(glmc_vec4_muladds) + TEST_ENTRY(glmc_vec4_maxadd) + TEST_ENTRY(glmc_vec4_minadd) + TEST_ENTRY(glmc_vec4_negate_to) + TEST_ENTRY(glmc_vec4_negate) + TEST_ENTRY(glmc_vec4_normalize) + TEST_ENTRY(glmc_vec4_normalize_to) + TEST_ENTRY(glmc_vec4_distance2) + TEST_ENTRY(glmc_vec4_distance) + TEST_ENTRY(glmc_vec4_maxv) + TEST_ENTRY(glmc_vec4_minv) + TEST_ENTRY(glmc_vec4_clamp) + TEST_ENTRY(glmc_vec4_lerp) + TEST_ENTRY(glmc_vec4_lerpc) + TEST_ENTRY(glmc_vec4_mix) + TEST_ENTRY(glmc_vec4_mixc) + TEST_ENTRY(glmc_vec4_step_uni) + TEST_ENTRY(glmc_vec4_step) + TEST_ENTRY(glmc_vec4_smoothstep_uni) + TEST_ENTRY(glmc_vec4_smoothstep) + TEST_ENTRY(glmc_vec4_smoothinterp) + TEST_ENTRY(glmc_vec4_smoothinterpc) + TEST_ENTRY(glmc_vec4_cubic) + TEST_ENTRY(glmc_vec4_swizzle) + TEST_ENTRY(glmc_vec4_broadcast) + TEST_ENTRY(glmc_vec4_fill) + TEST_ENTRY(glmc_vec4_eq) + TEST_ENTRY(glmc_vec4_eq_eps) + TEST_ENTRY(glmc_vec4_eq_all) + TEST_ENTRY(glmc_vec4_eqv) + TEST_ENTRY(glmc_vec4_eqv_eps) + TEST_ENTRY(glmc_vec4_max) + TEST_ENTRY(glmc_vec4_min) + TEST_ENTRY(glmc_vec4_isnan) + TEST_ENTRY(glmc_vec4_isinf) + TEST_ENTRY(glmc_vec4_isvalid) + TEST_ENTRY(glmc_vec4_sign) + TEST_ENTRY(glmc_vec4_abs) + TEST_ENTRY(glmc_vec4_fract) + TEST_ENTRY(glmc_vec4_hadd) + TEST_ENTRY(glmc_vec4_sqrt) + + /* ivec2 */ + TEST_ENTRY(glm_ivec2) + TEST_ENTRY(glm_ivec2_copy) + TEST_ENTRY(glm_ivec2_zero) + TEST_ENTRY(glm_ivec2_one) + TEST_ENTRY(glm_ivec2_add) + TEST_ENTRY(glm_ivec2_adds) + TEST_ENTRY(glm_ivec2_sub) + TEST_ENTRY(glm_ivec2_subs) + TEST_ENTRY(glm_ivec2_mul) + TEST_ENTRY(glm_ivec2_scale) + TEST_ENTRY(glm_ivec2_distance2) + TEST_ENTRY(glm_ivec2_distance) + TEST_ENTRY(glm_ivec2_maxv) + TEST_ENTRY(glm_ivec2_minv) + TEST_ENTRY(glm_ivec2_clamp) + + TEST_ENTRY(glmc_ivec2) + TEST_ENTRY(glmc_ivec2_copy) + TEST_ENTRY(glmc_ivec2_zero) + TEST_ENTRY(glmc_ivec2_one) + TEST_ENTRY(glmc_ivec2_add) + TEST_ENTRY(glmc_ivec2_adds) + TEST_ENTRY(glmc_ivec2_sub) + TEST_ENTRY(glmc_ivec2_subs) + TEST_ENTRY(glmc_ivec2_mul) + TEST_ENTRY(glmc_ivec2_scale) + TEST_ENTRY(glmc_ivec2_distance2) + TEST_ENTRY(glmc_ivec2_distance) + TEST_ENTRY(glmc_ivec2_maxv) + TEST_ENTRY(glmc_ivec2_minv) + TEST_ENTRY(glmc_ivec2_clamp) + + /* ivec3 */ + TEST_ENTRY(glm_ivec3) + TEST_ENTRY(glm_ivec3_copy) + TEST_ENTRY(glm_ivec3_zero) + TEST_ENTRY(glm_ivec3_one) + TEST_ENTRY(glm_ivec3_add) + TEST_ENTRY(glm_ivec3_adds) + TEST_ENTRY(glm_ivec3_sub) + TEST_ENTRY(glm_ivec3_subs) + TEST_ENTRY(glm_ivec3_mul) + TEST_ENTRY(glm_ivec3_scale) + TEST_ENTRY(glm_ivec3_distance2) + TEST_ENTRY(glm_ivec3_distance) + TEST_ENTRY(glm_ivec3_maxv) + TEST_ENTRY(glm_ivec3_minv) + TEST_ENTRY(glm_ivec3_clamp) + + TEST_ENTRY(glmc_ivec3) + TEST_ENTRY(glmc_ivec3_copy) + TEST_ENTRY(glmc_ivec3_zero) + TEST_ENTRY(glmc_ivec3_one) + TEST_ENTRY(glmc_ivec3_add) + TEST_ENTRY(glmc_ivec3_adds) + TEST_ENTRY(glmc_ivec3_sub) + TEST_ENTRY(glmc_ivec3_subs) + TEST_ENTRY(glmc_ivec3_mul) + TEST_ENTRY(glmc_ivec3_scale) + TEST_ENTRY(glmc_ivec3_distance2) + TEST_ENTRY(glmc_ivec3_distance) + TEST_ENTRY(glmc_ivec3_maxv) + TEST_ENTRY(glmc_ivec3_minv) + TEST_ENTRY(glmc_ivec3_clamp) + + /* ivec4 */ + TEST_ENTRY(glm_ivec4) + TEST_ENTRY(glm_ivec4_copy) + TEST_ENTRY(glm_ivec4_zero) + TEST_ENTRY(glm_ivec4_one) + TEST_ENTRY(glm_ivec4_add) + TEST_ENTRY(glm_ivec4_adds) + TEST_ENTRY(glm_ivec4_sub) + TEST_ENTRY(glm_ivec4_subs) + TEST_ENTRY(glm_ivec4_mul) + TEST_ENTRY(glm_ivec4_scale) + TEST_ENTRY(glm_ivec4_distance2) + TEST_ENTRY(glm_ivec4_distance) + TEST_ENTRY(glm_ivec4_maxv) + TEST_ENTRY(glm_ivec4_minv) + TEST_ENTRY(glm_ivec4_clamp) + + TEST_ENTRY(glmc_ivec4) + TEST_ENTRY(glmc_ivec4_copy) + TEST_ENTRY(glmc_ivec4_zero) + TEST_ENTRY(glmc_ivec4_one) + TEST_ENTRY(glmc_ivec4_add) + TEST_ENTRY(glmc_ivec4_adds) + TEST_ENTRY(glmc_ivec4_sub) + TEST_ENTRY(glmc_ivec4_subs) + TEST_ENTRY(glmc_ivec4_mul) + TEST_ENTRY(glmc_ivec4_scale) + TEST_ENTRY(glmc_ivec4_distance2) + TEST_ENTRY(glmc_ivec4_distance) + TEST_ENTRY(glmc_ivec4_maxv) + TEST_ENTRY(glmc_ivec4_minv) + TEST_ENTRY(glmc_ivec4_clamp) + + /* structs */ + TEST_ENTRY(mat3s_identity_init) + TEST_ENTRY(mat3s_zero_init) + TEST_ENTRY(mat4s_identity_init) + TEST_ENTRY(mat4s_zero_init) + TEST_ENTRY(quats_zero_init) + TEST_ENTRY(vec3s_one_init) + TEST_ENTRY(vec3s_zero_init) + TEST_ENTRY(vec4s_black_init) + TEST_ENTRY(vec4s_one_init) + TEST_ENTRY(vec4s_zero_init) +}; + +#endif /* tests_h */ -- cgit v1.2.1