Show / Hide Table of Contents

Class MathHelpers

Static class consisting of mathematical "helper" functions and constants that can be useful for performing operations on a 2D grid.

Inheritance
Object
MathHelpers
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public static class MathHelpers : Object

Fields

DegreePctOfCircle

Result of 1/360; represents in decimal form a percent of a circle that a degree constitutes.

Declaration
public const double DegreePctOfCircle = 0.0027777777777777779
Field Value
Type Description
Double

DegreesToRadiansConstant

Pi / 180. Used to speed up calculations related to circles.

Declaration
public const double DegreesToRadiansConstant = 0.017453292519943295
Field Value
Type Description
Double

RadiansToDegreesConstant

180 / Pi. Used to speed up calculations related to circles.

Declaration
public const double RadiansToDegreesConstant = 57.295779513082323
Field Value
Type Description
Double

Methods

Clamp(Double, Double, Double)

Restricts a value to a specified range.

Declaration
public static double Clamp(double value, double min, double max)
Parameters
Type Name Description
Double value

The value to restrict.

Double min

The minimum to clamp the value to.

Double max

The maximum to clamp the value to.

Returns
Type Description
Double

The clamped value.

Clamp(Int32, Int32, Int32)

Restricts a value to a specified range.

Declaration
public static int Clamp(int value, int min, int max)
Parameters
Type Name Description
Int32 value

The value to restrict.

Int32 min

The minimum to clamp the value to.

Int32 max

The maximum to clamp the value to.

Returns
Type Description
Int32

The clamped value.

Clamp(Single, Single, Single)

Restricts a value to a specified range.

Declaration
public static float Clamp(float value, float min, float max)
Parameters
Type Name Description
Single value

The value to restrict.

Single min

The minimum to clamp the value to.

Single max

The maximum to clamp the value to.

Returns
Type Description
Single

The clamped value.

Lerp(Double, Double, Double)

Performs linear interpolation between two values.

Declaration
public static double Lerp(double value1, double value2, double amount)
Parameters
Type Name Description
Double value1

Starting value.

Double value2

Ending value.

Double amount

The weight to apply to value2.

Returns
Type Description
Double

Lerp(Single, Single, Single)

Performs linear interpolation between two values.

Declaration
public static float Lerp(float value1, float value2, float amount)
Parameters
Type Name Description
Single value1

Starting value.

Single value2

Ending value.

Single amount

The weight to apply to value2.

Returns
Type Description
Single

ToDegree(Double)

Converts given angle from radians to degrees.

Declaration
public static double ToDegree(double radAngle)
Parameters
Type Name Description
Double radAngle

Angle in radians.

Returns
Type Description
Double

The given angle in degrees.

ToRadian(Double)

Converts given angle from degrees to radians.

Declaration
public static double ToRadian(double degAngle)
Parameters
Type Name Description
Double degAngle

Angle in degrees.

Returns
Type Description
Double

The given angle in radians.

Wrap(Single, Single, Single)

Wraps a value around the min and max.

Declaration
public static float Wrap(float value, float min, float max)
Parameters
Type Name Description
Single value

The value to wrap.

Single min

The minimum value before it transforms into the maximum.

Single max

The maximum value before it transforms into the minimum.

Returns
Type Description
Single

A new value if it falls outside the min/max range otherwise, the same value.

In This Article
Back to top Generated by DocFX