Class Utils
A collection of useful functions without a specific object context.
Namespace: Holoride.ElasticSDK
Assembly: Holoride.ElasticSDK.Library.Runtime.dll
Syntax
public static class Utils
Methods
ApplyPoseToTransform(Pose, Transform)
Applies a Pose to a transform.
Declaration
public static void ApplyPoseToTransform(Pose pose, Transform transform)
Parameters
Type | Name | Description |
---|---|---|
Pose | pose | The pose to apply. |
Transform | transform | The transform to apply the pose to. |
BlochHash(double, double)
Computes a hash code using a strategy by Josh Bloch.
Declaration
public static int BlochHash(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
double | x | The first seed value. |
double | y | The second seed value. |
Returns
Type | Description |
---|---|
int | The hashed value. |
CalculateGaussianKernel(int, float)
Calculates a Gaussian Kernel.
Declaration
public static float[,] CalculateGaussianKernel(int length, float weight)
Parameters
Type | Name | Description |
---|---|---|
int | length | The lenght. |
float | weight | The weight. |
Returns
Type | Description |
---|---|
float[,] | A float array with the Gaussian Kernel. |
Clamp(double, double, double)
Clamps a double value between a min and a max value.
Declaration
public static double Clamp(double number, double min, double max)
Parameters
Type | Name | Description |
---|---|---|
double | number | The value to clamp. |
double | min | The minimum value. |
double | max | The maximum value. |
Returns
Type | Description |
---|---|
double | The clamped value. |
Clamp01(double)
Clamps a double value into a range of [0, 1].
Declaration
public static double Clamp01(double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to clamp. |
Returns
Type | Description |
---|---|
double | The clamped value. |
Clone<T>(T)
Perform a deep Copy of the object. Note: This code was obtained from https://stackoverflow.com/questions/78536/deep-cloning-objects.
Declaration
public static T Clone<T>(T source)
Parameters
Type | Name | Description |
---|---|---|
T | source | The object instance to copy. |
Returns
Type | Description |
---|---|
T | The copied object. |
Type Parameters
Name | Description |
---|---|
T | The type of object being copied. |
ComputeCentroid(List<GeoCoordinate>)
Computes the centroid of a given polygon build of a list of coordinates.
Declaration
public static GeoCoordinate ComputeCentroid(List<GeoCoordinate> polygon)
Parameters
Type | Name | Description |
---|---|---|
List<GeoCoordinate> | polygon | The list of the polygon coordinates. |
Returns
Type | Description |
---|---|
GeoCoordinate | The centroid of the polygon. |
CopyComponent(Component, Component)
Copies a component and its values within this game object.
Declaration
public static Component CopyComponent(Component comp, Component target)
Parameters
Type | Name | Description |
---|---|---|
Component | comp | The component to copy. |
Component | target |
Returns
Type | Description |
---|---|
Component | The new copy of the component. |
DegreeToRadian(double)
Converts degree to radian.
Declaration
public static double DegreeToRadian(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle as degree. |
Returns
Type | Description |
---|---|
double | The angle as radian. |
ForEachCoordinateOverlapAsync(int, Vector2Int, Action<bool, Vector2Int, Vector2Int>, bool, CancellationToken)
Traverses all cells of a not further specified square grid (i.e. a two dimensional buffer) and calls a function that has the offset to a second square grid as a parameter.
Declaration
public static UniTask ForEachCoordinateOverlapAsync(int resolution, Vector2Int offset, Action<bool, Vector2Int, Vector2Int> function, bool processOverlapOnly = false, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
int | resolution | The resolution of both square grids. |
Vector2Int | offset | The offset between two square grids. |
Action<bool, Vector2Int, Vector2Int> | function | The function to be called. The parameters are: A bool to state whether this cell overlaps. A vector to the cell position that is visited in the first grid. A vector to the overlapping cell position the second grid. |
bool | processOverlapOnly | Calls the function only for overlapping regions. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask |
ForEachEvenlyDistributedStep(double, double, Action<double>)
A loop over evenly distributed steps along a given distance.
Declaration
public static void ForEachEvenlyDistributedStep(double maxStepSize, double totalDistance, Action<double> function)
Parameters
Type | Name | Description |
---|---|---|
double | maxStepSize | The maximum step size. |
double | totalDistance | The total distance to cover. |
Action<double> | function | The function to call per step. |
GetSpiralLoopIndices(int)
Creates spiral loop indices.
Declaration
public static List<int[]> GetSpiralLoopIndices(int radius)
Parameters
Type | Name | Description |
---|---|---|
int | radius | The spiral radius >=0. |
Returns
Type | Description |
---|---|
List<int[]> | A list containing spiral loop indices. |
GreatestCommonDivisor(int, int)
Computes the greatest common divisor.
Declaration
public static int GreatestCommonDivisor(int a, int b)
Parameters
Type | Name | Description |
---|---|---|
int | a | The first value. |
int | b | The second value. |
Returns
Type | Description |
---|---|
int | The greatest common divisor of a and b. |
HaltonSequence(float, float)
Calculates a value of the halton sequence based on an index and base value.
Declaration
public static float HaltonSequence(float index, float haltonBase)
Parameters
Type | Name | Description |
---|---|---|
float | index | The index value. |
float | haltonBase | The base value. |
Returns
Type | Description |
---|---|
float | The resulting value of the halton sequence. |
InverseLerp(double, double, double)
Inverse lerps between two double values.
Declaration
public static double InverseLerp(double a, double b, double v)
Parameters
Type | Name | Description |
---|---|---|
double | a | First bound. |
double | b | Second bound. |
double | v | The in-between value. |
Returns
Type | Description |
---|---|
double | The ratio where v splits the interval between a and b. |
InverseLerp(Vector2, Vector2, Vector2)
Inverse lerps between two Vector2 values.
Declaration
public static Vector2 InverseLerp(Vector2 a, Vector2 b, Vector2 v)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | a | First bound. |
Vector2 | b | Second bound. |
Vector2 | v | The in-between value. |
Returns
Type | Description |
---|---|
Vector2 | The ratio where v splits the interval between a and b. |
IsWithinArea(Vector2, Vector2, float, float)
Determines whether a position is inside defined area.
Declaration
public static bool IsWithinArea(Vector2 position, Vector2 center, float extend, float margin = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | position | The position to check. |
Vector2 | center | The center of the area. |
float | extend | The extend in x and y direction. |
float | margin | An optional margin. |
Returns
Type | Description |
---|---|
bool | Whether the position inside the given area. |
KilometersPerHourToMetersPerSecond(float)
Converts km/h into m/s.
Declaration
public static float KilometersPerHourToMetersPerSecond(float kilometersPerHour)
Parameters
Type | Name | Description |
---|---|---|
float | kilometersPerHour | The speed value in km/h. |
Returns
Type | Description |
---|---|
float | The speed value in m/s. |
KnutHash(int)
Computes a knut-hash.
Declaration
public static int KnutHash(int value)
Parameters
Type | Name | Description |
---|---|---|
int | value | The value to hash. |
Returns
Type | Description |
---|---|
int | The hashed value. |
KnutHash(long)
Computes a knut-hash.
Declaration
public static long KnutHash(long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | The value to hash. |
Returns
Type | Description |
---|---|
long | The hashed value. |
KnutHash(Vector2Int)
Computes a knut-hash from a Vector2Int.
Declaration
public static int KnutHash(Vector2Int value)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | value | The value to hash. |
Returns
Type | Description |
---|---|
int | The hashed value. |
Lerp(double, double, double)
Lerps between two double values.
Declaration
public static double Lerp(double a, double b, double t)
Parameters
Type | Name | Description |
---|---|---|
double | a | First value. |
double | b | Second value. |
double | t | The percentage. |
Returns
Type | Description |
---|---|
double | The lerped value. |
MetersPerSecondToKilometersPerHour(float)
Converts m/s into km/h.
Declaration
public static float MetersPerSecondToKilometersPerHour(float metersPerSecond)
Parameters
Type | Name | Description |
---|---|---|
float | metersPerSecond | The speed value in m/s. |
Returns
Type | Description |
---|---|
float | The speed value in km/h. |
Mod(float, float)
Computes the modulo similar to x % m except the added support for negative values.
Declaration
public static float Mod(float x, float m)
Parameters
Type | Name | Description |
---|---|---|
float | x | The first operand. |
float | m | The second operand. |
Returns
Type | Description |
---|---|
float | The modulo result with support for negative values. |
NormalDistribution(double, double, double)
Calculates a normal distribution, based on a mu-value and a sigma value.
Declaration
public static double NormalDistribution(double x, double mu = 0.5, double sigma = 0.5)
Parameters
Type | Name | Description |
---|---|---|
double | x | |
double | mu | |
double | sigma |
Returns
Type | Description |
---|---|
double |
RadianToDegree(double)
Converts radian to degree.
Declaration
public static double RadianToDegree(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle as radian. |
Returns
Type | Description |
---|---|
double | The angle as degree. |
ResetAnimator(Animator, string)
Resets an animator and all of its parameters.
Declaration
public static void ResetAnimator(Animator animator, string resetTrigger)
Parameters
Type | Name | Description |
---|---|---|
Animator | animator | The animator to reset. |
string | resetTrigger | The trigger to set. |
RoundUpToPowOfTwo(int)
Rounds up a value to the next higher power of two.
Declaration
public static int RoundUpToPowOfTwo(int value)
Parameters
Type | Name | Description |
---|---|---|
int | value | The value to round up. |
Returns
Type | Description |
---|---|
int | The rounded up value. |
RunOnThreadPool(Action, string, CancellationToken)
Utility wrapper for Cysharp.Threading.Tasks.UniTask.RunOnThreadPool(System.Action,System.Boolean,System.Threading.CancellationToken) with Unity profiler support.
Declaration
public static UniTask RunOnThreadPool(Action action, string profilerSectionName = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Action | action | The action to run on the thread pool. |
string | profilerSectionName | An optional name for the action being performed, to allow identification in the profiler. |
CancellationToken | cancellationToken | The cancellation token to observe to cancel the operation on the thread pool. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask | The task to await when waiting for the thread pool task to finish. |
Shuffle<T>(IList<T>, Random)
Shuffles a list.
Declaration
public static void Shuffle<T>(IList<T> list, Random randomGenerator)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The list to shuffle. |
Random | randomGenerator | The randomGenerator. |
Type Parameters
Name | Description |
---|---|
T |
Truncate(double, float)
Truncates a double value to a given number of digits.
Declaration
public static float Truncate(double value, float digits)
Parameters
Type | Name | Description |
---|---|---|
double | value | The double value. |
float | digits | The number of digits. |
Returns
Type | Description |
---|---|
float | The truncated value. |
Vector2ToVector3xz(Vector2)
Maps a vector 3D to the x and z coordinates of a vector 3D.
Declaration
public static Vector3 Vector2ToVector3xz(Vector2 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The 3D vector to map. |
Returns
Type | Description |
---|---|
Vector3 | The mapped vector 3D. |
Vector3xzToVector2(Vector3)
Maps the x and z coordinate to a vector 2D.
Declaration
public static Vector2 Vector3xzToVector2(Vector3 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The 3D vector to map. |
Returns
Type | Description |
---|---|
Vector2 | The mapped vector 2D. |
WaitForThread(Action)
Starts a thread and delays a coroutine until finished.
Declaration
public static IEnumerator WaitForThread(Action function)
Parameters
Type | Name | Description |
---|---|---|
Action | function | The function to run in a thread. |
Returns
Type | Description |
---|---|
IEnumerator |