MeshLib C++ Docs
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
14namespace std
15{
16
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> {};
62
63template<typename T>
64struct tuple_size<MR::Matrix3<T>> : integral_constant<size_t, MR::Matrix3<T>::VectorType::elements> {};
65
66template<typename T>
67struct tuple_size<MR::Matrix4<T>> : integral_constant<size_t, MR::Matrix4<T>::VectorType::elements> {};
68
69template<typename V>
70struct tuple_size<MR::AffineXf<V>> : integral_constant<size_t, 2> {};
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
79
80}
81
82namespace MR
83{
84
87
88template<size_t I, typename T>
89constexpr const T& get( const Vector2<T>& v ) noexcept { return v[int( I )]; }
90
91template<size_t I, typename T>
92constexpr T& get( Vector2<T>& v ) noexcept { return v[int( I )]; }
93
94template<size_t I, typename T>
95constexpr const T& get( const Vector3<T>& v ) noexcept { return v[int( I )]; }
96
97template<size_t I, typename T>
98constexpr T& get( Vector3<T>& v ) noexcept { return v[int( I )]; }
99
100template<size_t I, typename T>
101constexpr const T& get( const Vector4<T>& v ) noexcept { return v[int( I )]; }
102
103template<size_t I, typename T>
104constexpr T& get( Vector4<T>& v ) noexcept { return v[int( I )]; }
105
106template<size_t I, typename T>
107constexpr const typename Matrix2<T>::VectorType& get( const Matrix2<T>& m ) noexcept { return m[int( I )]; }
108
109template<size_t I, typename T>
110constexpr typename Matrix2<T>::VectorType& get( Matrix2<T>& m ) noexcept { return m[int( I )]; }
111
112template<size_t I, typename T>
113constexpr const typename Matrix3<T>::VectorType& get( const Matrix3<T>& m ) noexcept { return m[int( I )]; }
114
115template<size_t I, typename T>
116constexpr typename Matrix3<T>::VectorType& get( Matrix3<T>& m ) noexcept { return m[int( I )]; }
117
118template<size_t I, typename T>
119constexpr const typename Matrix4<T>::VectorType& get( const Matrix4<T>& m ) noexcept { return m[int( I )]; }
120
121template<size_t I, typename T>
122constexpr typename Matrix4<T>::VectorType& get( Matrix4<T>& m ) noexcept { return m[int( I )]; }
123
124template<size_t I, typename V>
125constexpr const typename std::tuple_element<I, AffineXf<V>>::type& get( const AffineXf<V>& m ) noexcept
126{
127 if constexpr ( I == 0 )
128 return m.A;
129 else
130 return m.b;
131}
132
133template<size_t I, typename V>
134constexpr typename std::tuple_element<I, AffineXf<V>>::type& get( AffineXf<V>& m ) noexcept
135{
136 if constexpr ( I == 0 )
137 return m.A;
138 else
139 return m.b;
140}
141
142template <size_t I, typename T>
143constexpr int get( const MR::Id<T> & id ) noexcept
144{
145 static_assert( I == 0 );
146 return (int)id;
147}
148
149template <size_t I, typename T>
150constexpr int & get( MR::Id<T>& id ) noexcept
151{
152 static_assert( I == 0 );
153 return id.get();
154}
155
156template<size_t I>
157constexpr const uint8_t& get( const Color& c ) noexcept
158{
159 static_assert( I < 4 );
160 return c[int( I )];
161}
162
163template<size_t I>
164constexpr uint8_t& get( Color& c ) noexcept
165{
166 static_assert( I < 4 );
167 return c[int( I )];
168}
169
171
172}
stores index of some element, it is made as template class to avoid mixing faces, edges and vertices
Definition MRId.h:19
constexpr const V & get(const Box< V > &box) noexcept
get<0> returns min, get<1> returns max
Definition MRBox.h:400
Vector4< T > VectorType
Definition MRMatrix4.h:27
T ValueType
Definition MRVector4.h:27
Vector3< T > VectorType
Definition MRMatrix3.h:26
Vector4
Definition MRMeshFwd.h:229
Matrix4
Definition MRMeshFwd.h:262
Vector2< T > VectorType
Definition MRMatrix2.h:26
class MRMESH_CLASS I
Definition MRMeshFwd.h:137
MRMESH_CLASS Vector2
Definition MRMeshFwd.h:204
T ValueType
Definition MRVector3.h:34
Matrix3
Definition MRMeshFwd.h:251
Matrix2
Definition MRMeshFwd.h:240
AffineXf
Definition MRMeshFwd.h:306
class MRMESH_CLASS Id(EdgeId, Id< EdgeTag >)(UndirectedEdgeId
MRMESH_CLASS Vector3
Definition MRMeshFwd.h:218
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRAffineXf.h:26
Definition MRColor.h:12
Definition MRMatrix2.h:24
Definition MRMatrix3.h:24
Definition MRMatrix4.h:25
Definition MRVector2.h:29
T ValueType
Definition MRVector2.h:30
Definition MRVector3.h:33
Definition MRVector4.h:26