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>
13{
14 T min = std::numeric_limits<T>::max();
15 T max = std::numeric_limits<T>::lowest();
17
18 auto minPair() const { return std::make_pair( min, minArg ); }
19 auto maxPair() const { return std::make_pair( max, maxArg ); }
20
22 void include( const std::pair<T,I>& p )
23 {
24 if ( p < minPair() )
25 {
26 min = p.first;
27 minArg = p.second;
28 }
29 if ( p > maxPair() )
30 {
31 max = p.first;
32 maxArg = p.second;
33 }
34 }
35
37 void include( T v, I arg )
38 {
39 return include( std::make_pair( v, arg ) );
40 }
41
43 void include( const MinMaxArg & s )
44 {
45 // it shall work with default initialized this and s
46 if ( s.minPair() < minPair() )
47 {
48 min = s.min;
49 minArg = s.minArg;
50 }
51 if ( s.maxPair() > maxPair() )
52 {
53 max = s.max;
54 maxArg = s.maxArg;
55 }
56 }
57};
58
59} //namespace MR
I
Definition MRMesh/MRMeshFwd.h:121
Definition MRMinMaxArg.h:13
auto maxPair() const
Definition MRMinMaxArg.h:19
T min
Definition MRMinMaxArg.h:14
void include(T v, I arg)
changes min(Arg) and max(Arg) if necessary to include given point
Definition MRMinMaxArg.h:37
void include(const MinMaxArg &s)
changes min(Arg) and max(Arg) if necessary to include given segment
Definition MRMinMaxArg.h:43
auto minPair() const
Definition MRMinMaxArg.h:18
T max
Definition MRMinMaxArg.h:15
I maxArg
Definition MRMinMaxArg.h:16
I minArg
Definition MRMinMaxArg.h:16
void include(const std::pair< T, I > &p)
changes min(Arg) and max(Arg) if necessary to include given point
Definition MRMinMaxArg.h:22