HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  {
25  *this = interval;
26  }
27 
28  UT_SuperIntervalT(T a, T b, bool ia = true, bool ib = true):
29  UT_IntervalT<T>( a, b )
30  {
31  myMinInclusive = ia;
32  myMaxInclusive = ib;
33  }
34 
36  {
37  myMinInclusive = true;
38  myMaxInclusive = true;
39  }
40 
42 
44  {
45  if( this != &interval )
46  {
47  *(UT_IntervalT<T>*)this = interval;
48  myMinInclusive = true;
49  myMaxInclusive = true;
50  }
51  return *this;
52  }
53 
54  // Returns true if arg is inside our interval range.
55  // WARNING: This is masking the int contains(T) function
56  // defined by UT_Interval!
57  bool contains(T arg, T tol=T(SYS_FTOLERANCE) ) const
58  {
59  return
60  (myMinInclusive ?
61  SYSisLessOrEqual(UT_IntervalT<T>::min, arg, tol) :
62  SYSisLess(UT_IntervalT<T>::min, arg, tol) )
63  &&
65  SYSisLessOrEqual(arg, UT_IntervalT<T>::max, tol) :
66  SYSisLess(arg, UT_IntervalT<T>::max, tol) );
67  }
68 
69  // This adjusts the range of our own interval so it doesn't
70  // exceed that of [c_min..c_max]. These boundaries are treated
71  // as inclusive boundaries, and the interval is made inclusive
72  // if clamped on an edge.
73  void clamp(T c_min, T c_max);
74 
75  void display() const;
76 
77 public:
79 };
80 
82 
83 
84 //////////////////////////////////////////////////////////////////////////////
85 //
86 // Implementation
87 //
88 
89 template <typename T>
90 void
91 UT_SuperIntervalT<T>::clamp(T c_min, T c_max)
92 {
93  if (UT_IntervalT<T>::min < c_min)
94  {
95  UT_IntervalT<T>::min = c_min;
96  myMinInclusive = true;
97  }
98  if (UT_IntervalT<T>::max > c_max)
99  {
100  UT_IntervalT<T>::max = c_max;
101  myMaxInclusive = true;
102  }
103 }
104 
105 #include <stdio.h>
106 
107 template <typename T>
108 void
110 {
111  printf( "%c%g, %g%c",
112  myMinInclusive ? '[' : '(',
115  myMaxInclusive ? ']' : ')'
116  );
117 }
118 
119 #endif // __UT_SuperInterval__
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
void display() const
void clamp(T c_min, T c_max)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
UT_SuperIntervalT(T a, T b, bool ia=true, bool ib=true)
#define SYS_FTOLERANCE
Definition: SYS_Types.h:196
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