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{
8
11template<typename T, typename I>
12struct MinArg
13{
14 T val = std::numeric_limits<T>::max();
15 I arg;
16
17 auto asPair() const { return std::make_pair( val, arg ); }
18
20 void include( const std::pair<T,I>& p )
21 {
22 if ( p < asPair() )
23 {
24 val = p.first;
25 arg = p.second;
26 }
27 }
28
30 void include( T testVal, I testArg )
31 {
32 include( std::make_pair( testVal, testArg ) );
33 }
34
36 void include( const MinArg & s )
37 {
38 include( s.asPair() );
39 }
40};
41
44template<typename T, typename I>
45struct MaxArg
46{
47 T val = std::numeric_limits<T>::lowest();
48 I arg;
49
50 auto asPair() const { return std::make_pair( val, arg ); }
51
53 void include( const std::pair<T,I>& p )
54 {
55 if ( p > asPair() )
56 {
57 val = p.first;
58 arg = p.second;
59 }
60 }
61
63 void include( T testVal, I testArg )
64 {
65 include( std::make_pair( testVal, testArg ) );
66 }
67
69 void include( const MaxArg & s )
70 {
71 include( s.asPair() );
72 }
73};
74
77template<typename T, typename I>
79{
80 T min = std::numeric_limits<T>::max();
81 T max = std::numeric_limits<T>::lowest();
83
84 auto minPair() const { return std::make_pair( min, minArg ); }
85 auto maxPair() const { return std::make_pair( max, maxArg ); }
86
88 void include( const std::pair<T,I>& p )
89 {
90 if ( p < minPair() )
91 {
92 min = p.first;
93 minArg = p.second;
94 }
95 if ( p > maxPair() )
96 {
97 max = p.first;
98 maxArg = p.second;
99 }
100 }
101
103 void include( T v, I arg )
104 {
105 return include( std::make_pair( v, arg ) );
106 }
107
109 void include( const MinMaxArg & s )
110 {
111 // it shall work with default initialized this and s
112 if ( s.minPair() < minPair() )
113 {
114 min = s.min;
115 minArg = s.minArg;
116 }
117 if ( s.maxPair() > maxPair() )
118 {
119 max = s.max;
120 maxArg = s.maxArg;
121 }
122 }
123};
124
125} //namespace MR
Definition MRCameraOrientationPlugin.h:8
Definition MRMinMaxArg.h:46
void include(T testVal, I testArg)
changes val and arg if given point is larger
Definition MRMinMaxArg.h:63
auto asPair() const
Definition MRMinMaxArg.h:50
void include(const std::pair< T, I > &p)
changes val and arg if given point is larger
Definition MRMinMaxArg.h:53
void include(const MaxArg &s)
changes val and arg if given point is larger
Definition MRMinMaxArg.h:69
T val
Definition MRMinMaxArg.h:47
I arg
Definition MRMinMaxArg.h:48
Definition MRMinMaxArg.h:13
auto asPair() const
Definition MRMinMaxArg.h:17
T val
Definition MRMinMaxArg.h:14
void include(const MinArg &s)
changes val and arg if given point is smaller
Definition MRMinMaxArg.h:36
void include(const std::pair< T, I > &p)
changes val and arg if given point is smaller
Definition MRMinMaxArg.h:20
I arg
Definition MRMinMaxArg.h:15
void include(T testVal, I testArg)
changes val and arg if given point is smaller
Definition MRMinMaxArg.h:30
Definition MRMinMaxArg.h:79
auto maxPair() const
Definition MRMinMaxArg.h:85
T min
Definition MRMinMaxArg.h:80
void include(T v, I arg)
changes min(Arg) and max(Arg) if necessary to include given point
Definition MRMinMaxArg.h:103
void include(const MinMaxArg &s)
changes min(Arg) and max(Arg) if necessary to include given segment
Definition MRMinMaxArg.h:109
auto minPair() const
Definition MRMinMaxArg.h:84
T max
Definition MRMinMaxArg.h:81
I maxArg
Definition MRMinMaxArg.h:82
I minArg
Definition MRMinMaxArg.h:82
void include(const std::pair< T, I > &p)
changes min(Arg) and max(Arg) if necessary to include given point
Definition MRMinMaxArg.h:88