Class MathUtil
Inheritance
System.Object
MathUtil
Assembly: Eco.Shared.dll
Syntax
public static class MathUtil : Object
Methods
Approach(Single, Single, Single)
Declaration
public static float Approach(float current, float target, float amount)
Parameters
Type |
Name |
Description |
System.Single |
current |
|
System.Single |
target |
|
System.Single |
amount |
|
Returns
Type |
Description |
System.Single |
|
ApproachValue(Single, Single, Single)
Declaration
public static float ApproachValue(float val, float target, float halflife)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
System.Single |
target |
|
System.Single |
halflife |
|
Returns
Type |
Description |
System.Single |
|
CapAfterPercent(Single, Single, Single, Single)
Declaration
public static float CapAfterPercent(float val, float cap, float startCappingAtPercent = 0.5F, float halflifeAtPercent = 0.5F)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
System.Single |
cap |
|
System.Single |
startCappingAtPercent |
|
System.Single |
halflifeAtPercent |
|
Returns
Type |
Description |
System.Single |
|
CeilToNearestMultiple(Vector2i, Int32)
Declaration
public static Vector2i CeilToNearestMultiple(this Vector2i val, int multiple)
Parameters
Type |
Name |
Description |
Vector2i |
val |
|
System.Int32 |
multiple |
|
Returns
CeilToNearestMultiple(Int32, Int32)
Ceiling that (3,15) return 15. (-3, 15) will return 0.
Declaration
public static int CeilToNearestMultiple(this int val, int multiple)
Parameters
Type |
Name |
Description |
System.Int32 |
val |
|
System.Int32 |
multiple |
|
Returns
Type |
Description |
System.Int32 |
|
ChangeAngleRange180(Vector3)
Declaration
public static Vector3 ChangeAngleRange180(this Vector3 angles)
Parameters
Type |
Name |
Description |
System.Numerics.Vector3 |
angles |
|
Returns
Type |
Description |
System.Numerics.Vector3 |
|
ChangeAngleRange180(Single)
Declaration
public static float ChangeAngleRange180(this float angle)
Parameters
Type |
Name |
Description |
System.Single |
angle |
|
Returns
Type |
Description |
System.Single |
|
Clamp<T>(T, T, T)
Declaration
public static T Clamp<T>(this T current, T min, T max)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
T |
current |
|
T |
min |
|
T |
max |
|
Returns
Type Parameters
ClampDirectionAngleDeg(Vector2, Vector2, Single)
Returns a max possible angle between two vectors
Declaration
public static float ClampDirectionAngleDeg(Vector2 originDirection, Vector2 targetDir, float angleInRad = 0.78F)
Parameters
Type |
Name |
Description |
Vector2 |
originDirection |
|
Vector2 |
targetDir |
|
System.Single |
angleInRad |
|
Returns
Type |
Description |
System.Single |
|
ClampDirectionToOffsetDeg(out Vector2, out Vector2, Vector2, Vector2, Vector2, Int32, Single, Single, Int32, Int32)
Function is finding new target and opposite directions in a curved way (lerping each step)
Declaration
public static void ClampDirectionToOffsetDeg(out Vector2 targetDir, out Vector2 oppositeDir, Vector2 originDirection, Vector2 originalTargetDir, Vector2 originalOppositeDir, int dirSign, float minAngleDeg, float maxAngleDeg, int tries, int tryCount)
Parameters
Type |
Name |
Description |
Vector2 |
targetDir |
|
Vector2 |
oppositeDir |
|
Vector2 |
originDirection |
|
Vector2 |
originalTargetDir |
|
Vector2 |
originalOppositeDir |
|
System.Int32 |
dirSign |
|
System.Single |
minAngleDeg |
|
System.Single |
maxAngleDeg |
|
System.Int32 |
tries |
|
System.Int32 |
tryCount |
|
Clip<T>(T, T, T)
Declaration
public static T Clip<T>(T val, T min, T max)
where T : IComparable
Parameters
Type |
Name |
Description |
T |
val |
|
T |
min |
|
T |
max |
|
Returns
Type Parameters
CloseEnough(Single, Single, Single)
Declaration
public static bool CloseEnough(this float l, float other, float fudgeFactor = 1.401298E-45F)
Parameters
Type |
Name |
Description |
System.Single |
l |
|
System.Single |
other |
|
System.Single |
fudgeFactor |
|
Returns
Type |
Description |
System.Boolean |
|
Compare(Boolean, Boolean, Func<Int32>)
Declaration
public static int Compare(bool a, bool b, Func<int> subCompare = null)
Parameters
Type |
Name |
Description |
System.Boolean |
a |
|
System.Boolean |
b |
|
System.Func<System.Int32> |
subCompare |
|
Returns
Type |
Description |
System.Int32 |
|
Compare(Int32, Int32, Func<Int32>)
Declaration
public static int Compare(int a, int b, Func<int> subCompare = null)
Parameters
Type |
Name |
Description |
System.Int32 |
a |
|
System.Int32 |
b |
|
System.Func<System.Int32> |
subCompare |
|
Returns
Type |
Description |
System.Int32 |
|
Compare(Single, Single, Func<Int32>)
Declaration
public static int Compare(float a, float b, Func<int> subCompare = null)
Parameters
Type |
Name |
Description |
System.Single |
a |
|
System.Single |
b |
|
System.Func<System.Int32> |
subCompare |
|
Returns
Type |
Description |
System.Int32 |
|
CustomHash(Int32[])
Declaration
public static int CustomHash(params int[] vals)
Parameters
Type |
Name |
Description |
System.Int32[] |
vals |
|
Returns
Type |
Description |
System.Int32 |
|
DiminishingReturn(Single, Single)
Declaration
public static float DiminishingReturn(float dimReturn, float val)
Parameters
Type |
Name |
Description |
System.Single |
dimReturn |
|
System.Single |
val |
|
Returns
Type |
Description |
System.Single |
|
Declaration
public static float DiminishingReturnExtra(float dimReturn, float val, float range)
Parameters
Type |
Name |
Description |
System.Single |
dimReturn |
|
System.Single |
val |
|
System.Single |
range |
|
Returns
Type |
Description |
System.Single |
|
DivideAndFloor(Vector2i, Int32)
Declaration
public static Vector2i DivideAndFloor(this Vector2i val, int divisor)
Parameters
Type |
Name |
Description |
Vector2i |
val |
|
System.Int32 |
divisor |
|
Returns
DivideAndFloor(Vector3i, Int32)
Declaration
public static Vector3i DivideAndFloor(this Vector3i val, int divisor)
Parameters
Type |
Name |
Description |
Vector3i |
val |
|
System.Int32 |
divisor |
|
Returns
DivideAndFloor(Int32, Int32)
Unlike a regular division, this will round down, instead of towards zero (IE, negative numbers round up when there is a remainder)
Declaration
public static int DivideAndFloor(this int val, int divisor)
Parameters
Type |
Name |
Description |
System.Int32 |
val |
|
System.Int32 |
divisor |
|
Returns
Type |
Description |
System.Int32 |
|
FloorToNearestMultiple(Vector2i, Int32)
Declaration
public static Vector2i FloorToNearestMultiple(this Vector2i val, int multiple)
Parameters
Type |
Name |
Description |
Vector2i |
val |
|
System.Int32 |
multiple |
|
Returns
FloorToNearestMultiple(Int32, Int32)
Floor that (3, 15) return 0. (-3, 15) return -15
Declaration
public static int FloorToNearestMultiple(this int val, int multiple)
Parameters
Type |
Name |
Description |
System.Int32 |
val |
|
System.Int32 |
multiple |
|
Returns
Type |
Description |
System.Int32 |
|
Fract(Double)
Declaration
public static double Fract(double v)
Parameters
Type |
Name |
Description |
System.Double |
v |
|
Returns
Type |
Description |
System.Double |
|
GetAnalysisValue(AnalysisValue, IEnumerable<Single>)
Declaration
public static float GetAnalysisValue(this AnalysisValue analysis, IEnumerable<float> values)
Parameters
Type |
Name |
Description |
AnalysisValue |
analysis |
|
System.Collections.Generic.IEnumerable<System.Single> |
values |
|
Returns
Type |
Description |
System.Single |
|
GetPercentThrough(Double, Double, Double, Boolean)
Declaration
public static double GetPercentThrough(double val, double min, double max, bool clamp)
Parameters
Type |
Name |
Description |
System.Double |
val |
|
System.Double |
min |
|
System.Double |
max |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Double |
|
GetPercentThrough(Int64, Int64, Int64, Boolean)
Declaration
public static float GetPercentThrough(long val, long min, long max, bool clamp)
Parameters
Type |
Name |
Description |
System.Int64 |
val |
|
System.Int64 |
min |
|
System.Int64 |
max |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Single |
|
GetPercentThrough(Single, Single, Single, Boolean)
Declaration
public static float GetPercentThrough(float val, float min, float max, bool clamp)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
System.Single |
min |
|
System.Single |
max |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Single |
|
InFront(Vector3, Vector3, Vector3)
Declaration
public static bool InFront(Vector3 a, Vector3 facing, Vector3 b)
Parameters
Type |
Name |
Description |
System.Numerics.Vector3 |
a |
|
System.Numerics.Vector3 |
facing |
|
System.Numerics.Vector3 |
b |
|
Returns
Type |
Description |
System.Boolean |
|
Interpolate(Single, Single, Single, Boolean)
Declaration
public static float Interpolate(float percent, float min, float max, bool clamp = true)
Parameters
Type |
Name |
Description |
System.Single |
percent |
|
System.Single |
min |
|
System.Single |
max |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Single |
|
IsCircleInBox(Vector2, Single, Vector2, Single)
Declaration
public static bool IsCircleInBox(Vector2 circleCenter, float circleRadius, Vector2 boxCenter, float side)
Parameters
Type |
Name |
Description |
Vector2 |
circleCenter |
|
System.Single |
circleRadius |
|
Vector2 |
boxCenter |
|
System.Single |
side |
|
Returns
Type |
Description |
System.Boolean |
|
IsFurtherFromOrigin(Single, Single)
Declaration
public static bool IsFurtherFromOrigin(float val, float range)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
System.Single |
range |
|
Returns
Type |
Description |
System.Boolean |
|
IsInCenter(Vector3, Vector3, Vector3, Vector3, Single)
Determine whether the point is in the center of a block
Declaration
public static bool IsInCenter(Vector3 size, Vector3 normal, Vector3 scaledHit, Vector3 centerSize = null, float thinSize = 0.4F)
Parameters
Type |
Name |
Description |
System.Numerics.Vector3 |
size |
Size of a block
|
System.Numerics.Vector3 |
normal |
Normal vector of a hit point
|
System.Numerics.Vector3 |
scaledHit |
Position of a hit point scaled to a size
|
System.Numerics.Vector3 |
centerSize |
Size of center on a block (default is 65% of a half)
|
System.Single |
thinSize |
Size of thin block
|
Returns
Type |
Description |
System.Boolean |
|
IsPointInBox(Vector2, Vector2, Single)
Declaration
public static bool IsPointInBox(Vector2 point, Vector2 boxCenter, float side)
Parameters
Type |
Name |
Description |
Vector2 |
point |
|
Vector2 |
boxCenter |
|
System.Single |
side |
|
Returns
Type |
Description |
System.Boolean |
|
IsReal(Vector2)
Declaration
public static bool IsReal(this Vector2 value)
Parameters
Type |
Name |
Description |
Vector2 |
value |
|
Returns
Type |
Description |
System.Boolean |
|
IsReal(Double)
Declaration
public static bool IsReal(this double value)
Parameters
Type |
Name |
Description |
System.Double |
value |
|
Returns
Type |
Description |
System.Boolean |
|
IsReal(Vector3)
Declaration
public static bool IsReal(this Vector3 value)
Parameters
Type |
Name |
Description |
System.Numerics.Vector3 |
value |
|
Returns
Type |
Description |
System.Boolean |
|
IsReal(Single)
Declaration
public static bool IsReal(this float value)
Parameters
Type |
Name |
Description |
System.Single |
value |
|
Returns
Type |
Description |
System.Boolean |
|
Lerp(Double, Double, Double)
Declaration
public static double Lerp(double a, double b, double t)
Parameters
Type |
Name |
Description |
System.Double |
a |
|
System.Double |
b |
|
System.Double |
t |
|
Returns
Type |
Description |
System.Double |
|
Lerp(Double, Double, Single, Boolean)
Declaration
public static double Lerp(double a, double b, float t, bool clamp = false)
Parameters
Type |
Name |
Description |
System.Double |
a |
|
System.Double |
b |
|
System.Single |
t |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Double |
|
Lerp(Single, Single, Single, Boolean)
Declaration
public static float Lerp(float a, float b, float t, bool clamp = false)
Parameters
Type |
Name |
Description |
System.Single |
a |
|
System.Single |
b |
|
System.Single |
t |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Single |
|
LerpToTarget(Single, Single, Single)
Sum source with delta to approach target, without passing it, and respecting absolute value.
Declaration
public static float LerpToTarget(this float source, float target, float delta)
Parameters
Type |
Name |
Description |
System.Single |
source |
|
System.Single |
target |
|
System.Single |
delta |
|
Returns
Type |
Description |
System.Single |
|
MapValue(Double, Double, Double, Double, Double, Boolean)
Declaration
public static double MapValue(double val, double sourceMin, double sourceMax, double targetMin, double targetMax, bool clamp)
Parameters
Type |
Name |
Description |
System.Double |
val |
|
System.Double |
sourceMin |
|
System.Double |
sourceMax |
|
System.Double |
targetMin |
|
System.Double |
targetMax |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Double |
|
MapValue(Single, Single, Single, Single, Single, Boolean)
Declaration
public static float MapValue(float val, float sourceMin, float sourceMax, float targetMin, float targetMax, bool clamp)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
System.Single |
sourceMin |
|
System.Single |
sourceMax |
|
System.Single |
targetMin |
|
System.Single |
targetMax |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Single |
|
MapValuePow(Single, Single, Single, Single, Single, Boolean, Single)
Declaration
public static float MapValuePow(float val, float sourceMin, float sourceMax, float targetMin, float targetMax, bool clamp, float pow = 2F)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
System.Single |
sourceMin |
|
System.Single |
sourceMax |
|
System.Single |
targetMin |
|
System.Single |
targetMax |
|
System.Boolean |
clamp |
|
System.Single |
pow |
|
Returns
Type |
Description |
System.Single |
|
MapValueSin(Single, Single, Single, Single, Single, Boolean)
Declaration
public static float MapValueSin(float val, float sourceMin, float sourceMax, float targetMin, float targetMax, bool clamp)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
System.Single |
sourceMin |
|
System.Single |
sourceMax |
|
System.Single |
targetMin |
|
System.Single |
targetMax |
|
System.Boolean |
clamp |
|
Returns
Type |
Description |
System.Single |
|
Max(Int32[])
Declaration
public static int Max(params int[] values)
Parameters
Type |
Name |
Description |
System.Int32[] |
values |
|
Returns
Type |
Description |
System.Int32 |
|
Min(Int32[])
Declaration
public static int Min(params int[] values)
Parameters
Type |
Name |
Description |
System.Int32[] |
values |
|
Returns
Type |
Description |
System.Int32 |
|
NextSignificantValue(Single)
Declaration
public static float NextSignificantValue(float val)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
Returns
Type |
Description |
System.Single |
|
NormalizeAngle0to360(Single)
Declaration
public static float NormalizeAngle0to360(float angle)
Parameters
Type |
Name |
Description |
System.Single |
angle |
|
Returns
Type |
Description |
System.Single |
|
NormalizeAngleDeg(Vector3, Vector3, Single)
Find a normalized (-1 : 1) angle between two directions. Cuts angle higher than max angle
Declaration
public static float NormalizeAngleDeg(Vector3 originalDirection, Vector3 targetDirection, float maxAngle = 45F)
Parameters
Type |
Name |
Description |
System.Numerics.Vector3 |
originalDirection |
|
System.Numerics.Vector3 |
targetDirection |
|
System.Single |
maxAngle |
|
Returns
Type |
Description |
System.Single |
|
NotReal(Double)
Declaration
public static bool NotReal(this double value)
Parameters
Type |
Name |
Description |
System.Double |
value |
|
Returns
Type |
Description |
System.Boolean |
|
NotReal(Single)
Declaration
public static bool NotReal(this float value)
Parameters
Type |
Name |
Description |
System.Single |
value |
|
Returns
Type |
Description |
System.Boolean |
|
RemovePlotsAndKeepContiguous(HashSet<PlotPos>, Int32, PlotPos)
Remove the given number of plots from position that wont break contiguity, counted from the starting pos, and return them.
Declaration
public static IEnumerable<PlotPos> RemovePlotsAndKeepContiguous(HashSet<PlotPos> positions, int numberOfPosToRemove, PlotPos startingPos)
Parameters
Type |
Name |
Description |
System.Collections.Generic.HashSet<PlotPos> |
positions |
|
System.Int32 |
numberOfPosToRemove |
|
PlotPos |
startingPos |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<PlotPos> |
|
RoundToNearest(Int32, Int32)
Declaration
public static int RoundToNearest(this int val, int nearest)
Parameters
Type |
Name |
Description |
System.Int32 |
val |
|
System.Int32 |
nearest |
|
Returns
Type |
Description |
System.Int32 |
|
SplitPositionsByContiniusIslands(IEnumerable<Vector2i>, Nullable<Vector2i>)
Declaration
public static List<List<Vector2i>> SplitPositionsByContiniusIslands(IEnumerable<Vector2i> existedPos, Nullable<Vector2i> wrapVector = null)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<Vector2i> |
existedPos |
|
System.Nullable<Vector2i> |
wrapVector |
|
Returns
Type |
Description |
System.Collections.Generic.List<System.Collections.Generic.List<Vector2i>> |
|
Square(Single)
Declaration
public static float Square(float a)
Parameters
Type |
Name |
Description |
System.Single |
a |
|
Returns
Type |
Description |
System.Single |
|
StdDev(IEnumerable<Double>)
Declaration
public static double StdDev(this IEnumerable<double> values)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<System.Double> |
values |
|
Returns
Type |
Description |
System.Double |
|
Swap<T>(ref T, ref T)
Declaration
public static void Swap<T>(ref T x, ref T y)
Parameters
Type |
Name |
Description |
T |
x |
|
T |
y |
|
Type Parameters
TotalAverageVector3i(Vector3i, Int32, Vector3i, Int32)
Combine calculate average total from 2 source value of Vector3i
Declaration
public static Vector3i TotalAverageVector3i(Vector3i firstV, int countFirst, Vector3i secondV, int countSecond)
Parameters
Type |
Name |
Description |
Vector3i |
firstV |
|
System.Int32 |
countFirst |
|
Vector3i |
secondV |
|
System.Int32 |
countSecond |
|
Returns
Truncate(Single)
Declaration
public static int Truncate(float val)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
Returns
Type |
Description |
System.Int32 |
|
TruncatePastHundreths(Single)
Declaration
public static float TruncatePastHundreths(this float val)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
Returns
Type |
Description |
System.Single |
|
TruncatePastTenThousandths(Single)
Declaration
public static float TruncatePastTenThousandths(this float val)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
Returns
Type |
Description |
System.Single |
|
TruncatePastTenths(Single)
Declaration
public static float TruncatePastTenths(this float val)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
Returns
Type |
Description |
System.Single |
|
TruncatePastThousandths(Single)
Declaration
public static float TruncatePastThousandths(this float val)
Parameters
Type |
Name |
Description |
System.Single |
val |
|
Returns
Type |
Description |
System.Single |
|
WeightedAverage(Single, Single, Single, Single)
Calculates average value between x
nad y
using value weights.
Formula is following: (x * xWeight + y * yWeight) / (xWeight + yWeight)
.
Declaration
public static float WeightedAverage(float x, float xWeight, float y, float yWeight)
Parameters
Type |
Name |
Description |
System.Single |
x |
|
System.Single |
xWeight |
|
System.Single |
y |
|
System.Single |
yWeight |
|
Returns
Type |
Description |
System.Single |
|