summaryrefslogtreecommitdiffstats
path: root/test/vec_example.cpp
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-02-23 13:49:23 +0100
committerNao Pross <naopross@thearcway.org>2019-02-23 13:49:23 +0100
commitdd8035c87efec996164c1c0f5c78c790d72747d9 (patch)
tree7f512bc20f46b09ec85455c54c3a446a3d70fca0 /test/vec_example.cpp
parentFix typos and other minor errors (diff)
downloadlibmm-dd8035c87efec996164c1c0f5c78c790d72747d9.tar.gz
libmm-dd8035c87efec996164c1c0f5c78c790d72747d9.zip
Add test to cmake
Diffstat (limited to 'test/vec_example.cpp')
-rw-r--r--test/vec_example.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/vec_example.cpp b/test/vec_example.cpp
new file mode 100644
index 0000000..3a00f58
--- /dev/null
+++ b/test/vec_example.cpp
@@ -0,0 +1,62 @@
+#include "mmvec.hpp"
+
+#include <iostream>
+#include <complex>
+
+int main(int argc, char *argv[]) {
+ // N dimensional vectors
+ std::cout << "N dimensional (int) vectors" << std::endl;
+ mm::vec<int, 5> u {3, 2, 1, 0, 1};
+ mm::vec<int, 5> v {1, 2, 3, 4, 5};
+
+ std::cout << "u = " << u << std::endl;
+ std::cout << "v = " << v << std::endl;
+ std::cout << std::endl;
+
+ // basic operations
+ std::cout << "u + v = " << u + v << std::endl;
+ std::cout << "u - v = " << u - v << std::endl;
+ std::cout << "2 * v = " << 2 * v << std::endl;
+ std::cout << "v * 2 = " << v * 2 << std::endl;
+ std::cout << "u * v = " << u * v << std::endl;
+ std::cout << std::endl;
+
+ u += v;
+
+ // three dimensional vectors
+ std::cout << "three dimensional (double) vectors" << std::endl;
+
+ mm::vec3<double> a {1, 2, 3};
+ mm::vec3<double> b {3, 2, 1};
+
+ std::cout << "a = " << a << std::endl;
+ std::cout << "b = " << b << std::endl;
+ std::cout << std::endl;
+
+ std::cout << "a x b = " << mm::vec3<double>::cross(a, b) << std::endl;
+ std::cout << "zenith(a) = " << a.zenith() << std::endl;
+ std::cout << "azimuth(a) = " << a.azimuth() << std::endl;
+ std::cout << "spherical(a) = " << a.spherical() << std::endl;
+ std::cout << std::endl;
+
+ a -= b;
+
+ // two dimensional vector
+ std::cout << "two dimensional (complex) vectors" << std::endl;
+
+ mm::vec2<std::complex<float>> j {{1, 2}, {3, -1}};
+ mm::vec2<std::complex<float>> k { 5, {-2, 1}};
+
+ std::cout << "j = " << j << std::endl;
+ std::cout << "k = " << k << std::endl;
+ std::cout << std::endl;
+
+ std::cout << "j x k = " << mm::vec2<std::complex<float>>::cross(j, k) << std::endl;
+ std::cout << "angle(j) = " << j.angle() << std::endl;
+ std::cout << "polar(j) = " << j.polar() << std::endl;
+ std::cout << std::endl;
+
+ j *= 10;
+
+ return 0;
+}