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 bool 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  // Returns true if arg overlaps our interval range.
82  // WARNING: This is masking the bool intersects(T) function
83  // defined by UT_Interval!
84  bool intersects(const UT_SuperIntervalT &arg, T tol=T(SYS_FTOLERANCE)) const
85  {
86  const T max = UT_IntervalT<T>::max;
87  const T min = UT_IntervalT<T>::min;
88 
89  if (SYSisLess(max, arg.min, tol))
90  return false;
91 
92  if (SYSisEqual(max, arg.min, tol))
93  return myMaxInclusive && arg.myMinInclusive;
94 
95  if (SYSisLess(arg.max, min, tol))
96  return false;
97 
98  if (SYSisEqual(arg.max, min, tol))
99  return arg.myMaxInclusive && myMinInclusive;
100 
101  return true;
102  }
103 
104  // This adjusts the range of our own interval so it doesn't
105  // exceed that of [c_min..c_max]. These boundaries are treated
106  // as inclusive boundaries, and the interval is made inclusive
107  // if clamped on an edge.
108  void clamp(T c_min, T c_max);
109 
110  void display() const;
111 
112 public:
114 };
115 
117 
118 
119 //////////////////////////////////////////////////////////////////////////////
120 //
121 // Implementation
122 //
123 
124 template <typename T>
125 void
127 {
128  if (UT_IntervalT<T>::min < c_min)
129  {
130  UT_IntervalT<T>::min = c_min;
131  myMinInclusive = true;
132  }
133  if (UT_IntervalT<T>::max > c_max)
134  {
135  UT_IntervalT<T>::max = c_max;
136  myMaxInclusive = true;
137  }
138 }
139 
140 #include <stdio.h>
141 
142 template <typename T>
143 void
145 {
146  printf( "%c%g, %g%c",
147  myMinInclusive ? '[' : '(',
150  myMaxInclusive ? ']' : ')'
151  );
152 }
153 
154 #endif // __UT_SuperInterval__
bool SYSisEqual(const UT_Vector2T< T > &a, const UT_Vector2T< T > &b, S tol)
Componentwise equality.
Definition: UT_Vector2.h:677
UT_SuperIntervalT & operator=(UT_SuperIntervalT< T > const &interval)=default
auto printf(const S &fmt, const T &...args) -> int
Definition: printf.h:670
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:1859
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 intersects(const UT_SuperIntervalT &arg, T tol=T(SYS_FTOLERANCE)) const
bool contains(T arg, T tol=T(SYS_FTOLERANCE)) const
UT_SuperIntervalT< fpreal > UT_SuperIntervalR