UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IndexUtil.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of geometry3cpp index_util.h
4
5#pragma once
6
7#include "Containers/Array.h"
8#include "GeometryBase.h"
9#include "IndexTypes.h"
10#include "IntVectorTypes.h"
11#include "Math/MathFwd.h"
12#include "Math/Vector.h"
13#include "Util/DynamicVector.h"
14#include "VectorTypes.h"
15
16
17namespace IndexUtil
18{
19 using namespace UE::Geometry;
21
25 template<typename T>
26 inline bool SamePairUnordered(T a0, T a1, T b0, T b1)
27 {
28 return (a0 == b0) ?
29 (a1 == b1) :
30 (a0 == b1 && a1 == b0);
31 }
32
33
38 {
39 if (EdgeVerts1.A == EdgeVerts2.A) return EdgeVerts1.A;
40 else if (EdgeVerts1.A == EdgeVerts2.B) return EdgeVerts1.A;
41 else if (EdgeVerts1.B == EdgeVerts2.A) return EdgeVerts1.B;
42 else if (EdgeVerts1.B == EdgeVerts2.B) return EdgeVerts1.B;
43 else return IndexConstants::InvalidID;
44 }
45
49 inline int FindEdgeOtherVertex(const FIndex2i & EdgeVerts, int VertexID)
50 {
51 if (EdgeVerts.A == VertexID) return EdgeVerts.B;
52 else if (EdgeVerts.B == VertexID) return EdgeVerts.A;
53 else return IndexConstants::InvalidID;
54 }
55
56
60 template<typename T, typename Vec>
61 inline int FindTriIndex(T VertexID, const Vec & TriangleVerts)
62 {
63 if (TriangleVerts[0] == VertexID) return 0;
64 if (TriangleVerts[1] == VertexID) return 1;
65 if (TriangleVerts[2] == VertexID) return 2;
67 }
68
73 template<typename T, typename Vec>
81
82
87 template<typename T, typename Vec>
89 {
90 if (TriangleVerts[0] == VertexID1 && TriangleVerts[1] == VertexID2) return 0;
91 if (TriangleVerts[1] == VertexID1 && TriangleVerts[2] == VertexID2) return 1;
92 if (TriangleVerts[2] == VertexID1 && TriangleVerts[0] == VertexID2) return 2;
94 }
95
100 template<typename T, typename Vec>
102 {
103 if (TriangleVerts[0] == VertexID1)
104 {
105 return (TriangleVerts[1] == VertexID2) ? TriangleVerts[2] : TriangleVerts[1];
106 }
107 else if (TriangleVerts[1] == VertexID1)
108 {
109 return (TriangleVerts[0] == VertexID2) ? TriangleVerts[2] : TriangleVerts[0];
110 }
111 else
112 {
113 return (TriangleVerts[0] == VertexID2) ? TriangleVerts[1] : TriangleVerts[0];
114 }
115 }
116
117
122 template<typename T, typename Vec>
124 {
125 for (int j = 0; j < 3; ++j)
126 {
128 {
129 return TriangleVerts[(j + 2) % 3];
130 }
131 }
133 }
134
143 inline int FindTriOtherVtx(int VertexID1, int VertexID2, const TDynamicVector<FIndex3i> & TriIndexArray, int TriangleIndex)
144 {
145 const FIndex3i& Triangle = TriIndexArray[TriangleIndex];
146 for (int j = 0; j < 3; ++j)
147 {
149 {
150 return Triangle[((j + 2) % 3)];
151 }
152 }
154 }
155
156
157
162 template<typename T, typename Vec>
164 {
165 for (int j = 0; j < 3; ++j)
166 {
168 {
169 return (j + 2) % 3;
170 }
171 }
173 }
174
175
179 inline int GetOtherTriIndex(int i0, int i1)
180 {
181 // @todo can we do this with a formula? I don't see it right now.
182 static const int values[4] = { 0, 2, 1, 0 };
183 return values[i0+i1];
184 }
185
186
192 template<typename T, typename Vec>
193 inline bool OrientTriEdge(T & Vertex1, T & Vertex2, const Vec & TriangleVerts)
194 {
195 if (Vertex1 == TriangleVerts[0])
196 {
197 if (TriangleVerts[2] == Vertex2)
198 {
199 T Temp = Vertex1; Vertex1 = Vertex2; Vertex2 = Temp;
200 return true;
201 }
202 }
203 else if (Vertex1 == TriangleVerts[1])
204 {
205 if (TriangleVerts[0] == Vertex2)
206 {
207 T Temp = Vertex1; Vertex1 = Vertex2; Vertex2 = Temp;
208 return true;
209 }
210 }
211 else if (Vertex1 == TriangleVerts[2])
212 {
213 if (TriangleVerts[1] == Vertex2)
214 {
215 T Temp = Vertex1; Vertex1 = Vertex2; Vertex2 = Temp;
216 return true;
217 }
218 }
219 return false;
220 }
221
222
228 template<typename T, typename Vec>
230 {
231 for (int j = 0; j < 3; ++j)
232 {
234 {
236 Vertex2 = TriangleVerts[(j + 1) % 3];
237 return TriangleVerts[(j + 2) % 3];
238 }
239 }
241 }
242
243
247 template<typename Func>
248 void ApplyMap(FIndex3i & Val, Func MapFunc)
249 {
250 Val[0] = MapFunc[Val[0]];
251 Val[1] = MapFunc[Val[1]];
252 Val[2] = MapFunc[Val[2]];
253 }
254
258 template<typename T, typename Func>
259 void ApplyMap(UE::Math::TVector<T> & Val, Func MapFunc)
260 {
261 Val[0] = MapFunc[Val[0]];
262 Val[1] = MapFunc[Val[1]];
263 Val[2] = MapFunc[Val[2]];
264 }
265
266
270 template<typename Func>
271 FIndex3i ApplyMap(const FIndex3i & Val, Func MapFunc)
272 {
273 return FIndex3i(MapFunc[Val[0]], MapFunc[Val[1]], MapFunc[Val[2]]);
274 }
275
276
280 template<typename T, typename Func>
282 {
283 return UE::Math::TVector<T>(MapFunc[Val[0]], MapFunc[Val[1]], MapFunc[Val[2]]);
284 }
285
289 template<typename T, typename Func>
291 {
292 for (const T& Value : ToCheck)
293 {
294 if (!CheckFn(Value))
295 {
296 return false;
297 }
298 }
299 return true;
300 }
301
306
311
316
321
325 extern GEOMETRYCORE_API const int BoxFaces[6][4];
326
330 extern GEOMETRYCORE_API const FVector2i BoxFacesUV[4];
331
335 extern GEOMETRYCORE_API const int BoxFaceNormals[6];
336
337
338 // @todo other index array constants
339}
EGLSurface EGLint const EGLint EGLnsecsANDROID * values
Definition AndroidOpenGLFunctions.h:11
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
float Val(const FString &Value)
Definition UnrealMath.cpp:3163
Definition Array.h:670
Definition DynamicVector.h:27
constexpr int InvalidID
Definition IndexTypes.h:13
Definition IndexUtil.h:18
void ApplyMap(FIndex3i &Val, Func MapFunc)
Definition IndexUtil.h:248
GEOMETRYCORE_API const FVector3i GridOffsets6[6]
Definition IndexUtil.cpp:24
int GetOtherTriIndex(int i0, int i1)
Definition IndexUtil.h:179
int FindTriOrderedEdge(T VertexID1, T VertexID2, const Vec &TriangleVerts)
Definition IndexUtil.h:88
int FindEdgeOtherVertex(const FIndex2i &EdgeVerts, int VertexID)
Definition IndexUtil.h:49
GEOMETRYCORE_API const FVector2i GridOffsets8[8]
Definition IndexUtil.cpp:15
int OrientTriEdgeAndFindOtherVtx(T &Vertex1, T &Vertex2, const Vec &TriangleVerts)
Definition IndexUtil.h:229
int FindTriIndex(T VertexID, const Vec &TriangleVerts)
Definition IndexUtil.h:61
int FindTriOtherVtx(T VertexID1, T VertexID2, const Vec &TriangleVerts)
Definition IndexUtil.h:123
int FindTriOtherVtxUnsafe(T VertexID1, T VertexID2, const Vec &TriangleVerts)
Definition IndexUtil.h:101
GEOMETRYCORE_API const FVector2i GridOffsets4[4]
Definition IndexUtil.cpp:8
GEOMETRYCORE_API const int BoxFaces[6][4]
Definition IndexUtil.cpp:65
int FindTriOtherIndex(T VertexID1, T VertexID2, const Vec &TriangleVerts)
Definition IndexUtil.h:163
bool OrientTriEdge(T &Vertex1, T &Vertex2, const Vec &TriangleVerts)
Definition IndexUtil.h:193
int FindEdgeIndexInTri(T VertexID1, T VertexID2, const Vec &TriangleVerts)
Definition IndexUtil.h:74
GEOMETRYCORE_API const int BoxFaceNormals[6]
Definition IndexUtil.cpp:82
GEOMETRYCORE_API const FVector2i BoxFacesUV[4]
Definition IndexUtil.cpp:80
bool SamePairUnordered(T a0, T a1, T b0, T b1)
Definition IndexUtil.h:26
int FindSharedEdgeVertex(const FIndex2i &EdgeVerts1, const FIndex2i &EdgeVerts2)
Definition IndexUtil.h:37
bool ArrayCheck(const TArray< T > &ToCheck, Func CheckFn)
Definition IndexUtil.h:290
GEOMETRYCORE_API const FVector3i GridOffsets26[26]
Definition IndexUtil.cpp:32
Definition ParametricSurfaceData.h:18
Definition IndexTypes.h:27
Definition IndexTypes.h:158
Definition IntVectorTypes.h:20
Definition IntVectorTypes.h:252
Definition Vector.h:51