diff --git a/Box.hpp b/Box.hpp index 0a99a33..87646f0 100644 --- a/Box.hpp +++ b/Box.hpp @@ -65,6 +65,7 @@ class BoundingBox { } }; +using Box2f = BoundingBox; using Box3f = BoundingBox; /// \brief Splits the box along given coordinate. @@ -82,5 +83,16 @@ std::pair splitBox(const Box& box, const int dim, const T x) { return std::make_pair(b1, b2); } +template +bool overlaps(const Box& box1, const Box& box2) { + constexpr int Dim = Box::Vector::size(); + for (int i = 0; i < Dim; ++i) { + if (box1.lower()[i] > box2.upper()[i] || box2.lower()[i] > box1.upper()[i]) { + return false; + } + } + return true; +} + } // namespace Pvl diff --git a/Vector.hpp b/Vector.hpp index 34d2d2c..9f027b1 100644 --- a/Vector.hpp +++ b/Vector.hpp @@ -21,14 +21,11 @@ class Vector { } } - Vector(const T x, const T y) /// \todo - : values_{ x, y } {} - - Vector(const T x, const T y, const T z) - : values_{ x, y, z } {} - - Vector(const T x, const T y, const T z, const T w) - : values_{ x, y, z, w } {} + template + Vector(const TFirst first, const TSecond second, const TRest... rest) + : values_{ T(first), T(second), T(rest)... } { + static_assert(sizeof...(TRest) == Dim - 2, "Incorrect number of vector components"); + } T& operator[](const int idx) { PVL_ASSERT(unsigned(idx) < unsigned(Dim), idx, Dim); @@ -187,9 +184,7 @@ Vector normalize(const Vector& v) { } inline Vec3f crossProd(const Vec3f& v1, const Vec3f& v2) { - return Vec3f(v1[1] * v2[2] - v1[2] * v2[1], - v1[2] * v2[0] - v1[0] * v2[2], - v1[0] * v2[1] - v1[1] * v2[0]); + return Vec3f(v1[1] * v2[2] - v1[2] * v2[1], v1[2] * v2[0] - v1[0] * v2[2], v1[0] * v2[1] - v1[1] * v2[0]); } template