curve: cubic hermite intrpolation

This commit is contained in:
Recep Aslantas
2019-01-29 22:17:44 +03:00
parent 1e121a4855
commit 7848dda1dd
7 changed files with 102 additions and 12 deletions

View File

@@ -21,6 +21,20 @@ test_bezier_plain(float s, float p0, float c0, float c1, float p1) {
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);
}
void
test_bezier(void **state) {
float s, p0, p1, c0, c1, smc, Bs, Bs_plain;
@@ -31,6 +45,7 @@ test_bezier(void **state) {
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);
@@ -38,4 +53,13 @@ test_bezier(void **state) {
assert_true(glm_eq(Bs, Bs_plain));
assert_true(glm_eq(smc, Bs_plain));
assert_true(glm_eq(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_true(glm_eq(Bs, Bs_plain));
assert_true(glm_eq(smc, Bs_plain));
assert_true(glm_eq(Bs, smc));
}