First round of animation improvements
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "dusktest.h"
|
||||
#include "animation/keyframeset.h"
|
||||
|
||||
static void test_keyframeSetGetValuePerTrack(void **state) {
|
||||
keyframe_t xKeyframes[] = {
|
||||
{ .time = 0.0f, .value = 0.0f, .easing = EASING_LINEAR },
|
||||
{ .time = 1.0f, .value = 10.0f, .easing = EASING_LINEAR }
|
||||
};
|
||||
keyframe_t yKeyframes[] = {
|
||||
{ .time = 0.0f, .value = 100.0f, .easing = EASING_LINEAR },
|
||||
{ .time = 1.0f, .value = 200.0f, .easing = EASING_LINEAR }
|
||||
};
|
||||
keyframe_t *tracks[] = { xKeyframes, yKeyframes };
|
||||
uint16_t trackCounts[] = { 2, 2 };
|
||||
|
||||
keyframeset_t set;
|
||||
keyframeSetInit(&set, tracks, trackCounts, 2);
|
||||
|
||||
assert_float_equal(keyframeSetGetValue(&set, 0, 0.5f), 5.0f, 0.0001f);
|
||||
assert_float_equal(keyframeSetGetValue(&set, 1, 0.5f), 150.0f, 0.0001f);
|
||||
}
|
||||
|
||||
static void test_keyframeSetGetValuesFillsAllTracks(void **state) {
|
||||
keyframe_t xKeyframes[] = {
|
||||
{ .time = 0.0f, .value = 0.0f, .easing = EASING_LINEAR },
|
||||
{ .time = 1.0f, .value = 10.0f, .easing = EASING_LINEAR }
|
||||
};
|
||||
keyframe_t yKeyframes[] = {
|
||||
{ .time = 0.0f, .value = 100.0f, .easing = EASING_LINEAR },
|
||||
{ .time = 1.0f, .value = 200.0f, .easing = EASING_LINEAR }
|
||||
};
|
||||
keyframe_t *tracks[] = { xKeyframes, yKeyframes };
|
||||
uint16_t trackCounts[] = { 2, 2 };
|
||||
|
||||
keyframeset_t set;
|
||||
keyframeSetInit(&set, tracks, trackCounts, 2);
|
||||
|
||||
float_t values[2];
|
||||
keyframeSetGetValues(&set, 0.5f, values);
|
||||
assert_float_equal(values[0], 5.0f, 0.0001f);
|
||||
assert_float_equal(values[1], 150.0f, 0.0001f);
|
||||
}
|
||||
|
||||
static void test_keyframeSetGetDurationIsLongestTrack(void **state) {
|
||||
keyframe_t shortKeyframes[] = {
|
||||
{ .time = 0.0f, .value = 0.0f, .easing = EASING_LINEAR },
|
||||
{ .time = 1.0f, .value = 10.0f, .easing = EASING_LINEAR }
|
||||
};
|
||||
keyframe_t longKeyframes[] = {
|
||||
{ .time = 0.0f, .value = 0.0f, .easing = EASING_LINEAR },
|
||||
{ .time = 3.5f, .value = 10.0f, .easing = EASING_LINEAR }
|
||||
};
|
||||
keyframe_t *tracks[] = { shortKeyframes, longKeyframes };
|
||||
uint16_t trackCounts[] = { 2, 2 };
|
||||
|
||||
keyframeset_t set;
|
||||
keyframeSetInit(&set, tracks, trackCounts, 2);
|
||||
|
||||
assert_float_equal(keyframeSetGetDuration(&set), 3.5f, 0.0001f);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_keyframeSetGetValuePerTrack),
|
||||
cmocka_unit_test(test_keyframeSetGetValuesFillsAllTracks),
|
||||
cmocka_unit_test(test_keyframeSetGetDurationIsLongestTrack),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user