# Class MathHelpers

Static class consisting of mathematical "helper" functions and constants -- things like angle unit conversions, and other helpful functions.

**Namespace**: GoRogue

**Assembly**: GoRogue.dll

##### Syntax

`public static class MathHelpers : Object`

### Methods

#### RoundToMultiple(Int32, Int32)

Rounds the given number up (toward highest number), to the nearest multiple of the specified value.

##### Declaration

`public static int RoundToMultiple(int number, int toMultipleOf)`

##### Parameters

Type | Name | Description |
---|---|---|

Int32 | number | Number to round. |

Int32 | toMultipleOf | Number given is rounded up to nearest multiple of this number. |

##### Returns

Type | Description |
---|---|

Int32 | The number parameter, rounded up to the nearest multiple of |

#### ScaledAtan2Approx(Double, Double)

Approximation of the Atan2 function that scales the returned value to the range [0.0, 1.0], in order to remain agnostic of units (radius vs degrees). It will never return a negative number, so is also useful to avoid floating-point modulus. Credit to the SquidLib java RL library and this suggestion from user njuffa for this math.

##### Declaration

`public static double ScaledAtan2Approx(double y, double x)`

##### Parameters

Type | Name | Description |
---|---|---|

Double | y | Y-component of point to find angle towards. |

Double | x | X-component of point to find angle towards. |

##### Returns

Type | Description |
---|---|

Double | A value representing the angle to the given point, scaled to range [0.0, 1.0]. |

#### WrapAround(Double, Double)

Same effect as WrapAround(Int32, Int32), but for doubles.

##### Declaration

`public static double WrapAround(double num, double wrapTo)`

##### Parameters

Type | Name | Description |
---|---|---|

Double | num | The number to wrap. |

Double | wrapTo | The number to wrap to. |

##### Returns

Type | Description |
---|---|

Double | The wrapped result. Guaranteed to lie in range [0, wrapTo). |

#### WrapAround(Int32, Int32)

A modified modulo operator, which practically differs from `num`

% `wrapTo`

in that it wraps from 0 to `wrapTo`

- 1, as well as from `wrapTo`

- 1 to 0.

##### Declaration

`public static int WrapAround(int num, int wrapTo)`

##### Parameters

Type | Name | Description |
---|---|---|

Int32 | num | The number to wrap. |

Int32 | wrapTo | The number to wrap to -- the result of the function is as outlined in function description, and guaranteed to be between [0, wrapTo - 1], inclusive. |

##### Returns

Type | Description |
---|---|

Int32 | The wrapped result, as outlined in function description. Guaranteed to lie in range [0, wrapTo - 1], inclusive. |

##### Remarks

A modified modulo operator. Returns the result of the formula
(`num`

% `wrapTo`

+ `wrapTo`

) % `wrapTo`

.
Practically it differs from regular modulo in that the values it returns when negative values for
`num`

are wrapped around like one would want an array index to (if wrapTo is list.length, -1 wraps to list.length - 1). For
example,
0 % 3 = 0, -1 % 3 = -1, -2 % 3 = -2, -3 % 3 = 0, and so forth, but WrapTo(0, 3) = 0,
WrapTo(-1, 3) = 2, WrapTo(-2, 3) = 1, WrapTo(-3, 3) = 0, and so forth. This can be useful if you're
trying to "wrap" a number around at both ends, for example wrap to 3, such that 3 wraps
to 0, and -1 wraps to 2. This is common if you are wrapping around an array index to the
length of the array and need to ensure that positive numbers greater than or equal to the
length of the array wrap to the beginning of the array (index 0), AND that negative
numbers (under 0) wrap around to the end of the array (Length - 1).