This is an example on how to use the vec2.h file.
#include "../Test.h"
template<class T>
class Vec2TestCase : public Test
{
bool testInitialization() {
T vals[2] = { 2, 4 };
vec2<T> vec = build_vec2<T>((
void*)vals);
return true;
}
bool testAssignment() {
foo[0] = (T)3;
foo[1] = (T)4;
return true;
}
bool testMemberAccess() {
assert(foo[0] == 1);
assert(foo[1] == 2);
return true;
}
bool testMisc() {
assert(foo.
length() == 2.82842708f);
assert(bar.
length() == 2.82842708f);
assert(baz.
length() == 10.0f);
if(extended) {
assert(normFoo.
x - (T)0.70710679328816484f < 1e-7);
assert(normFoo.
y - (T)0.70710679328816484f < 1e-7);
assert(normBar.
x - (T)0.70710679328816484f < 1e-7);
assert(normBar.
y - (T)-0.70710679328816484f < 1e-7);
assert(normBaz.
x - (T)1.0f < 1e-7);
assert(normBaz.
y - (T)0.0f < 1e-7);
}
return true;
}
bool testOperators() {
fooCopy += bar;
assert(fooCopy.
x == 2.0f);
assert(fooCopy.
y == 0.0f);
fooCopy = foo + bar;
assert(fooCopy.
x == 2.0f);
assert(fooCopy.
y == 0.0f);
fooCopy = foo;
fooCopy -= bar;
assert(fooCopy.
x == 0.0f);
assert(fooCopy.
y == 2.0f);
fooCopy = foo - bar;
assert(fooCopy.
x == 0.0f);
assert(fooCopy.
y == 2.0f);
fooCopy = foo;
fooCopy *= 2.0f;
assert(fooCopy.
x == (T)2.0f);
assert(fooCopy.
y == (T)2.0f);
fooCopy = foo * 2.0f;
assert(fooCopy.
x == (T)2.0f);
assert(fooCopy.
y == (T)2.0f);
float fooVal = foo * bar;
assert(fooVal == (T)0.0f);
fooVal = foo * baz;
assert(fooVal == (T)10.0f);
fooCopy = foo;
fooCopy /= 2.0f;
assert(fooCopy.
x == (T)0.5f);
assert(fooCopy.
y == (T)0.5f);
fooCopy = foo / 2.0f;
assert(fooCopy.
x == (T)0.5f);
assert(fooCopy.
y == (T)0.5f);
return true;
}
bool testComparison() {
assert(a == b);
return true;
}
bool testCast() {
assert(a2 == b);
return true;
}
public:
virtual void run() {
testInitialization();
testAssignment();
testMemberAccess();
testMisc();
testOperators();
testComparison();
testCast();
}
};
int main() {
auto testCase = Vec2TestCase<int>();
testCase.run();
auto testCase2 = Vec2TestCase<float>();
testCase2.extended = true;
testCase2.run();
auto testCase3 = Vec2TestCase<double>();
testCase3.extended = true;
testCase3.run();
return 0;
}
vec2< T > normalize() const
Definition: vec2.h:91
float length() const
Definition: vec2.h:86