-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-7.cpp
More file actions
59 lines (50 loc) · 1.22 KB
/
test-7.cpp
File metadata and controls
59 lines (50 loc) · 1.22 KB
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
#include "Vector4.h"
template<class T, class S>
bool equals(T a, S b) {
return fabs(a - b) < 1.0e-8;
}
#ifdef VM_INCLUDE_NAMESPACE
using namespace kh_vecmath;
#endif
/**
* test for Vector4
*/
#ifdef TESTALL
int test_7() {
#else
int main(int, char**) {
#endif
Vector4d p1(1,2,3,4);
Vector4d p2(4,6,1,5);
// dot product
Vector4d::value_type d = p1.dot(p2);
assert(equals(d, 39));
// length
d = p1.length();
assert(equals(d, sqrt(p1.dot(p1))));
// normalize
p1.normalize();
assert(equals(p1.x,1/d));
assert(equals(p1.y,2/d));
assert(equals(p1.z,3/d));
assert(equals(p1.w,4/d));
p1.set(-1,3,1,2);
d = p1.length();
p2.normalize(p1);
assert(equals(p2.x,-1/d));
assert(equals(p2.y, 3/d));
assert(equals(p2.z, 1/d));
assert(equals(p2.w, 2/d));
// angle
p1.set(3, 4, 1, -2);
p2.set(-4, 3, 1, -1);
d = p1.angle(p2);
assert(equals(d, acos(p1.dot(p2)/p1.length()/p2.length())));
d = p2.angle(p1);
assert(equals(d, acos(p1.dot(p2)/p1.length()/p2.length())));
d = p1.angle(p1);
assert(equals(d, 0));
d = p2.angle(p2);
assert(equals(d, 0));
return 0;
}