HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SuperInterval.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SuperInterval.h ( UT Library, C++)
7  *
8  * COMMENTS: This is an extension to UT_Interval which allows exclusive
9  * and inclusive ranges.
10  */
11 
12 #ifndef __UT_SuperInterval__
13 #define __UT_SuperInterval__
14 
15 #include "UT_API.h"
16 #include "UT_Interval.h"
17 #include <SYS/SYS_Math.h>
18 
19 template <typename T>
21 {
22 public:
24  : UT_IntervalT<T>()
25  , myMinInclusive(true)
26  , myMaxInclusive(true)
27  {
28  }
29 
30  UT_SuperIntervalT(T a, T b, bool ia = true, bool ib = true)
31  : UT_IntervalT<T>(a, b)
32  , myMinInclusive(ia)
33  , myMaxInclusive(ib)
34  {
35  }
36 
38  : UT_IntervalT<T>(interval)
39  , myMinInclusive(true)
40  , myMaxInclusive(true)
41  {
42  }
44  : UT_IntervalT<T>(interval)
45  , myMinInclusive(interval.myMinInclusive)
46  , myMaxInclusive(interval.myMaxInclusive)
47  {
48  }
49 
51 
53  = default;
54 
56  {
57  if( this != &interval )
58  {
59  *(UT_IntervalT<T>*)this = interval;
60  myMinInclusive = true;
61  myMaxInclusive = true;
62  }
63  return *this;
64  }
65 
66  // Returns true if arg is inside our interval range.
67  // WARNING: This is masking the int contains(T) function
68  // defined by UT_Interval!
69  bool contains(T arg, T tol=T(SYS_FTOLERANCE) ) const
70  {
71  return
72  (myMinInclusive ?
73  SYSisLessOrEqual(UT_IntervalT<T>::min, arg, tol) :
74  SYSisLess(UT_IntervalT<T>::min, arg, tol) )
75  &&
77  SYSisLessOrEqual(arg, UT_IntervalT<T>::max, tol) :
78  SYSisLess(arg, UT_IntervalT<T>::max, tol) );
79  }
80 
81  // This adjusts the range of our own interval so it doesn't
82  // exceed that of [c_min..c_max]. These boundaries are treated
83  // as inclusive boundaries, and the interval is made inclusive
84  // if clamped on an edge.
85  void clamp(T c_min, T c_max);
86 
87  void display() const;
88 
89 public:
91 };
92 
94 
95 
96 //////////////////////////////////////////////////////////////////////////////
97 //
98 // Implementation
99 //
100 
101 template <typename T>
102 void
104 {
105  if (UT_IntervalT<T>::min < c_min)
106  {
107  UT_IntervalT<T>::min = c_min;
108  myMinInclusive = true;
109  }
110  if (UT_IntervalT<T>::max > c_max)
111  {
112  UT_IntervalT<T>::max = c_max;
113  myMaxInclusive = true;
114  }
115 }
116 
117 #include <stdio.h>
118 
119 template <typename T>
120 void
122 {
123  printf( "%c%g, %g%c",
124  myMinInclusive ? '[' : '(',
127  myMaxInclusive ? ']' : ')'
128  );
129 }
130 
131 #endif // __UT_SuperInterval__
UT_SuperIntervalT & operator=(UT_SuperIntervalT< T > const &interval)=default
auto printf(const S &fmt, const T &...args) -> int
Definition: printf.h:626
UT_SuperIntervalT(UT_SuperIntervalT< T > const &interval)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1736
void display() const
void clamp(T c_min, T c_max)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
UT_SuperIntervalT(T a, T b, bool ia=true, bool ib=true)
#define SYS_FTOLERANCE
Definition: SYS_Types.h:208
UT_SuperIntervalT(UT_IntervalT< T > const &interval)
UT_SuperIntervalT & operator=(UT_IntervalT< T > const &interval)
bool contains(T arg, T tol=T(SYS_FTOLERANCE)) const
UT_SuperIntervalT< fpreal > UT_SuperIntervalR