Skip to content

Commit

Permalink
checking number of components in Vector constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sevec committed Jul 23, 2020
1 parent 4ff932e commit 7911717
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
12 changes: 12 additions & 0 deletions Box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class BoundingBox {
}
};

using Box2f = BoundingBox<Vec2f>;
using Box3f = BoundingBox<Vec3f>;

/// \brief Splits the box along given coordinate.
Expand All @@ -82,5 +83,16 @@ std::pair<Box, Box> splitBox(const Box& box, const int dim, const T x) {
return std::make_pair(b1, b2);
}

template <typename Box>
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
17 changes: 6 additions & 11 deletions Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename TFirst, typename TSecond, typename... TRest>
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);
Expand Down Expand Up @@ -187,9 +184,7 @@ Vector<T, Dim> normalize(const Vector<T, Dim>& 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 <typename T1, typename T2, int Dim>
Expand Down

0 comments on commit 7911717

Please sign in to comment.