M&B: Bannerlord 1.1.0
The horns sound, the ravens gather.
Loading...
Searching...
No Matches
TaleWorlds.Library.MBMath Class Reference

Static Public Member Functions

static float ToRadians (this float f)
 Converts the degree value to radian value.
 
static float ToDegrees (this float f)
 Converts the radian value to degree value.
 
static bool ApproximatelyEqualsTo (this float f, float comparedValue, float epsilon=MBMath.Epsilon)
 
static bool ApproximatelyEquals (float first, float second, float epsilon=MBMath.Epsilon)
 
static bool IsValidValue (float f)
 Checks the value.
 
static int ClampIndex (int value, int minValue, int maxValue)
 Clamps the input value, max exclusive.
 
static int ClampInt (int value, int minValue, int maxValue)
 Clamps the input value.
 
static float ClampFloat (float value, float minValue, float maxValue)
 Clamps the input value.
 
static void ClampUnit (ref float value)
 Clamps the input value between 0.0f and 1.0f.
 
static int GetNumberOfBitsToRepresentNumber (uint value)
 
static IEnumerable< ValueTuple< T, int > > DistributeShares< T > (int totalAward, IEnumerable< T > stakeHolders, Func< T, int > shareFunction)
 
static int GetNumberOfBitsToRepresentNumber (ulong value)
 
static float Lerp (float valueFrom, float valueTo, float amount, float minimumDifference=Epsilon)
 Linear interpolation between two floating values.
 
static float LinearExtrapolation (float valueFrom, float valueTo, float amount)
 Linear extrapolation with respect to two floating values.
 
static Vec3 Lerp (Vec3 vecFrom, Vec3 vecTo, float amount, float minimumDifference)
 Linear interpolation between two Vec3.
 
static Vec2 Lerp (Vec2 vecFrom, Vec2 vecTo, float amount, float minimumDifference)
 
static float Map (float input, float inputMinimum, float inputMaximum, float outputMinimum, float outputMaximum)
 Re-maps a number from one range to another.
 
static Mat3 Lerp (ref Mat3 matFrom, ref Mat3 matTo, float amount, float minimumDifference)
 Linear interpolation between two Matrices.
 
static float LerpRadians (float valueFrom, float valueTo, float amount, float minChange, float maxChange)
 Linear interpolation between two radian values.
 
static float SplitLerp (float value1, float value2, float value3, float cutOff, float amount, float minimumDifference)
 Linear interpolation between three floating values with a split value.
 
static float InverseLerp (float valueFrom, float valueTo, float value)
 Inverse Linear interpolation between two floating values.
 
static float SmoothStep (float edge0, float edge1, float value)
 SmoothStep performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. 0 when x <= edge0 and 1 when x >= edge1.
 
static float BilinearLerp (float topLeft, float topRight, float botLeft, float botRight, float x, float y)
 Bilinear interpolation between four floating values on a uniform grid.
 
static float GetSmallestDifferenceBetweenTwoAngles (float fromAngle, float toAngle)
 Calculates the (smallest) difference angle between two angles.
 
static float ClampAngle (float angle, float restrictionCenter, float restrictionRange)
 Restricts an angle to a specified portion of a disk, a circular sector.
 
static float WrapAngle (float angle)
 Reduces a given angle to a value between π and -π.
 
static bool IsBetween (float numberToCheck, float bottom, float top)
 
static bool IsBetween (int value, int minValue, int maxValue)
 
static bool IsBetweenInclusive (float numberToCheck, float bottom, float top)
 
static uint ColorFromRGBA (float red, float green, float blue, float alpha)
 
static Color HSBtoRGB (float hue, float saturation, float brightness, float outputAlpha)
 
static Vec3 RGBtoHSB (Color rgb)
 
static Vec3 GammaCorrectRGB (float gamma, Vec3 rgb)
 
static Vec3 GetClosestPointInLineSegmentToPoint (Vec3 point, Vec3 lineSegmentBegin, Vec3 lineSegmentEnd)
 
static bool GetRayPlaneIntersectionPoint (in Vec3 planeNormal, in Vec3 planeCenter, in Vec3 rayOrigin, in Vec3 rayDirection, out float t)
 
static Vec2 GetClosestPointInLineSegmentToPoint (Vec2 point, Vec2 lineSegmentBegin, Vec2 lineSegmentEnd)
 
static bool CheckLineToLineSegmentIntersection (Vec2 lineOrigin, Vec2 lineDirection, Vec2 segmentA, Vec2 segmentB, out float t, out Vec2 intersect)
 Computes intersection of a line (specified by a point on line and direction) with a line segment (specified by two segment points A and B)
 
static float GetClosestPointOnLineSegment (Vec2 point, Vec2 segmentA, Vec2 segmentB, out Vec2 closest)
 
static bool IntersectRayWithBoundaryList (Vec2 rayOrigin, Vec2 rayDir, List< Vec2 > boundaries, out Vec2 intersectionPoint)
 Intersects a ray with the given boundary list (in consecutive point order) and returns true (if intersection exists)
 
static string ToOrdinal (int number)
 Coverts a cardinal number to ordinal.
 
static int IndexOfMax< T > (MBReadOnlyList< T > array, Func< T, int > func)
 
static T MaxElement< T > (IEnumerable< T > collection, Func< T, float > func)
 Return the element that has the top return value for the supplied function.
 
static ValueTuple< T, T > MaxElements2< T > (IEnumerable< T > collection, Func< T, float > func)
 
static ValueTuple< T, T, T > MaxElements3< T > (IEnumerable< T > collection, Func< T, float > func)
 Return the three elements that have the top return values for the supplied function.
 
static ValueTuple< T, T, T, T > MaxElements4< T > (IEnumerable< T > collection, Func< T, float > func)
 Return the four elements that have the top return values for the supplied function.
 
static ValueTuple< T, T, T, T, T > MaxElements5< T > (IEnumerable< T > collection, Func< T, float > func)
 Return the five elements that have the top return values for the supplied function.
 
static IList< T > TopologySort< T > (IEnumerable< T > source, Func< T, IEnumerable< T > > getDependencies)
 Topology sort a list of items. getDependencies func needs to return the same instance of items for comparing.
 

Static Public Attributes

const float TwoPI = (float)(Math.PI * 2)
 
 
const float PI = (float)Math.PI
 π
 
const float HalfPI = (float)(Math.PI * 0.5)
 π / 2
 
const float E = (float)Math.E
 Represents the natural logarithmic base, specified by the constant, e.
 
const float DegreesToRadians = (PI / 180.0f)
 π / 180
 
const float RadiansToDegrees = (180f / PI)
 180 / π
 
const float Epsilon = 0.00001f
 Small positive infinitesimal quantity.
 

Member Function Documentation

◆ ToRadians()

static float TaleWorlds.Library.MBMath.ToRadians ( this float  f)
static
Parameters
f
Returns

◆ ToDegrees()

static float TaleWorlds.Library.MBMath.ToDegrees ( this float  f)
static
Parameters
f
Returns

◆ ApproximatelyEqualsTo()

static bool TaleWorlds.Library.MBMath.ApproximatelyEqualsTo ( this float  f,
float  comparedValue,
float  epsilon = MBMath::Epsilon 
)
static

◆ ApproximatelyEquals()

static bool TaleWorlds.Library.MBMath.ApproximatelyEquals ( float  first,
float  second,
float  epsilon = MBMath::Epsilon 
)
static

◆ IsValidValue()

static bool TaleWorlds.Library.MBMath.IsValidValue ( float  f)
static
Parameters
fValue to be checked.
Returns
true if value is valid float, false if value is NaN (Not A Number).

◆ ClampIndex()

static int TaleWorlds.Library.MBMath.ClampIndex ( int  value,
int  minValue,
int  maxValue 
)
static
Parameters
valueInput value.
minValueThe min value.
maxValueThe max value, exclusive.
Returns
Clamped value.

◆ ClampInt()

static int TaleWorlds.Library.MBMath.ClampInt ( int  value,
int  minValue,
int  maxValue 
)
static
Parameters
valueInput value.
minValueThe min value.
maxValueThe max value.
Returns
Clamped value.

◆ ClampFloat()

static float TaleWorlds.Library.MBMath.ClampFloat ( float  value,
float  minValue,
float  maxValue 
)
static
Parameters
valueInput value.
minValueThe min value.
maxValueThe max value.
Returns
Clamped value.

◆ ClampUnit()

static void TaleWorlds.Library.MBMath.ClampUnit ( ref float  value)
static
Parameters
value

◆ GetNumberOfBitsToRepresentNumber() [1/2]

static int TaleWorlds.Library.MBMath.GetNumberOfBitsToRepresentNumber ( uint  value)
static

◆ DistributeShares< T >()

static IEnumerable< ValueTuple< T, int > > TaleWorlds.Library.MBMath.DistributeShares< T > ( int  totalAward,
IEnumerable< T >  stakeHolders,
Func< T, int >  shareFunction 
)
static

◆ GetNumberOfBitsToRepresentNumber() [2/2]

static int TaleWorlds.Library.MBMath.GetNumberOfBitsToRepresentNumber ( ulong  value)
static

◆ Lerp() [1/4]

static float TaleWorlds.Library.MBMath.Lerp ( float  valueFrom,
float  valueTo,
float  amount,
float  minimumDifference = Epsilon 
)
static
Parameters
valueFromFirst source value.
valueToSecond source value.
amountThe weight of parameter valueTo, such that 0≤x≤1.
minimumDifferenceThe minimum difference that can happen between two values. If difference is less than this value, then valueTo is returned immediately.
Returns
Interpolated value.

◆ LinearExtrapolation()

static float TaleWorlds.Library.MBMath.LinearExtrapolation ( float  valueFrom,
float  valueTo,
float  amount 
)
static
Parameters
valueFromFirst source value.
valueToSecond source value.
amountThe weight of parameter valueTo.
Returns
Extrapolated value.

◆ Lerp() [2/4]

static Vec3 TaleWorlds.Library.MBMath.Lerp ( Vec3  vecFrom,
Vec3  vecTo,
float  amount,
float  minimumDifference 
)
static
Parameters
vecFromFirst source value.
vecToSecond source value.
amountThe weight of parameter valueTo, such that 0≤x≤1.
Returns
Interpolated vector.

◆ Lerp() [3/4]

static Vec2 TaleWorlds.Library.MBMath.Lerp ( Vec2  vecFrom,
Vec2  vecTo,
float  amount,
float  minimumDifference 
)
static

◆ Map()

static float TaleWorlds.Library.MBMath.Map ( float  input,
float  inputMinimum,
float  inputMaximum,
float  outputMinimum,
float  outputMaximum 
)
static
Parameters
inputThe number to map.
inputMinimumThe lower bound of the value’s current range.
inputMaximumThe upper bound of the value’s current range.
outputMinimumThe lower bound of the value’s target range.
outputMaximumThe upper bound of the value’s target range.
Returns
The mapped value

◆ Lerp() [4/4]

static Mat3 TaleWorlds.Library.MBMath.Lerp ( ref Mat3  matFrom,
ref Mat3  matTo,
float  amount,
float  minimumDifference 
)
static
Parameters
matFromFirst source value.
matToSecond source value.
amountThe weight of parameter valueTo, such that 0≤x≤1.
Returns
Interpolated Mat3.

◆ LerpRadians()

static float TaleWorlds.Library.MBMath.LerpRadians ( float  valueFrom,
float  valueTo,
float  amount,
float  minChange,
float  maxChange 
)
static
Parameters
valueFromFirst source value, such that -π≤θ≤π.
valueToSecond source value, such that -π≤θ≤π.
amountThe weight of parameter valueTo, such that 0≤x≤1.
Returns
Interpolated value, such that -π≤θ≤π.

◆ SplitLerp()

static float TaleWorlds.Library.MBMath.SplitLerp ( float  value1,
float  value2,
float  value3,
float  cutOff,
float  amount,
float  minimumDifference 
)
static
Parameters
value1First source value.
value2Second source value.
value3Third source value.
cutOffValue at which to stop lerping from value1 to value2, and go from value2 to value3.
amountThe weight, such that 0≤x≤1.
minimumDifferenceThe minimum difference that can happen between two values. If difference is less than this value, then the current goalValue is returned immediately.
Returns
Interpolated value.

◆ InverseLerp()

static float TaleWorlds.Library.MBMath.InverseLerp ( float  valueFrom,
float  valueTo,
float  value 
)
static
Parameters
valueFromFirst source value.
valueToSecond source value.
valueThe weight of parameter valueTo, such that valueFrom ≤ x ≤ valueTo.
Returns
Inverse interpolated value.

◆ SmoothStep()

static float TaleWorlds.Library.MBMath.SmoothStep ( float  edge0,
float  edge1,
float  value 
)
static
Parameters
edge0Specifies the value of the lower edge of the Hermite function.
edge1Specifies the value of the upper edge of the Hermite function.
valueSpecifies the source value for interpolation.
Returns
Hermite interpolated value between two values

◆ BilinearLerp()

static float TaleWorlds.Library.MBMath.BilinearLerp ( float  topLeft,
float  topRight,
float  botLeft,
float  botRight,
float  x,
float  y 
)
static
Parameters
topLeftFirst source value.
topRightSecond source value.
botLeftThird source value.
botRightFourth source value.
xThe horizontal weight
yThe vertical weight
Returns
Inverse interpolated value.

◆ GetSmallestDifferenceBetweenTwoAngles()

static float TaleWorlds.Library.MBMath.GetSmallestDifferenceBetweenTwoAngles ( float  fromAngle,
float  toAngle 
)
static
Parameters
fromAngleOffset angle, θ, measured in radians, such that -π≤θ≤π.
toAngleTarget angle, θ, measured in radians, such that -π≤θ≤π.
Returns
Difference angle, θ, measured in radians, such that -π≤θ≤π.

◆ ClampAngle()

static float TaleWorlds.Library.MBMath.ClampAngle ( float  angle,
float  restrictionCenter,
float  restrictionRange 
)
static
Parameters
angleThe angle to be restricted, θ, measured in radians, such that -π≤θ≤π.
restrictionCenterAngle of restriction arc's midpoint, θ, measured in radians, such that -π≤θ≤π.
restrictionRangeCentral angle of restriction sector, θ, measured in radians, such that 0<θ≤π/2.
Returns
The restricted angle value, θ, measured in radians, such that -π≤θ≤π.

◆ WrapAngle()

static float TaleWorlds.Library.MBMath.WrapAngle ( float  angle)
static
Parameters
angleThe angle to be reduced, θ, measured in radians.
Returns
The reduced angle, θ, measured in radians, such that -π≤θ≤π.

◆ IsBetween() [1/2]

static bool TaleWorlds.Library.MBMath.IsBetween ( float  numberToCheck,
float  bottom,
float  top 
)
static

◆ IsBetween() [2/2]

static bool TaleWorlds.Library.MBMath.IsBetween ( int  value,
int  minValue,
int  maxValue 
)
static

◆ IsBetweenInclusive()

static bool TaleWorlds.Library.MBMath.IsBetweenInclusive ( float  numberToCheck,
float  bottom,
float  top 
)
static

◆ ColorFromRGBA()

static uint TaleWorlds.Library.MBMath.ColorFromRGBA ( float  red,
float  green,
float  blue,
float  alpha 
)
static

◆ HSBtoRGB()

static Color TaleWorlds.Library.MBMath.HSBtoRGB ( float  hue,
float  saturation,
float  brightness,
float  outputAlpha 
)
static

◆ RGBtoHSB()

static Vec3 TaleWorlds.Library.MBMath.RGBtoHSB ( Color  rgb)
static

◆ GammaCorrectRGB()

static Vec3 TaleWorlds.Library.MBMath.GammaCorrectRGB ( float  gamma,
Vec3  rgb 
)
static

◆ GetClosestPointInLineSegmentToPoint() [1/2]

static Vec3 TaleWorlds.Library.MBMath.GetClosestPointInLineSegmentToPoint ( Vec3  point,
Vec3  lineSegmentBegin,
Vec3  lineSegmentEnd 
)
static

◆ GetRayPlaneIntersectionPoint()

static bool TaleWorlds.Library.MBMath.GetRayPlaneIntersectionPoint ( in Vec3  planeNormal,
in Vec3  planeCenter,
in Vec3  rayOrigin,
in Vec3  rayDirection,
out float  t 
)
static

◆ GetClosestPointInLineSegmentToPoint() [2/2]

static Vec2 TaleWorlds.Library.MBMath.GetClosestPointInLineSegmentToPoint ( Vec2  point,
Vec2  lineSegmentBegin,
Vec2  lineSegmentEnd 
)
static

◆ CheckLineToLineSegmentIntersection()

static bool TaleWorlds.Library.MBMath.CheckLineToLineSegmentIntersection ( Vec2  lineOrigin,
Vec2  lineDirection,
Vec2  segmentA,
Vec2  segmentB,
out float  t,
out Vec2  intersect 
)
static
Returns
Returns intersection parameter t (i.e. lineOrigin + t*lineDir = intersection Point) and intersection point itself.

◆ GetClosestPointOnLineSegment()

static float TaleWorlds.Library.MBMath.GetClosestPointOnLineSegment ( Vec2  point,
Vec2  segmentA,
Vec2  segmentB,
out Vec2  closest 
)
static

◆ IntersectRayWithBoundaryList()

static bool TaleWorlds.Library.MBMath.IntersectRayWithBoundaryList ( Vec2  rayOrigin,
Vec2  rayDir,
List< Vec2 boundaries,
out Vec2  intersectionPoint 
)
static
Returns

◆ ToOrdinal()

static string TaleWorlds.Library.MBMath.ToOrdinal ( int  number)
static
Parameters
numberCardinal number to convert.
Returns
Ordinal version of the given number as string.

◆ IndexOfMax< T >()

static int TaleWorlds.Library.MBMath.IndexOfMax< T > ( MBReadOnlyList< T >  array,
Func< T, int >  func 
)
static

◆ MaxElement< T >()

static T TaleWorlds.Library.MBMath.MaxElement< T > ( IEnumerable< T >  collection,
Func< T, float >  func 
)
static
Template Parameters
T
Parameters
collection
func
Returns

◆ MaxElements2< T >()

static ValueTuple< T, T > TaleWorlds.Library.MBMath.MaxElements2< T > ( IEnumerable< T >  collection,
Func< T, float >  func 
)
static

◆ MaxElements3< T >()

static ValueTuple< T, T, T > TaleWorlds.Library.MBMath.MaxElements3< T > ( IEnumerable< T >  collection,
Func< T, float >  func 
)
static
Template Parameters
T
Parameters
collection
func
Returns

◆ MaxElements4< T >()

static ValueTuple< T, T, T, T > TaleWorlds.Library.MBMath.MaxElements4< T > ( IEnumerable< T >  collection,
Func< T, float >  func 
)
static
Template Parameters
T
Parameters
collection
func
Returns

◆ MaxElements5< T >()

static ValueTuple< T, T, T, T, T > TaleWorlds.Library.MBMath.MaxElements5< T > ( IEnumerable< T >  collection,
Func< T, float >  func 
)
static
Template Parameters
T
Parameters
collection
func
Returns

◆ TopologySort< T >()

static IList< T > TaleWorlds.Library.MBMath.TopologySort< T > ( IEnumerable< T >  source,
Func< T, IEnumerable< T > >  getDependencies 
)
static
Returns

Member Data Documentation

◆ TwoPI

const float TaleWorlds.Library.MBMath.TwoPI = (float)(Math.PI * 2)
static

◆ PI

const float TaleWorlds.Library.MBMath.PI = (float)Math.PI
static

◆ HalfPI

const float TaleWorlds.Library.MBMath.HalfPI = (float)(Math.PI * 0.5)
static

◆ E

const float TaleWorlds.Library.MBMath.E = (float)Math.E
static

◆ DegreesToRadians

const float TaleWorlds.Library.MBMath.DegreesToRadians = (PI / 180.0f)
static

◆ RadiansToDegrees

const float TaleWorlds.Library.MBMath.RadiansToDegrees = (180f / PI)
static

◆ Epsilon

const float TaleWorlds.Library.MBMath.Epsilon = 0.00001f
static