HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
transform.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "matrix.hpp"
8#include "identity.hpp"
9#include "translate.hpp"
10#include "rotate.hpp"
11#include "scale.hpp"
12#include "perspective.hpp"
13#include <type_traits>
14
15namespace hi::inline v1 { namespace geo {
16
17template<int D>
18[[nodiscard]] constexpr matrix<D> operator*(identity const &lhs, matrix<D> const &rhs) noexcept
19{
20 return rhs;
21}
22
23template<typename T, int D>
24[[nodiscard]] constexpr translate<T, D> operator*(identity const &lhs, translate<T, D> const &rhs) noexcept
25{
26 return rhs;
27}
28
29template<int D>
30[[nodiscard]] constexpr scale<D> operator*(identity const &lhs, scale<D> const &rhs) noexcept
31{
32 return rhs;
33}
34
35template<int D>
36[[nodiscard]] constexpr rotate<D> operator*(identity const &lhs, rotate<D> const &rhs) noexcept
37{
38 return rhs;
39}
40
41template<int D, int E>
42[[nodiscard]] constexpr auto operator*(translate<float, D> const &lhs, scale<E> const &rhs) noexcept
43{
44 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
45 return matrix<std::max(D, E)>{
46 static_cast<f32x4>(rhs).x000(),
47 static_cast<f32x4>(rhs)._0y00(),
48 static_cast<f32x4>(rhs)._00z0(),
49 static_cast<f32x4>(lhs).xyz1()};
50}
51
52template<int D, int E>
53[[nodiscard]] constexpr auto operator*(scale<D> const &lhs, translate<float, E> const &rhs) noexcept
54{
55 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
56 return matrix<std::max(D, E)>{
57 static_cast<f32x4>(lhs).x000(),
58 static_cast<f32x4>(lhs)._0y00(),
59 static_cast<f32x4>(lhs)._00z0(),
60 static_cast<f32x4>(lhs) * static_cast<f32x4>(rhs).xyz1()};
61}
62
63template<typename T>
64struct transform : public std::false_type {
65};
66
67// clang-format off
68template<> struct transform<matrix<2>> : public std::true_type {};
69template<> struct transform<matrix<3>> : public std::true_type {};
70template<> struct transform<identity> : public std::true_type {};
71template<> struct transform<translate<float, 2>> : public std::true_type {};
72template<> struct transform<translate<float, 3>> : public std::true_type {};
73template<> struct transform<rotate<2>> : public std::true_type {};
74template<> struct transform<rotate<3>> : public std::true_type {};
75template<> struct transform<scale<2>> : public std::true_type {};
76template<> struct transform<scale<3>> : public std::true_type {};
77template<> struct transform<perspective> : public std::true_type {};
78// clang-format on
79
80template<typename T>
81constexpr bool transform_v = transform<T>::value;
82
83template<typename T>
84concept transformer = transform_v<T>;
85
86}} // namespace hi::inline v1::geo
Defines identity type.
Defines geo::matrix, matrix2 and matrix3.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
DOXYGEN BUG.
Definition algorithm.hpp:13
Definition rotate.hpp:14
Definition scale.hpp:16
Definition transform.hpp:64
Definition translate.hpp:15
Definition transform.hpp:84
T max(T... args)