All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
multiInterval.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_GF_MULTI_INTERVAL_H
25 #define PXR_BASE_GF_MULTI_INTERVAL_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/gf/interval.h"
32 #include "pxr/base/gf/api.h"
33 
34 #include <iosfwd>
35 #include <set>
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
47 {
48 public:
49  typedef std::set<GfInterval> Set;
50  typedef Set::const_iterator const_iterator;
51  typedef Set::const_iterator iterator;
52 
56  GfMultiInterval() = default;
58  GF_API explicit GfMultiInterval(const GfInterval &i);
60  GF_API explicit GfMultiInterval(const std::vector<GfInterval> &intervals);
62 
63  GF_API bool operator==(const GfMultiInterval &that) const { return _set == that._set; }
64  GF_API bool operator!=(const GfMultiInterval &that) const { return !(*this == that); }
65  GF_API bool operator<(const GfMultiInterval &that) const { return _set < that._set; }
66  GF_API bool operator>=(const GfMultiInterval &that) const { return !(*this < that); }
67  GF_API bool operator>(const GfMultiInterval &that) const { return (that < *this); }
68  GF_API bool operator<=(const GfMultiInterval &that) const { return !(that < *this); }
69 
70 
73  GF_API size_t Hash() const;
74 
75  friend inline size_t hash_value(const GfMultiInterval &mi) {
76  return mi.Hash();
77  }
78 
81 
83  GF_API bool IsEmpty() const { return _set.empty(); }
84 
86  GF_API size_t GetSize() const { return _set.size(); }
87 
90  GF_API GfInterval GetBounds() const;
91 
93  GF_API bool Contains(double d) const;
94 
96  GF_API bool Contains(const GfInterval & i) const;
97 
100  GF_API bool Contains(const GfMultiInterval & s) const;
101 
103 
106 
108  GF_API void Clear() { _set.clear(); }
109 
111  GF_API void Add( const GfInterval & i );
114  GF_API void Add( const GfMultiInterval &s );
115 
118  GF_API void ArithmeticAdd( const GfInterval &i );
119 
121  GF_API void Remove( const GfInterval & i );
123  GF_API void Remove( const GfMultiInterval &s );
124 
125  GF_API void Intersect( const GfInterval & i );
126  GF_API void Intersect( const GfMultiInterval &s );
127 
129  GF_API GfMultiInterval GetComplement() const;
130 
132 
137 
138  GF_API const_iterator begin() const { return _set.begin(); }
139  GF_API const_iterator end() const { return _set.end(); }
140 
143  GF_API const_iterator lower_bound( double x ) const;
144 
147  GF_API const_iterator upper_bound( double x ) const;
148 
151  GF_API const_iterator GetNextNonContainingInterval( double x ) const;
152 
155  GF_API const_iterator GetPriorNonContainingInterval( double x ) const;
156 
159  GF_API const_iterator GetContainingInterval( double x ) const;
160 
162 
164  static GfMultiInterval GetFullInterval() {
165  return GfMultiInterval(GfInterval::GetFullInterval());
166  }
167 
169  void swap(GfMultiInterval &other) { _set.swap(other._set); }
170 
171 private:
172  void _AssertInvariants() const;
173 
174  Set _set;
175 };
176 
179 GF_API std::ostream & operator<<(std::ostream &out, const GfMultiInterval &s);
180 
181 PXR_NAMESPACE_CLOSE_SCOPE
182 
183 #endif // PXR_BASE_GF_MULTI_INTERVAL_H
void swap(GfMultiInterval &other)
Swap two multi-intervals.
GF_API void Remove(const GfInterval &i)
Remove the given interval from this multi-interval.
GF_API const_iterator GetPriorNonContainingInterval(double x) const
Returns an iterator identifying the last (highest) interval whose maximum value is &lt; x...
GF_API GfInterval GetBounds() const
Returns an interval bounding the entire multi-interval.
GF_API void ArithmeticAdd(const GfInterval &i)
Uses the given interval to extend the multi-interval in the interval arithmetic sense.
GF_API void Add(const GfInterval &i)
Add the given interval to the multi-interval.
GF_API const_iterator upper_bound(double x) const
Returns an iterator identifying the first (lowest) interval whose minimum value is &gt; x...
GF_API bool IsEmpty() const
Returns true if the multi-interval is empty.
Definition: multiInterval.h:83
GF_API bool Contains(double d) const
Returns true if the multi-interval contains the given value.
GF_API const_iterator lower_bound(double x) const
Returns an iterator identifying the first (lowest) interval whose minimum value is &gt;= x...
GF_API size_t GetSize() const
Returns the number of intervals in the set.
Definition: multiInterval.h:86
static GfMultiInterval GetFullInterval()
Returns the full interval (-inf, inf).
GF_API size_t Hash() const
Hash value.
A basic mathematical interval class.
Definition: interval.h:50
static GfInterval GetFullInterval()
Returns the full interval (-inf, inf).
Definition: interval.h:346
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfMultiInterval represents a subset of the real number line as an ordered set of non-intersecting GfI...
Definition: multiInterval.h:46
GF_API void Clear()
Clear the multi-interval.
GF_API const_iterator GetNextNonContainingInterval(double x) const
Returns an iterator identifying the first (loest) interval whose minimum value is &gt; x...
GF_API GfMultiInterval GetComplement() const
Return the complement of this set.
GF_API const_iterator GetContainingInterval(double x) const
Returns an iterator identifying the interval that contains x.