UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IndexOfCoordinateFinder.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Core/Types.h"
5
6namespace UE::CADKernel
7{
20{
21protected:
23public:
28
29 virtual int32 Find(const double InCoordinate) = 0;
30};
31
33{
34 int32& Index;
35
36public:
42
43 virtual int32 Find(const double InCoordinate) override
44 {
45 if ((Coordinates.Num() < 3) || (InCoordinate < Coordinates[0]))
46 {
47 Index = 0;
48 return Index;
49 }
50
51 if (InCoordinate > Coordinates.Last())
52 {
53 Index = Coordinates.Num() - 2;
54 return Index;
55 }
56
57 if (InCoordinate < Coordinates[Index])
58 {
59 // find the previous segment containing the coordinate
60 while (Index > 0)
61 {
62 --Index;
63 if (InCoordinate + DOUBLE_SMALL_NUMBER >= Coordinates[Index])
64 {
65 return Index;
66 }
67 }
68 return Index;
69 }
70
71 // find the next segment containing the coordinate
72 for (; Index < Coordinates.Num() - 2; ++Index)
73 {
74 if (InCoordinate <= Coordinates[Index + 1])
75 {
76 return Index;
77 }
78 }
79 Index = Coordinates.Num() - 2;
80 return Index;
81 }
82};
83
85{
86
87public:
94
101
104
105 virtual int32 Find(const double InCoordinate) override
106 {
107 if (StartUpper < 0)
108 {
109 StartUpper = Coordinates.Num() - 2;
110 }
111
112 if ((StartUpper - StartLower < 1) || (InCoordinate < Coordinates[StartLower + 1]))
113 {
114 return StartLower;
115 }
116
117 if (InCoordinate > Coordinates[StartUpper])
118 {
119 StartLower = StartUpper;
120 return StartUpper;
121 }
122
123 int32 LowerBound = StartLower;
124 int32 UpperBound = StartUpper;
125
126 while (LowerBound <= UpperBound)
127 {
128 int32 Center = (LowerBound + UpperBound) >> 1;
129 if (InCoordinate >= Coordinates[Center] && InCoordinate <= Coordinates[Center + 1])
130 {
131 StartLower = Center;
132 return Center;
133 }
134 else if (InCoordinate < Coordinates[Center])
135 {
136 UpperBound = Center;
137 }
138 else
139 {
140 LowerBound = Center + 1;
141 }
142 }
143 return StartUpper;
144 }
145};
146} // namespace UE::CADKernel
147
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
@ Num
Definition MetalRHIPrivate.h:234
#define DOUBLE_SMALL_NUMBER
Definition UnrealMathUtility.h:72
Definition Array.h:670
Definition IndexOfCoordinateFinder.h:85
int32 StartLower
Definition IndexOfCoordinateFinder.h:102
FDichotomyFinder(const TArray< double > &InPolylineCoordinates)
Definition IndexOfCoordinateFinder.h:88
virtual int32 Find(const double InCoordinate) override
Definition IndexOfCoordinateFinder.h:105
FDichotomyFinder(const TArray< double > &InPolylineCoordinates, int32 InStartLowerBound, int32 InStartUpperBound)
Definition IndexOfCoordinateFinder.h:95
int32 StartUpper
Definition IndexOfCoordinateFinder.h:103
Definition IndexOfCoordinateFinder.h:20
const TArray< double > & Coordinates
Definition IndexOfCoordinateFinder.h:22
FIndexOfCoordinateFinder(const TArray< double > &InPolylineCoordinates)
Definition IndexOfCoordinateFinder.h:24
virtual int32 Find(const double InCoordinate)=0
Definition IndexOfCoordinateFinder.h:33
virtual int32 Find(const double InCoordinate) override
Definition IndexOfCoordinateFinder.h:43
FLinearFinder(const TArray< double > &InPolylineCoordinates, int32 &InOutIndex)
Definition IndexOfCoordinateFinder.h:37
Definition CADEntity.cpp:23
U16 Index
Definition radfft.cpp:71