cross.hh 731 Bytes
Newer Older
Philip Trettner's avatar
Philip Trettner committed
1
2
3
#pragma once

#include "../../types/vec.hh"
4
#include "../scalar_traits.hh"
Philip Trettner's avatar
Philip Trettner committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

namespace tg
{
template <class ScalarT>
constexpr vec<3, squared_result<ScalarT>> cross(vec<3, ScalarT> const& a, vec<3, ScalarT> const& b)
{
    vec<3, ScalarT> r;
    r.x = a.y * squared_result<ScalarT>(b.z) - a.z * squared_result<ScalarT>(b.y);
    r.y = a.z * squared_result<ScalarT>(b.x) - a.x * squared_result<ScalarT>(b.z);
    r.z = a.x * squared_result<ScalarT>(b.y) - a.y * squared_result<ScalarT>(b.x);
    return r;
}

template <class ScalarT>
constexpr squared_result<ScalarT> cross(vec<2, ScalarT> const& a, vec<2, ScalarT> const& b)
{
    return a.x * squared_result<ScalarT>(b.y) - a.y * squared_result<ScalarT>(b.x);
}

} // namespace tg