- just some support functions for the Vector class master
authorAkiko <akiko@linux-addicted.net>
Mon, 28 Oct 2013 13:37:13 +0000 (14:37 +0100)
committerAkiko <akiko@linux-addicted.net>
Mon, 28 Oct 2013 13:37:13 +0000 (14:37 +0100)
engine/Object.hxx
engine/VectorUtils.hxx [new file with mode: 0644]

index f7f7dcf..cdbe56b 100644 (file)
@@ -8,6 +8,7 @@ enum class ObjectType : uint8_t {
     None,
     Camera,
     Plane,
+    AABox,
     Sphere,
     Mesh
 };
diff --git a/engine/VectorUtils.hxx b/engine/VectorUtils.hxx
new file mode 100644 (file)
index 0000000..9237915
--- /dev/null
@@ -0,0 +1,83 @@
+#pragma once
+
+#include <algorithm>
+#include "Vector.hxx"
+
+namespace std
+{
+    // --- minimum ---
+
+    template <typename T>
+    Vector2<T> min(const Vector2<T>& vec1, const Vector2<T>& vec2)
+    {
+        return {std::min(vec1.x, vec2.x), std::min(vec1.y, vec2.y)};
+    }
+
+    template <typename T>
+    Vector2<T> min(const Vector2<T>& vec1, const Vector2<T>& vec2, const Vector2<T>& vec3)
+    {
+        return std::min(std::min(vec1, vec2), std::min(vec2, vec3));
+    }
+
+    template <typename T>
+    Vector3<T> min(const Vector3<T>& vec1, const Vector3<T>& vec2)
+    {
+        return {std::min(vec1.x, vec2.x), std::min(vec1.y, vec2.y), std::min(vec1.z, vec2.z)};
+    }
+
+    template <typename T>
+    Vector3<T> min(const Vector3<T>& vec1, const Vector3<T>& vec2, const Vector3<T>& vec3)
+    {
+        return std::min(std::min(vec1, vec2), std::min(vec2, vec3));
+    }
+
+    template <typename T>
+    Vector4<T> min(const Vector4<T>& vec1, const Vector4<T>& vec2)
+    {
+        return {std::min(vec1.x, vec2.x), std::min(vec1.y, vec2.y), std::min(vec1.z, vec2.z), std::min(vec1.w, vec2.w)};
+    }
+
+    template <typename T>
+    Vector4<T> min(const Vector4<T>& vec1, const Vector4<T>& vec2, const Vector4<T>& vec3)
+    {
+        return std::min(std::min(vec1, vec2), std::min(vec2, vec3));
+    }
+
+    // --- maximum ---
+
+    template <typename T>
+    Vector2<T> max(const Vector2<T>& vec1, const Vector2<T>& vec2)
+    {
+        return {std::max(vec1.x, vec2.x), std::max(vec1.y, vec2.y)};
+    }
+
+    template <typename T>
+    Vector2<T> max(const Vector2<T>& vec1, const Vector2<T>& vec2, const Vector2<T>& vec3)
+    {
+        return std::max(std::max(vec1, vec2), std::max(vec2, vec3));
+    }
+
+    template <typename T>
+    Vector3<T> max(const Vector3<T>& vec1, const Vector3<T>& vec3)
+    {
+        return {std::max(vec1.x, vec2.y), std::max(vec1.y, vec2.y), std::max(vec1.z, vec2.z)};
+    }
+
+    template <typename T>
+    Vector3<T> max(const Vector3<T>& vec1, const Vector3<T>& vec2, const Vector3<T>& vec3)
+    {
+        return std::max(std::max(vec1, vec2), std::max(vec2, vec3));
+    }
+
+    template <typename T>
+    Vector4<T> max(const Vector4<T>& vec1, const Vector4<T>& vec2)
+    {
+        return {std::max(vec1.x, vec2.x), std::max(vec1.y, vec2.y), std::max(vec1.z, vec2.z), std::max(vec1.w, vec2.w)};
+    }
+
+    template <typename T>
+    Vector4<T> max(const Vector4<T>& vec1, const Vector4<T>& vec2, const Vector4<T>& vec3)
+    {
+        return std::max(std::max(vec1, vec2), std::max(vec2, vec3));
+    }
+}