Class MathHelper
- Namespace
- VisioForge.Core.Helpers
- Assembly
- VisioForge.Core.dll
Provides mathematical utility methods and extension methods for common mathematical operations.
public static class MathHelperInheritance
Inherited Members
Methods
Clamp<T>(T, T, T)
Clamps a value between a minimum and maximum range.
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>Parameters
valT-
The value to clamp.
minT-
The minimum allowed value.
maxT-
The maximum allowed value.
Returns
- T
-
The clamped value. Returns min if val is less than min, max if val is greater than max, otherwise returns val.
Type Parameters
T-
The type of the value to clamp. Must implement IComparable.
DegreesToRadians(double)
Converts an angle from degrees to radians.
public static double DegreesToRadians(double degrees)Parameters
degreesdouble-
The angle in degrees to convert.
Returns
- double
-
The angle converted to radians.
GenRange(int, int, int)
Generates a sequence of integers within a specified range with a given step size.
public static IEnumerable<int> GenRange(int min, int max, int step)Parameters
minint-
The starting value of the range (inclusive).
maxint-
The ending value of the range (inclusive).
stepint-
The increment between each value in the sequence.
Returns
- IEnumerable<int>
-
An enumerable sequence of integers from min to max with the specified step size.
HighWord(uint)
Extracts the high word (upper 16 bits) from a 32-bit unsigned integer.
public static uint HighWord(this uint number)Parameters
numberuint-
The 32-bit unsigned integer to extract the high word from.
Returns
- uint
-
The upper 16 bits of the input number as a 32-bit unsigned integer.
Hypot(double, double)
Calculates the length of the hypotenuse of a right triangle given the lengths of the two other sides.
public static double Hypot(double x, double y)Parameters
xdouble-
The length of one side of the right triangle.
ydouble-
The length of the other side of the right triangle.
Returns
- double
-
The length of the hypotenuse, calculated as sqrt(x² + y²).
IsIntInRange(int, int, int)
Determines whether an integer value is within a specified range (inclusive).
public static bool IsIntInRange(int value, int min, int max)Parameters
valueint-
The value to check.
minint-
The minimum value of the range (inclusive).
maxint-
The maximum value of the range (inclusive).
Returns
- bool
-
True if the value is within the range [min, max], false otherwise.
LowWord(uint)
Extracts the low word (lower 16 bits) from a 32-bit unsigned integer.
public static uint LowWord(this uint number)Parameters
numberuint-
The 32-bit unsigned integer to extract the low word from.
Returns
- uint
-
The lower 16 bits of the input number as a 32-bit unsigned integer.
RoundToSpecial(int, int)
Rounds a value down to the nearest multiple of a specified number.
public static int RoundToSpecial(int value, int roundTo)Parameters
Returns
- int
-
The value rounded down to the nearest multiple of roundTo.