Skip to main content

class MathEx

(Niantic.Lightship.Maps.Core.Utilities.MathEx)

Overview

Utility class for mathematical functions

class MathEx {
public:
// fields

static const double PI = Math.PI;
static const double HALF_PI = PI / 2.0;
static const double TWO_PI = 2.0* PI;
static const double DEGREES_PER_RADIAN = 180.0 / PI;
static const double RADIANS_PER_DEGREE = PI / 180.0;

// methods

static double DegToRad(double deg);
static double RadToDeg(double rad);
static double Clamp(double var, double min, double max);
static int Clamp(int var, int min, int max);
static double WrapInclusive(double value, double min, double max);
static int WrapInclusive(int value, int min, int max);
static double WrapExclusive(double value, double min, double max);
static int WrapExclusive(int value, int min, int max);
static bool IsBetween(int value, int min, int max);
static bool IsBetween(float value, float min, float max);
static bool IsBetween(double value, double min, double max);
static bool IsBetweenMaxExclusive(int value, int min, int max);
static bool IsBetweenMaxExclusive(float value, float min, float max);
static bool IsBetweenMaxExclusive(double value, double min, double max);

static bool AlmostEqual(
float value1,
float value2,
float tolerance = float.Epsilon
);

static bool AlmostEqual(
double value1,
double value2,
double tolerance = double.Epsilon
);
};

Detailed Documentation

Utility class for mathematical functions

Methods

DegToRad

static double DegToRad(double deg)

Converts between degrees and radians

    Parameters:

    deg -

    Returns:

RadToDeg

static double RadToDeg(double rad)

Converts between radians and degrees

    Parameters:

    rad -

    Returns:

Clamp

static double Clamp(double var, double min, double max)

Clamps the first number within the input range.

    Parameters:

    var -

    min -

    max -

    Returns:

Clamp

static int Clamp(int var, int min, int max)

Clamps the first number within the input range.

    Parameters:

    var -

    min -

    max -

    Returns:

WrapInclusive

static double WrapInclusive(double value, double min, double max)

Wraps a value to within [min, max] (inclusive of max).

    Parameters:

    value - The value to wrap

    min - The minimum value

    max - The maximum value

    Returns:

    A value wrapped to within [min, max]

WrapInclusive

static int WrapInclusive(int value, int min, int max)

Wraps a value to within [min, max] (inclusive of max).

    Parameters:

    value - The value to wrap

    min - The minimum value

    max - The maximum value

    Returns:

    A value wrapped to within [min, max]

WrapExclusive

static double WrapExclusive(double value, double min, double max)

Wraps a value to within [min, max) (not inclusive of max).

    Parameters:

    value - The value to wrap

    min - The minimum value

    max - The maximum value

    Returns:

    A value wrapped to within [min, max)

WrapExclusive

static int WrapExclusive(int value, int min, int max)

Wraps a value to within [min, max) (not inclusive of max).

    Parameters:

    value - The value to wrap

    min - The minimum value

    max - The maximum value

    Returns:

    A value wrapped to within [min, max)

IsBetween

static bool IsBetween(int value, int min, int max)

Checks whether a value is within a given range of [min, max] (inclusive of min and max).

    Parameters:

    value - The value to check

    min - The minimum value

    max - The maximum value

    Returns:

    True if the value is in [min, max]

IsBetween

static bool IsBetween(float value, float min, float max)

Checks whether a value is within a given range of [min, max] (inclusive of min and max).

    Parameters:

    value - The value to check

    min - The minimum value

    max - The maximum value

    Returns:

    True if the value is in [min, max]

IsBetween

static bool IsBetween(double value, double min, double max)

Checks whether a value is within a given range of [min, max] (inclusive of min and max).

    Parameters:

    value - The value to check

    min - The minimum value

    max - The maximum value

    Returns:

    True if the value is in [min, max]

IsBetweenMaxExclusive

static bool IsBetweenMaxExclusive(int value, int min, int max)

Checks whether a value is within a given range of [min, max) (not inclusive of max).

    Parameters:

    value - The value to check

    min - The minimum value

    max - The maximum value

    Returns:

    True if the value is in [min, max)

IsBetweenMaxExclusive

static bool IsBetweenMaxExclusive(float value, float min, float max)

Checks whether a value is within a given range of [min, max) (not inclusive of max).

    Parameters:

    value - The value to check

    min - The minimum value

    max - The maximum value

    Returns:

    True if the value is in [min, max)

IsBetweenMaxExclusive

static bool IsBetweenMaxExclusive(double value, double min, double max)

Checks whether a value is within a given range of [min, max) (not inclusive of max).

    Parameters:

    value - The value to check

    min - The minimum value

    max - The maximum value

    Returns:

    True if the value is in [min, max)

AlmostEqual

static bool AlmostEqual(
float value1,
float value2,
float tolerance = float.Epsilon
)

Checks whether two floating-point values are almost equal, to within a certain degree of tolerance.

    Parameters:

    value1 - The first value to check

    value2 - The second value to check

    tolerance - The amount of tolerance between the two values to be considered equal.

    Returns:

    True if the two values are close enough to be considered equal

AlmostEqual

static bool AlmostEqual(
double value1,
double value2,
double tolerance = double.Epsilon
)

Checks whether two floating-point values are almost equal, to within a certain degree of tolerance.

    Parameters:

    value1 - The first value to check

    value2 - The second value to check

    tolerance - The amount of tolerance between the two values to be considered equal.

    Returns:

    True if the two values are close enough to be considered equal