Class MathHelpers
Static class consisting of mathematical "helper" functions and constants that can be useful for performing operations on a 2D grid.
Inherited Members
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public static class MathHelpers
Fields
View SourceDegreePctOfCircle
Result of 1/360; represents in decimal form a percent of a circle that a degree constitutes.
Declaration
public const double DegreePctOfCircle = 0.002777777777777778
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.29577951308232
Field Value
| Type | Description |
|---|---|
| double |
Methods
View SourceClamp(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(int, int, int)
Restricts a value to a specified range.
Declaration
public static int Clamp(int value, int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to restrict. |
| int | min | The minimum to clamp the value to. |
| int | max | The maximum to clamp the value to. |
Returns
| Type | Description |
|---|---|
| int | The clamped value. |
Clamp(float, float, float)
Restricts a value to a specified range.
Declaration
public static float Clamp(float value, float min, float max)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to restrict. |
| float | min | The minimum to clamp the value to. |
| float | max | The maximum to clamp the value to. |
Returns
| Type | Description |
|---|---|
| float | 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 |
Returns
| Type | Description |
|---|---|
| double | The interpolated value between |
Lerp(float, float, float)
Performs linear interpolation between two values.
Declaration
public static float Lerp(float value1, float value2, float amount)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value1 | Starting value. |
| float | value2 | Ending value. |
| float | amount | The weight to apply to |
Returns
| Type | Description |
|---|---|
| float | The interpolated value between |
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(float, float, float)
Wraps a value around the min and max.
Declaration
public static float Wrap(float value, float min, float max)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to wrap. |
| float | min | The minimum value before it transforms into the maximum. |
| float | max | The maximum value before it transforms into the minimum. |
Returns
| Type | Description |
|---|---|
| float | A new value if it falls outside the min/max range otherwise, the same value. |