view src/main.cpp @ 5:f6e6f3c8f7eb

Vectors done
author Eris Caffee <discordia@eldalin.com>
date Sun, 04 Sep 2011 12:46:08 -0500
parents f4e384b966b9
children 11e216148d1c
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::normalize*()
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 // Vector::cross()
145 {
146 cout << "===============================================================" << endl <<
147 "Testing Vector::cross()" << endl;
149 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 0.0f, 0.0f, 0.0f } };
150 cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl;
151 cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl;
152 cross(v3f[0], v3f[1], v3f[2]);
153 cout << setw(40) << "cross(v3f[0], v3f[1], v3f[2]): " << vectostr3(v3f[2], s1) << endl;
155 Vector3d v3d[3] = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 0.0, 0.0, 0.0 } };
156 cout << setw(40) << "v3d[0]: " << vectostr3(v3d[0], s1) << endl;
157 cout << setw(40) << "v3d[1]: " << vectostr3(v3d[1], s1) << endl;
158 cross(v3d[0], v3d[1], v3d[2]);
159 cout << setw(40) << "cross(v3d[0], v3d[1], v3d[2]): " << vectostr3(v3d[2], s1) << endl;
161 }
164 // Vector::cross()
165 {
166 cout << "===============================================================" << endl <<
167 "Testing Vector::get_angle*()" << endl;
169 Vector3i v3i[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
170 cout << setw(40) << "v3i[0]: " << vectostr3(v3i[0], s1) << endl;
171 cout << setw(40) << "v3i[1]: " << vectostr3(v3i[1], s1) << endl;
172 cout << setw(40) << "get_angle3(v3i[0], v3i[1]): " << get_angle3(v3i[0], v3i[1]) << endl;
174 Vector3f v3f[2] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
175 cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl;
176 cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl;
177 cout << setw(40) << "get_angle3(v3f[0], v3f[1]): " << get_angle3(v3f[0], v3f[1]) << endl;
178 normalize3(v3f[0]);
179 normalize3(v3f[1]);
180 cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl;
181 cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl;
182 cout << setw(40) << "get_angle3n(v3f[0], v3f[1]): " << get_angle3n(v3f[0], v3f[1]) << endl;
184 Vector3d v3d[2] = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 } };
185 cout << setw(40) << "v3d[0]: " << vectostr3(v3d[0], s1) << endl;
186 cout << setw(40) << "v3d[1]: " << vectostr3(v3d[1], s1) << endl;
187 cout << setw(40) << "get_angle3(v3d[0], v3d[1]): " << get_angle3(v3d[0], v3d[1]) << endl;
188 normalize3(v3d[0]);
189 normalize3(v3d[1]);
190 cout << setw(40) << "v3d[0]: " << vectostr3(v3d[0], s1) << endl;
191 cout << setw(40) << "v3d[1]: " << vectostr3(v3d[1], s1) << endl;
192 cout << setw(40) << "get_angle3n(v3d[0], v3d[1]): " << get_angle3n(v3d[0], v3d[1]) << endl;
193 }
195 // Vector::subtract*()
196 {
197 cout << "===============================================================" << endl <<
198 "Testing Vector::subtract*()" << endl;
200 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } };
201 Vector2i v2ires;
202 cout << setw(40) << "v2i[0]: " << vectostr2(v2i[0], s1) << endl;
203 cout << setw(40) << "v2i[1]: " << vectostr2(v2i[1], s1) << endl;
204 subtract2(v2i[0], v2i[1], v2ires);
205 cout << setw(40) << "subtract2(v2i[0], v2i[1], v2ires): " << vectostr2(v2ires, s1) << endl;
206 cout << setw(40) << "length2(subtract2(v2i[0], v2i[1], v2ires)): " << length2(subtract2(v2i[0], v2i[1], v2ires)) << endl;
208 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
209 Vector3f v3fres;
210 cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl;
211 cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl;
212 subtract3(v3f[0], v3f[1], v3fres);
213 cout << setw(40) << "subtract3(v3f[0], v3f[1], v3fres): " << vectostr3(v3fres, s1) << endl;
214 cout << setw(40) << "length3(subtract3(v3f[0], v3f[1], v3fres)): " << length3(subtract3(v3f[0], v3f[1], v3fres)) << endl;
216 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
217 Vector4d v4dres;
218 cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl;
219 cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl;
220 subtract4(v4d[0], v4d[1], v4dres);
221 cout << setw(40) << "subtract4(v4d[0], v4d[1], v4dres): " << vectostr4(v4dres, s1) << endl;
222 cout << setw(40) << "length4(subtract4(v4d[0], v4d[1], v4dres)): " << length4(subtract4(v4d[0], v4d[1], v4dres)) << endl;
224 }
226 // Vector::assign*()
227 {
228 cout << "===============================================================" << endl <<
229 "Testing Vector::assign*()" << endl;
231 Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } };
232 cout << setw(40) << "v2i[0]: " << vectostr2(v2i[0], s1) << endl;
233 cout << setw(40) << "v2i[1]: " << vectostr2(v2i[1], s1) << endl;
234 assign2(v2i[0], v2i[1]);
235 cout << setw(40) << "assign2(v2i[0], v2i[1]): " << vectostr2(v2i[0], s1) << endl;
237 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
238 cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl;
239 cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl;
240 assign3(v3f[0], v3f[1]);
241 cout << setw(40) << "assign3(v3f[0], v3f[1]): " << vectostr3(v3f[0], s1) << endl;
243 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
244 cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl;
245 cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl;
246 assign4(v4d[0], v4d[1]);
247 cout << setw(40) << "assign4(v4d[0], v4d[1]): " << vectostr4(v4d[0], s1) << endl;
249 }
251 // Vector::proj*()
252 {
253 cout << "===============================================================" << endl <<
254 "Testing Vector::proj*()" << endl;
256 Vector2f v2f[3] = { { 1.1f, 2.2f }, { 3.3f, 4.4f } };
257 Vector2f v2fres;
258 cout << setw(40) << "v2f[0]: " << vectostr2(v2f[0], s1) << endl;
259 cout << setw(40) << "v2f[1]: " << vectostr2(v2f[1], s1) << endl;
260 proj3(v2f[0], v2f[1], v2fres);
261 cout << setw(40) << "proj3(v2f[0], v2f[1], v2fres): " << vectostr2(v2fres, s1) << endl;
263 Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } };
264 Vector3f v3fres;
265 cout << setw(40) << "v3f[0]: " << vectostr3(v3f[0], s1) << endl;
266 cout << setw(40) << "v3f[1]: " << vectostr3(v3f[1], s1) << endl;
267 proj3(v3f[0], v3f[1], v3fres);
268 cout << setw(40) << "proj3(v3f[0], v3f[1], v3fres): " << vectostr3(v3fres, s1) << endl;
270 Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };
271 Vector4d v4dres;
272 cout << setw(40) << "v4d[0]: " << vectostr4(v4d[0], s1) << endl;
273 cout << setw(40) << "v4d[1]: " << vectostr4(v4d[1], s1) << endl;
274 proj4(v4d[0], v4d[1], v4dres);
275 cout << setw(40) << "proj4(v4d[0], v4d[1], v4dres): " << vectostr4(v4dres, s1) << endl;
277 }
278 }