view src/main.cpp @ 4:f4e384b966b9

About half done with Vectors
author Eris Caffee <discordia@eldalin.com>
date Tue, 30 Aug 2011 11:08:12 -0500
parents
children f6e6f3c8f7eb
line source
1 #include <iostream>
2 #include <iomanip>
3 #include <string>
4 using namespace std;
6 #include "Math.h"
7 using namespace arda::Vector;
9 int main (int argc, char * argv[])
10 {
11 string s1, s2;
13 // Vector::scale*()
14 {
15 cout << "===============================================================" << endl <<
16 "Testing Vector::scale*()" << endl;
18 Vector2i v2i = { 1, 2 };
19 cout << setw(40) << "v2i: " << vectostr2(v2i, s1) << endl;
20 scale2(v2i, 2);
21 cout << setw(40) << "scale2(v2i, 2): " << vectostr2(v2i, s1) << endl;
22 scale2(v2i, 2.4);
23 cout << setw(40) << "scale2(vi, 2.4): " << vectostr2(v2i, s1) << endl;
24 scale2(scale2(v2i, 2), 3);
25 cout << setw(40) << "scale2(scale2(v2i, 2), 3): " << vectostr2(v2i, s1) << endl;
28 Vector3f v3f = { 3.0, 4.1, 5.2 };
29 cout << setw(40) << "v3f: " << vectostr3(v3f, s1) << endl;
30 scale3(v3f, 2.2f);
31 cout << setw(40) << "scale3(v3f, 2.2f): " << vectostr3(v3f, s1) << endl;
32 scale3(v3f, 2);
33 cout << setw(40) << "scale3(v2f, 2): " << vectostr3(v3f, s1) << endl;
35 Vector4d v4d = { 6.0L, 7.1L, 8.2L, 9.3L };
36 cout << setw(40) << "vd4: " << vectostr4(v4d, s1) << endl;
37 scale4(v4d, 2.0);
38 cout << setw(40) << "scale4(v4d, 2.0): " << vectostr4(v4d, s1) << endl;
39 scale4(v4d, 2);
40 cout << setw(40) << "scale4(v4d, 2): " << vectostr4(v4d, s1) << endl;
41 }
44 // Vector::dot*()
45 {
46 cout << "===============================================================" << endl <<
47 "Testing Vector::dot*()" << endl;
49 Vector2i v2i[2] = { { 1, 2 }, { 3, 4 } };
50 cout << setw(40) << "v2i[0]: " << vectostr2(v2i[0], s1) << endl;
51 cout << setw(40) << "v2i[1]: " << vectostr2(v2i[1], s1) << endl;
52 cout << setw(40) << "dot2(v2i[0], v2i[1]): " << dot2(v2i[0], v2i[1]) << endl;
54 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
55 cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl;
56 cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl;
57 cout << setw(40) << "dot3(v3f[0], v3f[1]): " << dot3(v3f[0], v3f[1]) << endl;
59 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
60 cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl;
61 cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl;
62 cout << setw(40) << "dot4(v4d[0], v4d[1]): " << dot4(v4d[0], v4d[1]) << endl;
64 }
66 // Vector::length*()
67 {
68 cout << "===============================================================" << endl <<
69 "Testing Vector::length*()" << endl;
71 Vector2i v2i = { 1, 2 };
72 cout << setw(40) << "v2i: " << vectostr2(v2i, s1) << endl;
73 cout << setw(40) << "length2(v2i): " << length2(v2i) << endl;
75 Vector3f v3f = { 1.1f, 2.2f, 3.3f };
76 cout << setw(40) << "v3f: " << vectostr3(v3f, s1) << endl;
77 cout << setw(40) << "length3(v3f): " << length3(v3f) << endl;
79 Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 };
80 cout << setw(40) << "v4d: " << vectostr4(v4d, s1) << endl;
81 cout << setw(40) << "length4(v4d): " << length4(v4d) << endl;
83 }
85 // Vector::add*()
86 {
87 cout << "===============================================================" << endl <<
88 "Testing Vector::add*()" << endl;
90 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } };
91 Vector2i v2ires;
92 cout << setw(40) << "v2i[0]: " << vectostr2(v2i[0], s1) << endl;
93 cout << setw(40) << "v2i[1]: " << vectostr2(v2i[1], s1) << endl;
94 add2(v2i[0], v2i[1], v2ires);
95 cout << setw(40) << "add2(v2i[0], v2i[1], v2ires): " << vectostr2(v2ires, s1) << endl;
96 cout << setw(40) << "length2(add2(v2i[0], v2i[1], v2ires)): " << length2(add2(v2i[0], v2i[1], v2ires)) << endl;
98 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
99 Vector3f v3fres;
100 cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl;
101 cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl;
102 add3(v3f[0], v3f[1], v3fres);
103 cout << setw(40) << "add3(v3f[0], v3f[1], v3fres): " << vectostr3(v3fres, s1) << endl;
104 cout << setw(40) << "length3(add3(v3f[0], v3f[1], v3fres)): " << length3(add3(v3f[0], v3f[1], v3fres)) << endl;
106 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
107 Vector4d v4dres;
108 cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl;
109 cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl;
110 add4(v4d[0], v4d[1], v4dres);
111 cout << setw(40) << "add4(v4d[0], v4d[1], v4dres): " << vectostr4(v4dres, s1) << endl;
112 cout << setw(40) << "length4(add4(v4d[0], v4d[1], v4dres)): " << length4(add4(v4d[0], v4d[1], v4dres)) << endl;
114 }
116 // Vector::add*()
117 {
118 cout << "===============================================================" << endl <<
119 "Testing Vector::normalize*()" << endl;
121 Vector2f v2f = { 1.1, 2.2 };
122 cout << setw(40) << "v2f: " << vectostr2(v2f, s1) << endl;
123 normalize2(v2f);
124 cout << setw(40) << "normalize2(v2f): " << vectostr2(v2f, s1) << endl;
125 scale2(normalize2(v2f), 2.0);
126 cout << setw(40) << "scale(normalize2(v2f), 2.0): " << vectostr2(v2f, s1) << endl;
128 Vector3f v3f = { 1.1f, 2.2f, 3.3f };
129 cout << setw(40) << "v3f: " << vectostr3(v3f, s1) << endl;
130 normalize3(v3f);
131 cout << setw(40) << "normalize3(v3f): " << vectostr3(v3f, s1) << endl;
132 scale3(normalize3(v3f), 2.0);
133 cout << setw(40) << "scale(normalize3(v3f), 2.0): " << vectostr3(v3f, s1) << endl;
135 Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 };
136 cout << setw(40) << "v4d: " << vectostr4(v4d, s1) << endl;
137 normalize4(v4d);
138 cout << setw(40) << "normalize4(v4d): " << vectostr4(v4d, s1) << endl;
139 scale4(normalize4(v4d), 2.0);
140 cout << setw(40) << "scale4(normalize4(v4d), 2.0): " << vectostr4(v4d, s1) << endl;
142 }
144 }