MeshLib Documentation
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 template <typename U = ImVec2> // Adding a template parameter to avoid including the whole `imgui.h`.
30 static constexpr U diagonal( float v ) { return U( v, v ); }
31};
32
33template <>
34struct VectorTraits<ImVec4>
35{
36 using BaseType = float;
37 static constexpr int size = 4;
38
39 // Can't change the element type...
40 template <std::same_as<float>>
41 using ChangeBaseType = ImVec4;
42
43 template <typename U>
44 [[nodiscard]] static auto&& getElem( int i, U&& value )
45 {
46 // Technically UB, but helps with optimizations on MSVC for some reason, compared to an if-else chain.
47 // GCC and Clang optimize both in the same manner.
48 return ( &value.x )[i];
49 }
50
51 template <typename U = ImVec4> // Adding a template parameter to avoid including the whole `imgui.h`.
52 static constexpr U diagonal( float v ) { return U( v, v, v, v ); }
53};
54
55}
Definition MRCameraOrientationPlugin.h:8
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 constexpr U diagonal(float v)
Definition MRViewer/MRVectorTraits.h:30
static auto && getElem(int i, U &&value)
Definition MRViewer/MRVectorTraits.h:44
float BaseType
Definition MRViewer/MRVectorTraits.h:36
ImVec4 ChangeBaseType
Definition MRViewer/MRVectorTraits.h:41
static constexpr U diagonal(float v)
Definition MRViewer/MRVectorTraits.h:52
Definition MRMesh/MRVectorTraits.h:14
static constexpr int size
Definition MRMesh/MRVectorTraits.h:18