mirror of
https://github.com/recp/cglm.git
synced 2025-12-24 20:34:58 +00:00
add bezier helpers
This commit is contained in:
41
test/src/test_bezier.c
Normal file
41
test/src/test_bezier.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
void
|
||||
test_bezier(void **state) {
|
||||
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();
|
||||
|
||||
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_true(glm_eq(Bs, Bs_plain));
|
||||
assert_true(glm_eq(smc, Bs_plain));
|
||||
assert_true(glm_eq(Bs, smc));
|
||||
}
|
||||
@@ -38,7 +38,10 @@ main(int argc, const char * argv[]) {
|
||||
cmocka_unit_test(test_vec3),
|
||||
|
||||
/* affine */
|
||||
cmocka_unit_test(test_affine)
|
||||
cmocka_unit_test(test_affine),
|
||||
|
||||
/* bezier */
|
||||
cmocka_unit_test(test_bezier)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -40,4 +40,7 @@ test_vec3(void **state);
|
||||
void
|
||||
test_affine(void **state);
|
||||
|
||||
void
|
||||
test_bezier(void **state);
|
||||
|
||||
#endif /* test_tests_h */
|
||||
|
||||
Reference in New Issue
Block a user