Table of Contents

Class MathExtensions

Namespace
BSGameLib.Core
Assembly
BSGameLib.Core.dll

Extensions for limiting and range-checking numbers.

public static class MathExtensions
Inheritance
MathExtensions
Inherited Members

Methods

Clamp<T>(T, T, T)

Generic method to limit the value of 'val' to be a minimum of 'min' and a maximum of 'max'.

public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>

Parameters

val T

The value to be limited

min T

The minimum value of val.

max T

The maximum value of val.

Returns

T

Returns min if val < min, max if val > max, otherwise val.

Type Parameters

T

Implements IComparable, so any that it is compatible with.

OutOfRangeDefault<T>(T, T, T, T)

Returns defaultValue when val is below min or above max; otherwise returns val. Both bounds are inclusive.

public static T OutOfRangeDefault<T>(this T val, T min, T max, T defaultValue) where T : IComparable<T>

Parameters

val T
min T
max T
defaultValue T

Returns

T

Type Parameters

T