From 78b2e2d2ccfcd431378b8f479010456e5a223f0e Mon Sep 17 00:00:00 2001 From: Uwila Date: Mon, 6 Apr 2020 11:38:27 +0200 Subject: [PATCH 1/5] Add tests for glm_ray_triangle --- test/src/test_ray.h | 34 ++++++++++++++++++++++++++++++++++ test/src/tests.c | 1 + test/tests.h | 6 ++++++ 3 files changed, 41 insertions(+) create mode 100644 test/src/test_ray.h diff --git a/test/src/test_ray.h b/test/src/test_ray.h new file mode 100644 index 0000000..a85ad8c --- /dev/null +++ b/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/test/src/tests.c b/test/src/tests.c index 669b33c..956823f 100644 --- a/test/src/tests.c +++ b/test/src/tests.c @@ -23,6 +23,7 @@ #include "test_plane.h" #include "test_affine.h" #include "test_affine_mat.h" +#include "test_ray.h" #undef GLM #undef GLM_PREFIX diff --git a/test/tests.h b/test/tests.h index 4c9a552..83351a5 100644 --- a/test/tests.h +++ b/test/tests.h @@ -218,6 +218,9 @@ TEST_DECLARE(clamp) /* euler */ TEST_DECLARE(euler) +/* ray */ +TEST_DECLARE(glm_ray_triangle) + /* quat */ TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY_INIT) TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY) @@ -905,6 +908,9 @@ TEST_LIST { /* euler */ TEST_ENTRY(euler) + /* ray */ + TEST_ENTRY(glm_ray_triangle) + /* quat */ TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY_INIT) TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY) From 90eb164a438d640b40064bb7961ecc7d90f39c7d Mon Sep 17 00:00:00 2001 From: Uwila Date: Mon, 6 Apr 2020 11:42:23 +0200 Subject: [PATCH 2/5] Add tests for cglm_ray_triangle --- test/src/tests.c | 1 + test/tests.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/test/src/tests.c b/test/src/tests.c index 956823f..ea9f902 100644 --- a/test/src/tests.c +++ b/test/src/tests.c @@ -45,6 +45,7 @@ #include "test_plane.h" #include "test_affine.h" #include "test_affine_mat.h" +#include "test_ray.h" #undef GLM #undef GLM_PREFIX diff --git a/test/tests.h b/test/tests.h index 83351a5..1ed75d8 100644 --- a/test/tests.h +++ b/test/tests.h @@ -220,6 +220,7 @@ TEST_DECLARE(euler) /* ray */ TEST_DECLARE(glm_ray_triangle) +TEST_DECLARE(glmc_ray_triangle) /* quat */ TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY_INIT) @@ -910,6 +911,7 @@ TEST_LIST { /* ray */ TEST_ENTRY(glm_ray_triangle) + TEST_ENTRY(glmc_ray_triangle) /* quat */ TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY_INIT) From 7bcd7609eb863658c47d1a1b0877567e6db98dcc Mon Sep 17 00:00:00 2001 From: Uwila Date: Mon, 6 Apr 2020 11:43:12 +0200 Subject: [PATCH 3/5] Fix test_ray.h style --- test/src/test_ray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/test_ray.h b/test/src/test_ray.h index a85ad8c..b7816f0 100644 --- a/test/src/test_ray.h +++ b/test/src/test_ray.h @@ -11,7 +11,7 @@ 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 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}; From 38cb693834aef1acb2a573f48b45198ccd33d195 Mon Sep 17 00:00:00 2001 From: Uwila Date: Mon, 6 Apr 2020 13:51:29 +0200 Subject: [PATCH 4/5] Update vcxproj files for test_ray --- win/cglm-test.vcxproj | 1 + win/cglm-test.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/win/cglm-test.vcxproj b/win/cglm-test.vcxproj index 1c0916d..6599103 100644 --- a/win/cglm-test.vcxproj +++ b/win/cglm-test.vcxproj @@ -42,6 +42,7 @@ + diff --git a/win/cglm-test.vcxproj.filters b/win/cglm-test.vcxproj.filters index c81dc11..b8f7326 100644 --- a/win/cglm-test.vcxproj.filters +++ b/win/cglm-test.vcxproj.filters @@ -79,5 +79,8 @@ src + + src + \ No newline at end of file From 47807b79558ada4a4483062376b35980f2903358 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 6 Apr 2020 16:44:07 +0300 Subject: [PATCH 5/5] Update test_ray.h --- test/src/test_ray.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/src/test_ray.h b/test/src/test_ray.h index b7816f0..c1b0281 100644 --- a/test/src/test_ray.h +++ b/test/src/test_ray.h @@ -8,25 +8,25 @@ #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}; + /* 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; + 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 + /* 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 + /* Check that we can disregard distance and pass NULL pointer instead */ hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, NULL); ASSERT(hit);