MCPcopy Create free account
hub / github.com/PCGEx/PCGExtendedToolkit / GetMode

Function GetMode

Source/PCGExtendedToolkit/Private/PCGExMath.cpp:87–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85 }
86
87 double GetMode(const TArray<double>& Values, const bool bHighest, const uint32 Tolerance)
88 {
89 TMap<double, int32> Map;
90 int32 LastCount = 0;
91 double Mode = 0;
92
93 for (const double Value : Values)
94 {
95 const double AdjustedValue = FMath::RoundToZero(Value / Tolerance) * Tolerance;
96 const int32* Count = Map.Find(AdjustedValue);
97 const int32 UpdatedCount = Count ? *Count + 1 : 1;
98 Map.Add(Value, UpdatedCount);
99
100 if (LastCount < UpdatedCount)
101 {
102 LastCount = UpdatedCount;
103 Mode = AdjustedValue;
104 }
105 else if (LastCount == UpdatedCount)
106 {
107 if (bHighest) { Mode = FMath::Max(Mode, AdjustedValue); }
108 else { Mode = FMath::Min(Mode, AdjustedValue); }
109 }
110 }
111
112 return Mode;
113 }
114
115 FVector SafeLinePlaneIntersection(const FVector& Pt1, const FVector& Pt2, const FVector& PlaneOrigin, const FVector& PlaneNormal, bool& bIntersect)
116 {

Callers 1

PostInitMethod · 0.85

Calls 4

MaxFunction · 0.85
MinFunction · 0.85
FindMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected