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::geo {
15
16template<int D>
17[[nodiscard]] constexpr matrix<D> operator*(identity const &lhs, matrix<D> const &rhs) noexcept
18{
19 return rhs;
20}
21
22template<int D>
23[[nodiscard]] constexpr translate<D> operator*(identity const &lhs, translate<D> const &rhs) noexcept
24{
25 return rhs;
26}
27
28template<int D>
29[[nodiscard]] constexpr scale<D> operator*(identity const &lhs, scale<D> const &rhs) noexcept
30{
31 return rhs;
32}
33
34template<int D>
35[[nodiscard]] constexpr rotate<D> operator*(identity const &lhs, rotate<D> const &rhs) noexcept
36{
37 return rhs;
38}
39
40template<int D, int E>
41[[nodiscard]] constexpr auto operator*(translate<D> const &lhs, scale<E> const &rhs) noexcept
42{
43 tt_axiom(lhs.is_valid() && rhs.is_valid());
44 return matrix<std::max(D, E)>{
45 static_cast<f32x4>(rhs).x000(),
46 static_cast<f32x4>(rhs)._0y00(),
47 static_cast<f32x4>(rhs)._00z0(),
48 static_cast<f32x4>(lhs).xyz1()};
49}
50
51template<int D, int E>
52[[nodiscard]] constexpr auto operator*(scale<D> const &lhs, translate<E> const &rhs) noexcept
53{
54 tt_axiom(lhs.is_valid() && rhs.is_valid());
55 return matrix<std::max(D, E)>{
56 static_cast<f32x4>(lhs).x000(),
57 static_cast<f32x4>(lhs)._0y00(),
58 static_cast<f32x4>(lhs)._00z0(),
59 static_cast<f32x4>(lhs) * static_cast<f32x4>(rhs).xyz1()};
60}
61
62template<typename T, int D>
63struct transform : public std::false_type {
64};
65
66template<int D>
67struct transform<matrix<D>, D> : public std::true_type {
68};
69
70template<int D>
71struct transform<translate<D>, D> : public std::true_type {
72};
73
74template<int D>
75struct transform<rotate<D>, D> : public std::true_type {
76};
77
78template<int D>
79struct transform<scale<D>, D> : public std::true_type {
80};
81
82template<typename T, int D>
83constexpr bool transform_v = transform<T, D>::value;
84
85template<typename T, int D>
86concept transformer = transform_v<T, D>;
87
88} // namespace tt
Definition matrix.hpp:18
Definition rotate.hpp:14
Definition scale.hpp:15
Definition transform.hpp:63
Definition translate.hpp:14
Definition transform.hpp:86
T max(T... args)