bezier: add straight line tests for order 1-3

This commit is contained in:
Danny Robson 2015-01-22 14:57:57 +11:00
parent b9f38eb4a9
commit 7934ae865b
2 changed files with 63 additions and 0 deletions

View File

@ -3,6 +3,7 @@ AM_CXXFLAGS = $(COMMON_CXXFLAGS) -I$(top_srcdir)
TEST_BIN = \
backtrace \
bezier \
bitwise \
checksum \
colour \

62
test/bezier.cpp Normal file
View File

@ -0,0 +1,62 @@
#include "bezier.hpp"
#include "debug.hpp"
#include <cstdlib>
int
main (int, char**)
{
// Check degree-1 beziers
{
static const util::bezier<1> b1 ({{ 0.f, 0.f},
{100.f, 100.f}});
auto p0 = b1.eval(0.f);
auto p1 = b1.eval(1.f);
CHECK_EQ (p0, b1[0]);
CHECK_EQ (p1, b1[1]);
auto px = b1.eval(0.5f);
auto rx = b1[0] + 0.5f * (b1[1]-b1[0]);
CHECK_EQ (px, rx);
}
// Check degree-2 beziers
{
static const util::bezier<2> b2 ({{ 0.f, 0.f},
{ 50.f, 50.f},
{100.f, 100.f}});
auto p0 = b2.eval(0.f);
auto p2 = b2.eval(1.f);
CHECK_EQ (p0, b2[0]);
CHECK_EQ (p2, b2[2]);
auto px = b2.eval(0.5f);
auto rx = b2[0] + 0.5f * (b2[2]-b2[0]);
CHECK_EQ (px, rx);
}
// Check degree-3 beziers
{
static const util::bezier<3> b3 ({{ 0.f, 0.f },
{ 33.f, 33.f },
{ 67.f, 67.f },
{ 100.f, 100.f }});
auto p0 = b3.eval (0.f);
auto p3 = b3.eval (1.f);
CHECK_EQ (p0, b3[0]);
CHECK_EQ (p3, b3[3]);
auto px = b3.eval (0.5f);
auto rx = b3[0] + 0.5f * (b3[3] - b3[0]);
CHECK_EQ (px, rx);
}
return EXIT_SUCCESS;
}