Empeld Empeld plugin documentation.
pluginbase.Helpers.Computative.MExt Class Reference

Math extensions More...

## Static Public Member Functions

static int mmod (int i, int m)
Mod the way every other language does with negative numbers More...

static float mmodNorm (int i, int m)
Mod where the result is normalized between 0-1 More...

static int bounce (int i, int m)
A modulo that bounces back and forth More...

static float FloatRemainder (float val, float div)
Get the remainder of two floats divided by each other i.e. 11/4, has a remainder of 3; or 4 / 1.5 has a remainder of 1 More...

static float NormalizedFloatRemainder (float val, float div)
Gets the normalized (0.0-1.0) value of the divided remainer of two numbers More...

static int NextPow2 (int v)
Gets the next power-of-2. i.e. if 513 was passed in, it'd return 1024 More...

static int FloorInt (float v)
Make a floor of the float and then converts to an int (i.e. 0.5 -> 0, -1.5 -> -2) More...

static int FloorInt (double v)
Fast floor int for double More...

static int CeilInt (float v)
Ceils the int. More...

static int CeilInt (double v)
Ceils the int. More...

static float Fraction (float v)
Gets the fractional part of the value More...

static double Fraction (double v)
Gets the fractional part of the value More...

Radians to degree. More...

static float DegreeToRadian (float degree)
Degrees to radian. More...

Radians to degree. More...

static double DegreeToRadian (double degree)
Degrees to radian. More...

static float Clamp (float v, float min, float max)
Clamp the specified v, min and max. More...

static int Clamp (int v, int min, int max)
Clamp a number between min and max More...

static long Clamp (long v, long min, long max)
Clamp a number between min and max More...

static double Clamp (double v, double min, double max)
Clamp a number between min and max More...

static float ClampUnit (float v)
Clamp a float between 0 and 1, inclusive More...

static double ClampUnit (double v)
Clamp a double between 0 and 1, inclusive More...

static int FloorDiv (int a, int b)
Returns the floor value of the division of two numbers C# Standard specifies that the div op moves the remainder closer to 0, rather than the normal standard (a higher value) More...

static int CeilDiv (int a, int b)
Gets the ceiling of a number that moves towards the higher value, rather than away from 0 More...

static float Normalize (float v, float min, float max)
Scales the values between the max and min to a 0-1 scale eg 0.6 between 0.5 and 1 = 0.2 More...

static double Normalize (double v, double min, double max)
Scales the values between the max and min to a 0-1 scale eg 0.6 between 0.5 and 1 = 0.2 More...

static float NormalizeClamp (float v, float min, float max)
Normalize the value, and clamp between 0 and 1 More...

static double NormalizeClamp (double v, double min, double max)
Normalize the value and clamp between 0 and 1 More...

## Public Attributes

const float Pi = (float)Math.PI
Pi in float form More...

Math extensions

## Member Function Documentation

 static int pluginbase.Helpers.Computative.MExt.bounce ( int i, int m )
static

A modulo that bounces back and forth

Parameters
 i A System.Int32 m A System.Int32
Returns
A System.Int32
72  {
73  return Math.Abs((m-1) - MExt.mmod(i, m*2-1 ));
74  }
 static int pluginbase.Helpers.Computative.MExt.CeilDiv ( int a, int b )
static

Gets the ceiling of a number that moves towards the higher value, rather than away from 0

Returns
The div.
Parameters
 a The alpha component. b The blue component.
360  {
361  return (a ^ b) > 0 && a % b != 0 ? a / b + 1 : a / b;
362  }
 static int pluginbase.Helpers.Computative.MExt.CeilInt ( float v )
static

Ceils the int.

Returns
The int.
Parameters
 v V.
169  {
170  return v < 0f ? (int)v : (int)(v + NEAR_ONE_FLOAT);
171  }
 static int pluginbase.Helpers.Computative.MExt.CeilInt ( double v )
static

Ceils the int.

Returns
The int.
Parameters
 v V.
183  {
184  return v < 0.0 ? (int)v : (int)(v + NEAR_ONE_DOUBLE);
185  }
 static float pluginbase.Helpers.Computative.MExt.Clamp ( float v, float min, float max )
static

Clamp the specified v, min and max.

Parameters
 v V. min Minimum. max Max.
278  {
279  return v < min ? min : (v > max ? max : v);
280  }
 static int pluginbase.Helpers.Computative.MExt.Clamp ( int v, int min, int max )
static

Clamp a number between min and max

Parameters
 v V. min Minimum. max Max.
289  {
290  return v < min ? min : (v > max ? max : v);
291  }
 static long pluginbase.Helpers.Computative.MExt.Clamp ( long v, long min, long max )
static

Clamp a number between min and max

Parameters
 v V. min Minimum. max Max.
300  {
301  return v < min ? min : (v > max ? max : v);
302  }
 static double pluginbase.Helpers.Computative.MExt.Clamp ( double v, double min, double max )
static

Clamp a number between min and max

Parameters
 v V. min Minimum. max Max.
311  {
312  return v < min ? min : (v > max ? max : v);
313  }
 static float pluginbase.Helpers.Computative.MExt.ClampUnit ( float v )
static

Clamp a float between 0 and 1, inclusive

Returns
Clamped value.
Parameters
 v Value
321  {
322  return v < 0f ? 0f : (v > 1f ? 1f : v);
323  }
 static double pluginbase.Helpers.Computative.MExt.ClampUnit ( double v )
static

Clamp a double between 0 and 1, inclusive

Returns
Clamped value
Parameters
 v Value
331  {
332  return v < 0.0 ? 0.0 : (v > 1.0 ? 1.0 : v);
333  }
 static float pluginbase.Helpers.Computative.MExt.DegreeToRadian ( float degree )
static

Returns
Parameters
 degree Degree.
233  {
234  return degree * FLOAT_PI_OVER_180;
235  }
 static double pluginbase.Helpers.Computative.MExt.DegreeToRadian ( double degree )
static

Returns
Parameters
 degree Degree.
261  {
262  return degree * DBL_PI_OVER_180;
263  }
 static float pluginbase.Helpers.Computative.MExt.FloatRemainder ( float val, float div )
static

Get the remainder of two floats divided by each other i.e. 11/4, has a remainder of 3; or 4 / 1.5 has a remainder of 1

Returns
The remainder.
Parameters
 val Value. div Div.
90  {
91  return val - (float)Math.Floor(val/div)*div;
92  }
 static int pluginbase.Helpers.Computative.MExt.FloorDiv ( int a, int b )
static

Returns the floor value of the division of two numbers C# Standard specifies that the div op moves the remainder closer to 0, rather than the normal standard (a higher value)

Returns
The div.
Parameters
 a A. b B.
349  {
350  return (a ^ b) < 0 && a % b != 0 ? a / b -1 : a / b;
351  }
 static int pluginbase.Helpers.Computative.MExt.FloorInt ( float v )
static

Make a floor of the float and then converts to an int (i.e. 0.5 -> 0, -1.5 -> -2)

Returns
The int.
Parameters
 v V.
141  {
142  return v < 0f ? (int)(v - NEAR_ONE_FLOAT) : (int)v;
143  }
 static int pluginbase.Helpers.Computative.MExt.FloorInt ( double v )
static

Fast floor int for double

Returns
The int.
Parameters
 v V.
155  {
156  return v < 0.0 ? (int)(v - NEAR_ONE_DOUBLE) : (int)v;
157  }
 static float pluginbase.Helpers.Computative.MExt.Fraction ( float v )
static

Gets the fractional part of the value

Parameters
 v V.
194  {
195  return v - (int)v;
196  }
 static double pluginbase.Helpers.Computative.MExt.Fraction ( double v )
static

Gets the fractional part of the value

Parameters
 v V.
205  {
206  return v - (int)v;
207  }
 static int pluginbase.Helpers.Computative.MExt.mmod ( int i, int m )
static

Mod the way every other language does with negative numbers

Parameters
 i A System.Int32 m A System.Int32
Returns
A System.Int32
36  {
37  //This method is slightly slower in debug mode, but if it's allowed to JIT
38  //it's absurdly fast.
39  return (i%m+m)%m;
40  }
 static float pluginbase.Helpers.Computative.MExt.mmodNorm ( int i, int m )
static

Mod where the result is normalized between 0-1

Returns
The norm.
Parameters
 i I. m M.
55  {
56  return ((i%m+m)%m) / (float)m;
57  }
 static int pluginbase.Helpers.Computative.MExt.NextPow2 ( int v )
static

Gets the next power-of-2. i.e. if 513 was passed in, it'd return 1024

Returns
The next pow2.
Parameters
 v V.
121  {
122  v--;
123  v |= v >> 1;
124  v |= v >> 2;
125  v |= v >> 4;
126  v |= v >> 8;
127  v |= v >> 16;
128  return v + 1;
129  }
 static float pluginbase.Helpers.Computative.MExt.Normalize ( float v, float min, float max )
static

Scales the values between the max and min to a 0-1 scale eg 0.6 between 0.5 and 1 = 0.2

Parameters
 v V. min Minimum. max Max.
372  {
373  return (v - min) / (max - min);
374  }
 static double pluginbase.Helpers.Computative.MExt.Normalize ( double v, double min, double max )
static

Scales the values between the max and min to a 0-1 scale eg 0.6 between 0.5 and 1 = 0.2

Parameters
 v V. min Minimum. max Max.
384  {
385  return (v - min) / (max - min);
386  }
 static float pluginbase.Helpers.Computative.MExt.NormalizeClamp ( float v, float min, float max )
static

Normalize the value, and clamp between 0 and 1

Returns
The clamp.
Parameters
 v V. min Minimum. max Max.
396  {
397  float x = (v - min) / (max - min);
398  return x < 0f ? 0f : (x > 1f ? 1f : x);
399  }
 static double pluginbase.Helpers.Computative.MExt.NormalizeClamp ( double v, double min, double max )
static

Normalize the value and clamp between 0 and 1

Returns
The clamp.
Parameters
 v V. min Minimum. max Max.
409  {
410  double x = (v - min) / (max - min);
411  return x < 0f ? 0f : (x > 1f ? 1f : x);
412  }
 static float pluginbase.Helpers.Computative.MExt.NormalizedFloatRemainder ( float val, float div )
static

Gets the normalized (0.0-1.0) value of the divided remainer of two numbers

Returns
The float remainder.
Parameters
 val Value. div Div.
107  {
108  return (val - (float)Math.Floor(val/div)*div) / div;
109  }
 static float pluginbase.Helpers.Computative.MExt.RadianToDegree ( float radian )
static

Returns
The to degree.
Parameters
219  {
220  return radian * FLOAT_180_OVER_PI;
221  }
 static double pluginbase.Helpers.Computative.MExt.RadianToDegree ( double radian )
static

Returns
The to degree.
Parameters