RoR2-ChensHelpers

Contains simple and useful helpers for RoR2 mod creators to use. Mainly caters to Chen's mods.

View on GitHub

ChensHelpers

Chen.Helpers.MathHelpers.Arithmetic

Arithmetic.Average(float[], Func<float,float>) Method

Computes for the average of the numbers in the array. Preprocessing each item is possible before they are computed by providing the logic.
e.g. Average(new float[] { 2f, -4f, 2f }, item => Mathf.Max(2f, item)) will yield a result of 2f.

public static float Average(this float[] numbers, System.Func<float,float> preProcess=null);

Parameters

numbers System.Single[]
Array of numbers

preProcess System.Func<System.Single,System.Single>
Preprocessor code

Returns

System.Single
Average of the values in the array

Exceptions

System.DivideByZeroException
Raised when the array length is 0 when division is performed.