summaryrefslogtreecommitdiffstats
path: root/core/math/vectors.hh
blob: 9b9e762f87a123f08984e547d06cbb4eb398d93b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include "core/math/concepts.hh"

// core/vectors.hh - because NO ONE would POSSIBLY
// need integer-based distance calculations in a
// game about voxels. That would be INSANE! :D

namespace math
{
template<math::Arithmetic T>
constexpr static inline const T length2(const glm::vec<2, T>& vector);
template<math::Arithmetic T>
constexpr static inline const T length2(const glm::vec<3, T>& vector);
template<math::Arithmetic T>
constexpr static inline const T distance2(const glm::vec<2, T>& vector_a, const glm::vec<2, T>& vector_b);
template<math::Arithmetic T>
constexpr static inline const T distance2(const glm::vec<3, T>& vector_a, const glm::vec<3, T>& vector_b);
} // namespace math

template<math::Arithmetic T>
constexpr static inline const T math::length2(const glm::vec<2, T>& vector)
{
    return (vector.x * vector.x) + (vector.y * vector.y);
}

template<math::Arithmetic T>
constexpr static inline const T math::length2(const glm::vec<3, T>& vector)
{
    return (vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z);
}

template<math::Arithmetic T>
constexpr static inline const T math::distance2(const glm::vec<2, T>& vector_a, const glm::vec<2, T>& vector_b)
{
    return math::length2(vector_a - vector_b);
}

template<math::Arithmetic T>
constexpr static inline const T math::distance2(const glm::vec<3, T>& vector_a, const glm::vec<3, T>& vector_b)
{
    return math::length2(vector_a - vector_b);
}