Show / Hide Table of Contents

Class FloatExtensions

Inheritance
System.Object
FloatExtensions
Namespace: Eco.Shared.Math
Assembly: Eco.Shared.dll
Syntax
public static class FloatExtensions : Object

Methods

SetWhenLess(ref Single, Single)

Replaces value with candidate if it is less than value. Shorthand for

var candidate = someFunc();
if (candidate < value)
{
   value = candidate;
   doSomethingElse();
}

may be shortened to

if (value.SetWhenLess(someFunc())) doSomethingElse();
Declaration
public static bool SetWhenLess(this ref float value, float candidate)
Parameters
Type Name Description
System.Single value
System.Single candidate
Returns
Type Description
System.Boolean

true if value was set.

Sign(Single, Single)

Returns value sing with specified tolerance. If absolute value less than tolerance then sign will be assumed to 0.

Declaration
public static int Sign(this float value, float tolerance = 0.05F)
Parameters
Type Name Description
System.Single value
System.Single tolerance
Returns
Type Description
System.Int32

Wrap(Single, Single)

Wraps value to a range starting with 0 and ending with wrapTo. It ensures value in this range and if value is negative it will start from end of range.

For wrapped range we means a some range starting with 0 and ended with concrete end value. I.e. [0, 100) When value wrapped it should be enclosed in this range:

  • reduce it to length of this range with "modulo" operation.
  • if it negative then it should be aligned at the end of range Some examples for range [0, 100): 250 -> 250 % 100 = 50 | - -> 50 -175 -> -175 % 100 = -75 | 100 - 75 = 25 -> 25.
Declaration
public static float Wrap(this float value, float wrapTo)
Parameters
Type Name Description
System.Single value

Value to wrap.

System.Single wrapTo

Ending value of range.

Returns
Type Description
System.Single

Value wrapped to range.

☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾