summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/tests/easing_test.cpp
blob: 4556c3ad19ce172957ae2eb335ce552744c423a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
 * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
 */

#include "test.h"

#include <bx/easing.h>
#include <bx/file.h>

TEST_CASE("easing", "")
{
	bx::WriterI* writer = bx::getNullOut();
	bx::Error err;

	for (uint32_t ee = 0; ee < bx::Easing::Count; ++ee)
	{
		bx::write(writer, &err, "\n\n%d\n", ee);

		const bx::EaseFn easing = bx::getEaseFunc(bx::Easing::Enum(ee) );

		const int32_t nx = 64;
		const int32_t ny = 10;

		bx::write(writer, &err, "\t///      ^\n");

		for (int32_t yy = ny+4; yy >= -5; --yy)
		{
			const float ys = float(yy    )/float(ny);
			const float ye = float(yy+1.0)/float(ny);

			bx::write(writer, &err, "\t///      %c", yy != 0 ? '|' : '+');

			for (int32_t xx = 0; xx < nx; ++xx)
			{
				int32_t jj = 0;
				for (; jj < 10; ++jj)
				{
					const float tt = float(xx*10+jj)/10.0f/float(nx);
					const float vv = easing(tt);

					if (vv >= ys
					&&  vv <  ye)
					{
						bx::write(writer, "*");
						break;
					}
				}

				if (jj == 10)
				{
					bx::write(writer, &err, "%c", yy != 0 ? ' ' : '-');
				}
			}

			bx::write(writer, &err, "%s\n", yy != 0 ? "" : ">");
		}
	}
}