Viskores  1.0
RangeId.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_RangeId_h
19 #define viskores_RangeId_h
20 
21 #include <viskores/Math.h>
22 #include <viskores/Types.h>
23 
24 namespace viskores
25 {
26 
36 struct RangeId
37 {
42 
46  : Min(0)
47  , Max(0)
48  {
49  }
50 
55  : Min(min)
56  , Max(max)
57  {
58  }
59 
67  bool IsNonEmpty() const { return (this->Min < this->Max); }
68 
75  bool Contains(viskores::Id value) const { return ((this->Min <= value) && (this->Max > value)); }
76 
83  viskores::Id Length() const { return this->Max - this->Min; }
84 
90  viskores::Id Center() const { return (this->Min + this->Max) / 2; }
91 
99  void Include(viskores::Id value)
100  {
101  this->Min = viskores::Min(this->Min, value);
102  this->Max = viskores::Max(this->Max, value + 1);
103  }
104 
111  void Include(const viskores::RangeId& range)
112  {
113  this->Min = viskores::Min(this->Min, range.Min);
114  this->Max = viskores::Max(this->Max, range.Max);
115  }
116 
123  {
124  viskores::RangeId unionRange(*this);
125  unionRange.Include(other);
126  return unionRange;
127  }
128 
132  viskores::RangeId operator+(const viskores::RangeId& other) const { return this->Union(other); }
133 
135  bool operator==(const viskores::RangeId& other) const
136  {
137  return ((this->Min == other.Min) && (this->Max == other.Max));
138  }
139 
141  bool operator!=(const viskores::RangeId& other) const
142  {
143  return ((this->Min != other.Min) || (this->Max != other.Max));
144  }
145 };
146 
149 static inline VISKORES_CONT std::ostream& operator<<(std::ostream& stream,
150  const viskores::RangeId& range)
151 {
152  return stream << "[" << range.Min << ".." << range.Max << ")";
153 } // Declared inside of viskores namespace so that the operator work with ADL lookup
154 } // namespace viskores
155 
156 #endif // viskores_RangeId_h
viskores::RangeId::IsNonEmpty
bool IsNonEmpty() const
Determine if the range is valid.
Definition: RangeId.h:67
Types.h
viskores::RangeId::RangeId
RangeId(viskores::Id min, viskores::Id max)
Construct a range with the given minimum (inclusive) and maximum (exclusive) indices.
Definition: RangeId.h:54
viskores::RangeId::Contains
bool Contains(viskores::Id value) const
Determines if a value is within the range.
Definition: RangeId.h:75
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::RangeId::RangeId
RangeId()
Construct a range with no indices.
Definition: RangeId.h:45
viskores::RangeId::operator==
bool operator==(const viskores::RangeId &other) const
Definition: RangeId.h:135
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::operator<<
std::ostream & operator<<(std::ostream &stream, const viskores::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:268
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Math.h
viskores::RangeId::Include
void Include(viskores::Id value)
Expand range to include a value.
Definition: RangeId.h:99
viskores::RangeId::Include
void Include(const viskores::RangeId &range)
Expand range to include other range.
Definition: RangeId.h:111
viskores::RangeId::Center
viskores::Id Center() const
Returns the center of the range.
Definition: RangeId.h:90
viskores::RangeId::operator!=
bool operator!=(const viskores::RangeId &other) const
Definition: RangeId.h:141
viskores::RangeId
Represent a range of viskores::Id values.
Definition: RangeId.h:36
viskores::RangeId::Union
viskores::RangeId Union(const viskores::RangeId &other) const
Return the union of this and another range.
Definition: RangeId.h:122
viskores::RangeId::Max
viskores::Id Max
The maximum index of the range (exclusive).
Definition: RangeId.h:41
viskores::RangeId::Length
viskores::Id Length() const
Returns the length of the range.
Definition: RangeId.h:83
viskores::RangeId::operator+
viskores::RangeId operator+(const viskores::RangeId &other) const
Operator for union
Definition: RangeId.h:132
viskores::RangeId::Min
viskores::Id Min
The minimum index of the range (inclusive).
Definition: RangeId.h:39