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 Class

Extensions related to computations involving numbers.

public static class Arithmetic

Inheritance System.Object 🡒 Arithmetic

Methods  
Average(float[], Func<float,float>) 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.
Average(int[], Func<int,int>) 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 int[] { 2, -4, 2 }, item => Mathf.Max(2, item)) will yield a result of 2.
SafeDivide(float, float, float) Performs division with a safety check when the divisor is 0.
The parameter fallbackResult will be returned instead if the divisor is 0.
SafeDivide(int, int, int) Performs division with a safety check when the divisor is 0.
The parameter fallbackResult will be returned instead if the divisor is 0.
Sum(float[], Func<float,float>) Adds all the values contained in the array. Preprocessing each item is possible before they are computed by providing the logic.
e.g. Sum(new float[] { 2f, -4f, 1f }, item => Mathf.Max(0f, item)) will yield a result of 3f.
Sum(int[], Func<int,int>) Adds all the values contained in the array. Preprocessing each item is possible before they are computed by providing the logic.
e.g. Sum(new int[] { 2, -4, 1 }, item => Mathf.Max(0, item)) will yield a result of 3.