MeshLib Documentation
Loading...
Searching...
No Matches
MRTupleBindings.h
Go to the documentation of this file.
1#pragma once
2#include "MRVector2.h"
3#include "MRVector3.h"
4#include "MRVector4.h"
5#include "MRMatrix2.h"
6#include "MRMatrix3.h"
7#include "MRMatrix4.h"
8#include "MRAffineXf.h"
9#include "MRId.h"
10#include "MRColor.h"
11
12#include <type_traits>
13
17
18namespace std
19{
20
21template<size_t I, typename T>
22struct tuple_element<I, MR::Vector2<T>> { using type = typename MR::Vector2<T>::ValueType; };
23
24template<size_t I, typename T>
25struct tuple_element<I, MR::Vector3<T>> { using type = typename MR::Vector3<T>::ValueType; };
26
27template<size_t I, typename T>
28struct tuple_element<I, MR::Vector4<T>> { using type = typename MR::Vector4<T>::ValueType; };
29
30template<size_t I, typename T>
31struct tuple_element<I, MR::Matrix2<T>> { using type = typename MR::Matrix2<T>::VectorType; };
32
33template<size_t I, typename T>
34struct tuple_element<I, MR::Matrix3<T>> { using type = typename MR::Matrix3<T>::VectorType; };
35
36template<size_t I, typename T>
37struct tuple_element<I, MR::Matrix4<T>> { using type = typename MR::Matrix4<T>::VectorType; };
38
39template<typename V>
40struct tuple_element<0, MR::AffineXf<V>> { using type = typename V::MatrixType; };
41
42template<typename V>
43struct tuple_element<1, MR::AffineXf<V>> { using type = V; };
44
45template <typename T>
46struct tuple_element<0, MR::Id<T>> { using type = int; };
47
48template<size_t I>
49struct tuple_element<I, MR::Color> { using type = uint8_t; };
50
51template<typename T>
52struct tuple_size<MR::Vector2<T>> : integral_constant<size_t, MR::Vector2<T>::elements> {};
53
54template<typename T>
55struct tuple_size<MR::Vector3<T>> : integral_constant<size_t, MR::Vector3<T>::elements> {};
56
57template<typename T>
58struct tuple_size<MR::Vector4<T>> : integral_constant<size_t, MR::Vector4<T>::elements> {};
59
60template<typename T>
61struct tuple_size<MR::Matrix2<T>> : integral_constant<size_t, MR::Matrix2<T>::VectorType::elements> {}; // as far as matrix as square num vector elements is equal to num vectors
62
63template<typename T>
64struct tuple_size<MR::Matrix3<T>> : integral_constant<size_t, MR::Matrix3<T>::VectorType::elements> {}; // as far as matrix as square num vector elements is equal to num vectors
65
66template<typename T>
67struct tuple_size<MR::Matrix4<T>> : integral_constant<size_t, MR::Matrix4<T>::VectorType::elements> {}; // as far as matrix as square num vector elements is equal to num vectors
68
69template<typename V>
70struct tuple_size<MR::AffineXf<V>> : integral_constant<size_t, 2> {}; // 2 here - matrix and translation
71
72template <typename T>
73struct tuple_size<MR::Id<T>> : integral_constant<size_t, 1> {};
74
75template <>
76struct tuple_size<MR::Color> : integral_constant<size_t, 4> {};
77}
78
79namespace MR
80{
81
82template<size_t I, typename T>
83constexpr const T& get( const Vector2<T>& v ) noexcept { return v[int( I )]; }
84
85template<size_t I, typename T>
86constexpr T& get( Vector2<T>& v ) noexcept { return v[int( I )]; }
87
88template<size_t I, typename T>
89constexpr const T& get( const Vector3<T>& v ) noexcept { return v[int( I )]; }
90
91template<size_t I, typename T>
92constexpr T& get( Vector3<T>& v ) noexcept { return v[int( I )]; }
93
94template<size_t I, typename T>
95constexpr const T& get( const Vector4<T>& v ) noexcept { return v[int( I )]; }
96
97template<size_t I, typename T>
98constexpr T& get( Vector4<T>& v ) noexcept { return v[int( I )]; }
99
100template<size_t I, typename T>
101constexpr const typename Matrix2<T>::VectorType& get( const Matrix2<T>& m ) noexcept { return m[int( I )]; }
102
103template<size_t I, typename T>
104constexpr typename Matrix2<T>::VectorType& get( Matrix2<T>& m ) noexcept { return m[int( I )]; }
105
106template<size_t I, typename T>
107constexpr const typename Matrix3<T>::VectorType& get( const Matrix3<T>& m ) noexcept { return m[int( I )]; }
108
109template<size_t I, typename T>
110constexpr typename Matrix3<T>::VectorType& get( Matrix3<T>& m ) noexcept { return m[int( I )]; }
111
112template<size_t I, typename T>
113constexpr const typename Matrix4<T>::VectorType& get( const Matrix4<T>& m ) noexcept { return m[int( I )]; }
114
115template<size_t I, typename T>
116constexpr typename Matrix4<T>::VectorType& get( Matrix4<T>& m ) noexcept { return m[int( I )]; }
117
118template<size_t I, typename V>
119constexpr const typename std::tuple_element<I, AffineXf<V>>::type& get( const AffineXf<V>& m ) noexcept
120{
121 if constexpr ( I == 0 )
122 return m.A;
123 else
124 return m.b;
125}
126
127template<size_t I, typename V>
128constexpr typename std::tuple_element<I, AffineXf<V>>::type& get( AffineXf<V>& m ) noexcept
129{
130 if constexpr ( I == 0 )
131 return m.A;
132 else
133 return m.b;
134}
135
136template <size_t I, typename T>
137constexpr int get( const MR::Id<T> & id ) noexcept
138{
139 static_assert( I == 0 );
140 return (int)id;
141}
142
143template <size_t I, typename T>
144constexpr int & get( MR::Id<T>& id ) noexcept
145{
146 static_assert( I == 0 );
147 return id.get();
148}
149
150template<size_t I>
151constexpr const uint8_t& get( const Color& c ) noexcept
152{
153 static_assert( I < 4 );
154 return c[int( I )];
155}
156
157template<size_t I>
158constexpr uint8_t& get( Color& c ) noexcept
159{
160 static_assert( I < 4 );
161 return c[int( I )];
162}
163
164
165} // namespace MR
166
Definition MRMesh/MRId.h:13
constexpr const V & get(const Box< V > &box) noexcept
get<0> returns min, get<1> returns max
Definition MRMesh/MRBox.h:268
Definition MRCameraOrientationPlugin.h:8
MRMESH_CLASS Vector3< double > Matrix2
Definition MRMesh/MRMeshFwd.h:153
MRMESH_CLASS Vector3< double > Matrix2< double > Matrix4
Definition MRMesh/MRMeshFwd.h:169
I
Definition MRMesh/MRMeshFwd.h:88
MRMESH_CLASS Vector3< double > Matrix2< double > Matrix4< double > SymMatrix3< double > AffineXf
Definition MRMesh/MRMeshFwd.h:201
MRMESH_CLASS Vector3
Definition MRMesh/MRMeshFwd.h:137
Definition MRMesh/MRAffineXf.h:14
Definition MRColor.h:9
Definition MRMatrix2.h:13
Definition MRMesh/MRMatrix3.h:13
Definition MRMatrix4.h:14
Definition MRVector2.h:18
T ValueType
Definition MRVector2.h:19
Definition MRMesh/MRVector3.h:19
T ValueType
Definition MRMesh/MRVector3.h:20
Definition MRVector4.h:13
T ValueType
Definition MRVector4.h:14