MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMinMaxArg.h
Go to the documentation of this file.
1#pragma once
2
3#include <limits>
4#include <utility>
5
6namespace MR
7{
10
11
14template<typename T, typename I>
15struct MinArg
16{
17 T val = std::numeric_limits<T>::max();
18 I arg;
19
20 auto asPair() const { return std::make_pair( val, arg ); }
21
23 void include( const std::pair<T,I>& p )
24 {
25 if ( p < asPair() )
26 {
27 val = p.first;
28 arg = p.second;
29 }
30 }
31
33 void include( T testVal, I testArg )
34 {
35 include( std::make_pair( testVal, testArg ) );
36 }
37
39 void include( const MinArg & s )
40 {
41 include( s.asPair() );
42 }
43};
44
47template<typename T, typename I>
48struct MaxArg
49{
50 T val = std::numeric_limits<T>::lowest();
51 I arg;
52
53 auto asPair() const { return std::make_pair( val, arg ); }
54
56 void include( const std::pair<T,I>& p )
57 {
58 if ( p > asPair() )
59 {
60 val = p.first;
61 arg = p.second;
62 }
63 }
64
66 void include( T testVal, I testArg )
67 {
68 include( std::make_pair( testVal, testArg ) );
69 }
70
72 void include( const MaxArg & s )
73 {
74 include( s.asPair() );
75 }
76};
77
80template<typename T, typename I>
82{
83 T min = std::numeric_limits<T>::max();
84 T max = std::numeric_limits<T>::lowest();
86
87 auto minPair() const { return std::make_pair( min, minArg ); }
88 auto maxPair() const { return std::make_pair( max, maxArg ); }
89
91 void include( const std::pair<T,I>& p )
92 {
93 if ( p < minPair() )
94 {
95 min = p.first;
96 minArg = p.second;
97 }
98 if ( p > maxPair() )
99 {
100 max = p.first;
101 maxArg = p.second;
102 }
103 }
104
106 void include( T v, I arg )
107 {
108 return include( std::make_pair( v, arg ) );
109 }
110
112 void include( const MinMaxArg & s )
113 {
115 if ( s.minPair() < minPair() )
116 {
117 min = s.min;
118 minArg = s.minArg;
119 }
120 if ( s.maxPair() > maxPair() )
121 {
122 max = s.max;
123 maxArg = s.maxArg;
124 }
125 }
126};
127
128}
auto maxPair() const
Definition MRMinMaxArg.h:88
T min
Definition MRMinMaxArg.h:83
void include(T v, I arg)
changes min(Arg) and max(Arg) if necessary to include given point
Definition MRMinMaxArg.h:106
auto asPair() const
Definition MRMinMaxArg.h:20
void include(const MinMaxArg &s)
changes min(Arg) and max(Arg) if necessary to include given segment
Definition MRMinMaxArg.h:112
auto minPair() const
Definition MRMinMaxArg.h:87
T val
Definition MRMinMaxArg.h:17
T max
Definition MRMinMaxArg.h:84
void include(T testVal, I testArg)
changes val and arg if given point is larger
Definition MRMinMaxArg.h:66
void include(const MinArg &s)
changes val and arg if given point is smaller
Definition MRMinMaxArg.h:39
I maxArg
Definition MRMinMaxArg.h:85
void include(const std::pair< T, I > &p)
changes val and arg if given point is smaller
Definition MRMinMaxArg.h:23
auto asPair() const
Definition MRMinMaxArg.h:53
I arg
Definition MRMinMaxArg.h:18
void include(const std::pair< T, I > &p)
changes val and arg if given point is larger
Definition MRMinMaxArg.h:56
void include(T testVal, I testArg)
changes val and arg if given point is smaller
Definition MRMinMaxArg.h:33
I minArg
Definition MRMinMaxArg.h:85
void include(const MaxArg &s)
changes val and arg if given point is larger
Definition MRMinMaxArg.h:72
T val
Definition MRMinMaxArg.h:50
I arg
Definition MRMinMaxArg.h:51
void include(const std::pair< T, I > &p)
changes min(Arg) and max(Arg) if necessary to include given point
Definition MRMinMaxArg.h:91
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMinMaxArg.h:49
Definition MRMinMaxArg.h:16
Definition MRMinMaxArg.h:82