MeshLib
 
Loading...
Searching...
No Matches
MRViewer/MRVectorTraits.h
Go to the documentation of this file.
1#pragma once
2
4
5struct ImVec2;
6struct ImVec4;
7
8namespace MR
9{
10
11template <>
12struct VectorTraits<ImVec2>
13{
14 using BaseType = float;
15 static constexpr int size = 2;
16
17 // Can't change the element type...
18 template <std::same_as<float>>
19 using ChangeBaseType = ImVec2;
20
21 template <typename U>
22 [[nodiscard]] static auto&& getElem( int i, U&& value )
23 {
24 // Technically UB, but helps with optimizations on MSVC for some reason, compared to an if-else chain.
25 // GCC and Clang optimize both in the same manner.
26 return ( &value.x )[i];
27 }
28};
29
30template <>
31struct VectorTraits<ImVec4>
32{
33 using BaseType = float;
34 static constexpr int size = 4;
35
36 // Can't change the element type...
37 template <std::same_as<float>>
38 using ChangeBaseType = ImVec4;
39
40 template <typename U>
41 [[nodiscard]] static auto&& getElem( int i, U&& value )
42 {
43 // Technically UB, but helps with optimizations on MSVC for some reason, compared to an if-else chain.
44 // GCC and Clang optimize both in the same manner.
45 return ( &value.x )[i];
46 }
47};
48
49}
Definition MRCameraOrientationPlugin.h:7
ImVec2 ChangeBaseType
Definition MRViewer/MRVectorTraits.h:19
static auto && getElem(int i, U &&value)
Definition MRViewer/MRVectorTraits.h:22
float BaseType
Definition MRViewer/MRVectorTraits.h:14
static auto && getElem(int i, U &&value)
Definition MRViewer/MRVectorTraits.h:41
float BaseType
Definition MRViewer/MRVectorTraits.h:33
ImVec4 ChangeBaseType
Definition MRViewer/MRVectorTraits.h:38
Definition MRMesh/MRVectorTraits.h:14
static constexpr int size
Definition MRMesh/MRVectorTraits.h:18