UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RangeSet.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Containers/Array.h"
7#include "Math/Range.h"
9
10
16template<typename ElementType> class TRangeSet
17{
20
21 /*~ Typedef used to pass/return small element types by value rather than const& */
22 typedef typename TCallTraits<ElementType>::ParamType ElementValueOrConstRef;
23
24public:
25
28
31
32public:
33
42 void Add(RangeType Range)
43 {
44 for (int32 Index = 0; Index < Ranges.Num(); ++Index)
45 {
46 const RangeType& Current = Ranges[Index];
47
48 if (Current.Adjoins(Range) || Current.Overlaps(Range))
49 {
50 Range = RangeType(
51 BoundsType::MinLower(Current.GetLowerBound(), Range.GetLowerBound()),
52 BoundsType::MaxUpper(Current.GetUpperBound(), Range.GetUpperBound())
53 );
54
55 Ranges.RemoveAtSwap(Index--);
56 }
57 }
58
59 Ranges.Add(Range);
60 }
61
67 void Merge(const TRangeSet& Other)
68 {
69 for (typename TArray<RangeType>::TConstIterator It(Other.Ranges); It; ++It)
70 {
71 Add(*It);
72 }
73 }
74
/*
82 void Remove(const RangeType& Range)
83 {
84 for (int32 Index = 0; Index < Ranges.Num(); ++Index)
85 {
86 const RangeType& Current = Ranges(Index);
87
88 if (Current.Overlaps(Range))
89 {
90 if (Current.GetLowerBound() < Range.GetLowerBound())
91 {
92 Ranges.Add(RangeType(Current.GetLowerBound(), Range.GetLowerBound()));
93 }
94
95 if (Current.GetUpperBound() > Range.GetUpperBound())
96 {
97 Ranges.Add(RangeType(Range.GetUpperBound(), Current.GetUpperBound()));
98 }
99
100 Ranges.RemoveAtSwap(Index--);
101 }
102 }
103 }*/
104
106 void Empty()
107 {
108 Ranges.Empty();
109 }
110
111public:
112
119 [[nodiscard]] bool Contains(ElementValueOrConstRef Element) const
120 {
121 for (typename TArray<RangeType>::TConstIterator It(Ranges); It; ++It)
122 {
123 if (It->Contains(Element))
124 {
125 return true;
126 }
127 }
128
129 return false;
130 }
131
138 [[nodiscard]] bool Contains(const RangeType& Range) const
139 {
140 for (typename TArray<RangeType>::TConstIterator It(Ranges); It; ++It)
141 {
142 if (It->Contains(Range))
143 {
144 return true;
145 }
146 }
147
148 return false;
149 }
150
158 {
159 BoundsType Result;
160
161 if (Ranges.Num())
162 {
163 Result = Ranges[0].GetLowerBound();
164 for (int32 i = 1; i < Ranges.Num(); i++)
165 {
166 Result = BoundsType::MinLower(Result, Ranges[i].GetLowerBound());
167 }
168 }
169
170 return Result;
171 }
172
181 [[nodiscard]] ElementType GetMinBoundValue() const
182 {
183 return GetMinBound().GetValue();
184 }
185
193 {
194 BoundsType Result;
195
196 if (Ranges.Num())
197 {
198 Result = Ranges[0].GetUpperBound();
199 for (int32 i = 1; i < Ranges.Num(); i++)
200 {
201 Result = BoundsType::MaxUpper(Result, Ranges[i].GetUpperBound());
202 }
203 }
204
205 return Result;
206 }
207
216 [[nodiscard]] ElementType GetMaxBoundValue() const
217 {
218 return GetMaxBound().GetValue();
219 }
220
221
228 template<typename Allocator>
230 {
231 OutRanges = Ranges;
232 }
233
240 [[nodiscard]] bool HasMinBound() const
241 {
242 return GetMinBound().IsClosed();
243 }
244
251 [[nodiscard]] bool HasMaxBound() const
252 {
253 return GetMaxBound().IsClosed();
254 }
255
261 [[nodiscard]] bool IsEmpty() const
262 {
263 return (Ranges.Num() == 0);
264 }
265
272 [[nodiscard]] bool Overlaps(const RangeType& Range) const
273 {
274 for (typename TArray<RangeType>::TConstIterator It(Ranges); It; ++It)
275 {
276 if (It->Overlaps(Range))
277 {
278 return true;
279 }
280 }
281
282 return false;
283 }
284
293 [[nodiscard]] bool Overlaps(const TRangeSet& Other) const
294 {
295 for (typename TArray<RangeType>::TConstIterator It(Other.Ranges); It; ++It)
296 {
297 if (Overlaps(*It))
298 {
299 return true;
300 }
301 }
302
303 return false;
304 }
305
306public:
307
315 friend class FArchive& operator<<(class FArchive& Ar, TRangeSet& RangeSet)
316 {
317 return Ar << RangeSet.Ranges;
318 }
319
320private:
321
323 TArray<RangeType> Ranges;
324};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition Archive.h:1208
Definition Array.h:670
Definition Array.h:64
Definition RangeBound.h:36
ElementValueOrConstRef GetValue() const
Definition RangeBound.h:97
UE_FORCEINLINE_HINT bool IsClosed() const
Definition RangeBound.h:125
static const TRangeBound & MinLower(const TRangeBound &A, const TRangeBound &B)
Definition RangeBound.h:300
static const TRangeBound & MaxUpper(const TRangeBound &A, const TRangeBound &B)
Definition RangeBound.h:282
Definition RangeSet.h:17
bool HasMaxBound() const
Definition RangeSet.h:251
bool Contains(ElementValueOrConstRef Element) const
Definition RangeSet.h:119
friend class FArchive & operator<<(class FArchive &Ar, TRangeSet &RangeSet)
Definition RangeSet.h:315
BoundsType GetMaxBound() const
Definition RangeSet.h:192
BoundsType GetMinBound() const
Definition RangeSet.h:157
bool Contains(const RangeType &Range) const
Definition RangeSet.h:138
bool Overlaps(const RangeType &Range) const
Definition RangeSet.h:272
const void GetRanges(TArray< RangeType, Allocator > &OutRanges) const
Definition RangeSet.h:229
void Empty()
Definition RangeSet.h:106
bool IsEmpty() const
Definition RangeSet.h:261
bool Overlaps(const TRangeSet &Other) const
Definition RangeSet.h:293
TRangeSet()
Definition RangeSet.h:27
ElementType GetMinBoundValue() const
Definition RangeSet.h:181
bool HasMinBound() const
Definition RangeSet.h:240
void Add(RangeType Range)
Definition RangeSet.h:42
ElementType GetMaxBoundValue() const
Definition RangeSet.h:216
~TRangeSet()
Definition RangeSet.h:30
void Merge(const TRangeSet &Other)
Definition RangeSet.h:67
Definition Range.h:50
U16 Index
Definition radfft.cpp:71
TCallTraitsParamTypeHelper< T, PassByValue >::ParamType ParamType
Definition UnrealTypeTraits.h:275