Show / Hide Table of Contents

Class MathHelpers

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

Inheritance
System.Object
MathHelpers
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
public static class MathHelpers

Fields

| Improve this Doc View Source

DEGREE_PCT_OF_CIRCLE

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

Declaration
public const double DEGREE_PCT_OF_CIRCLE = 0.0027777777777777779
Field Value
Type Description
System.Double

Methods

| Improve this Doc View Source

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
System.Int32 number

Number to round.

System.Int32 toMultipleOf

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

Returns
Type Description
System.Int32

The number parameter, rouded up to the nearest multiple of toMultipleOf.

| Improve this Doc View Source

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
System.Double y

Y-component of point to find angle towards.

System.Double x

X-component of point to find angle towards.

Returns
Type Description
System.Double

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

| Improve this Doc View Source

ToDegree(Double)

Converts given angle from radians to degrees.

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

Angle in radians.

Returns
Type Description
System.Double

The given angle in degrees.

| Improve this Doc View Source

ToRadian(Double)

Converts given angle from degrees to radians.

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

Angle in degrees.

Returns
Type Description
System.Double

The given angle in radians.

| Improve this Doc View Source

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
System.Int32 num

The number to wrap.

System.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
System.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).

  • Improve this Doc
  • View Source
Back to top Generated by DocFX