summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-12-10 15:28:28 +0100
committerNao Pross <naopross@thearcway.org>2018-12-10 15:28:28 +0100
commitb94064dec5c39f30cbf3ecad668f8e51cebcee7d (patch)
tree4c29159d92aa5f01eaa89d7693b3cf8c76d28242
parentUpdate makefile ad update basic_vec to allow abstract algebraic structures (diff)
downloadcplusplus-b94064dec5c39f30cbf3ecad668f8e51cebcee7d.tar.gz
cplusplus-b94064dec5c39f30cbf3ecad668f8e51cebcee7d.zip
Implement vec2<T>::polar() former vec2<T>::angle()
-rw-r--r--vector/vector.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/vector/vector.cpp b/vector/vector.cpp
index d5f0c36..8057cdd 100644
--- a/vector/vector.cpp
+++ b/vector/vector.cpp
@@ -1,10 +1,11 @@
#include <iostream>
-#include <iterator>
#include <cassert>
+#include <cmath>
+
#include <array>
-#include <initializer_list>
#include <algorithm>
+#include <initializer_list>
template<typename T, std::size_t d>
@@ -146,11 +147,16 @@ public:
template<std::size_t n>
vec2(const basic_vec<T, n>& other) : basic_vec<T, 2>(other) {}
- T angle();
+ T polar();
static vec3<T> cross(const vec2<T>& rhs, const vec2<T>& lhs);
};
template<typename T>
+T vec2<T>::polar() {
+ return std::atan2(this->at(0), this->at(1));
+}
+
+template<typename T>
vec3<T> vec2<T>::cross(const vec2<T>& rhs, const vec2<T>& lhs) {
return vec3<T>::cross(vec3<T>(rhs), vec3<T>(lhs));
}