SRange.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <ionCore/ionTypes.h>
5 
6 
7 template <typename T>
8 struct SRange
9 {
10  static SRange const Full;
11  static SRange const Empty;
12 
13  bool Contains(T const value) const
14  {
15  return value >= Minimum && value <= Maximum;
16  }
17 
18  bool IsEmpty() const
19  {
20  return Minimum > Maximum;
21  }
22 
23  bool IsSingular() const
24  {
25  return Equals(Minimum, Maximum);
26  }
27 
28  T Normalize(T const value) const
29  {
30  return (value - Minimum) / (Maximum - Minimum);
31  }
32 
33  T Size() const
34  {
35  return Maximum - Minimum;
36  }
37 
39  {
40  * this = Empty;
41  }
42 
43  SRange(T const minimum, T const maximum)
44  : Minimum(minimum), Maximum(maximum)
45  {}
46 
47  SRange & operator = (SRange const & Other)
48  {
49  Minimum = Other.Minimum;
50  Maximum = Other.Maximum;
51  return * this;
52  }
53 
56 };
57 
58 template <typename T>
59 SRange<T> const SRange<T>::Full = SRange<T>(-std::numeric_limits<T>::max(), std::numeric_limits<T>::max());
60 
61 template <typename T>
62 SRange<T> const SRange<T>::Empty = SRange<T>(std::numeric_limits<T>::max(), -std::numeric_limits<T>::max());
static SRange const Empty
Definition: SRange.h:11
bool Contains(T const value) const
Definition: SRange.h:13
static SRange const Full
Definition: SRange.h:10
T Maximum
Definition: SRange.h:55
T Size() const
Definition: SRange.h:33
T Normalize(T const value) const
Definition: SRange.h:28
SRange(T const minimum, T const maximum)
Definition: SRange.h:43
bool IsSingular() const
Definition: SRange.h:23
Defines typedefs for integer and floating point types.
Definition: SRange.h:8
T Minimum
Definition: SRange.h:54
SRange & operator=(SRange const &Other)
Definition: SRange.h:47
bool IsEmpty() const
Definition: SRange.h:18
SRange()
Definition: SRange.h:38