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 <type_traits>
13
14namespace tt {
15namespace 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<int D>
24[[nodiscard]] constexpr translate<D> operator*(identity const &lhs, translate<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<D> const &lhs, scale<E> const &rhs) noexcept
43{
44 tt_axiom(lhs.is_valid() && rhs.is_valid());
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<E> const &rhs) noexcept
54{
55 tt_axiom(lhs.is_valid() && rhs.is_valid());
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<2>> : public std::true_type {};
72template<> struct transform<translate<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 {};
77// clang-format on
78
79template<typename T>
80constexpr bool transform_v = transform<T>::value;
81
82template<typename T>
83concept transformer = transform_v<T>;
84
85} // namespace geo
86
87} // namespace tt
Definition identity.hpp:11
Definition matrix.hpp:18
Definition rotate.hpp:14
Definition scale.hpp:15
Definition transform.hpp:64
Definition translate.hpp:14
Definition transform.hpp:83
T max(T... args)