Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Hydrogen.Math Class Reference

Additional static functions used to extend existing Math support inside of Unity. More...

Static Public Member Functions

static float ClampAngle (float angle, float minimumAngle, float maximumAngle)
 Clamp and neutralize an angle. More...
 
static float NeutralizeAngle (float angle)
 Neutralizes the an angle, providing an angle below 360 degrees. More...
 
static float SignedAngle (float angle)
 The signed equivalent of the angle. More...
 
static object ToUnsigned (object value)
 Converts the specified values boxed type to its corresponding unsigned type. More...
 
static long UnboxToLong (object value, bool round)
 Convert object to long value. More...
 
static float UnsignedAngle (float angle)
 The unsigned equivalent of the angle. More...
 

Detailed Description

Additional static functions used to extend existing Math support inside of Unity.

Definition at line 36 of file Math.cs.

Member Function Documentation

static float Hydrogen.Math.ClampAngle ( float  angle,
float  minimumAngle,
float  maximumAngle 
)
static

Clamp and neutralize an angle.

Returns
The clamped and neutralized angle.
Parameters
angleThe source angle.
minimumAngleMinimum angle.
maximumAngleMaximum angle.

Definition at line 45 of file Math.cs.

46  {
47  // Clamp that angle up
48  return UnityEngine.Mathf.Clamp (NeutralizeAngle (angle), minimumAngle, maximumAngle);
49  }
static float NeutralizeAngle(float angle)
Neutralizes the an angle, providing an angle below 360 degrees.
Definition: Math.cs:56
static float Hydrogen.Math.NeutralizeAngle ( float  angle)
static

Neutralizes the an angle, providing an angle below 360 degrees.

Returns
The neutralized angle.
Parameters
angleThe source angle.

Definition at line 56 of file Math.cs.

57  {
58  // Neutralize really fucked up angles
59  if (angle < 0)
60  return (angle % 360f) * -1;
61  else
62  return angle % 360f;
63  }
static float Hydrogen.Math.SignedAngle ( float  angle)
static

The signed equivalent of the angle.

Returns
The signed angle.
Parameters
angleThe source angle.

Definition at line 70 of file Math.cs.

71  {
72  angle = angle % 360f;
73 
74  if (angle > 180f) {
75  return (180 - ((angle % 180f))) * -1f;
76  } else if (angle < -180) {
77  return ((angle % 180) * -1f);
78  }
79  return angle;
80  }
static object Hydrogen.Math.ToUnsigned ( object  value)
static

Converts the specified values boxed type to its corresponding unsigned type.

Returns
A boxed numeric object whos type is unsigned.

This allows for converting without knowing the original type.

Parameters
valueThe value.

Definition at line 88 of file Math.cs.

89  {
90  switch (Type.GetTypeCode (value.GetType ())) {
91  case TypeCode.SByte:
92  return (byte)((sbyte)value);
93  case TypeCode.Int16:
94  return (ushort)((short)value);
95  case TypeCode.Int32:
96  return (uint)((int)value);
97  case TypeCode.Int64:
98  return (ulong)((long)value);
99 
100  case TypeCode.Byte:
101  return value;
102  case TypeCode.UInt16:
103  return value;
104  case TypeCode.UInt32:
105  return value;
106  case TypeCode.UInt64:
107  return value;
108 
109  case TypeCode.Single:
110  return (UInt32)((float)value);
111  case TypeCode.Double:
112  return (ulong)((double)value);
113  case TypeCode.Decimal:
114  return (ulong)((decimal)value);
115 
116  default:
117  return null;
118  }
119  }
static long Hydrogen.Math.UnboxToLong ( object  value,
bool  round 
)
static

Convert object to long value.

Returns
A long value.
Parameters
valueThe object.
roundShould decimals be rounded?

Definition at line 127 of file Math.cs.

128  {
129  switch (Type.GetTypeCode (value.GetType ())) {
130  case TypeCode.SByte:
131  return (long)((sbyte)value);
132  case TypeCode.Int16:
133  return (long)((short)value);
134  case TypeCode.Int32:
135  return (long)((int)value);
136  case TypeCode.Int64:
137  return (long)value;
138 
139  case TypeCode.Byte:
140  return (long)((byte)value);
141  case TypeCode.UInt16:
142  return (long)((ushort)value);
143  case TypeCode.UInt32:
144  return (long)((uint)value);
145  case TypeCode.UInt64:
146  return (long)((ulong)value);
147 
148  case TypeCode.Single:
149  return (round ? (long)System.Math.Round ((float)value) : (long)((float)value));
150  case TypeCode.Double:
151  return (round ? (long)System.Math.Round ((double)value) : (long)((double)value));
152  case TypeCode.Decimal:
153  return (round ? (long)System.Math.Round ((decimal)value) : (long)((decimal)value));
154 
155  default:
156  return 0;
157  }
158  }
static float Hydrogen.Math.UnsignedAngle ( float  angle)
static

The unsigned equivalent of the angle.

Returns
The unsigned angle.
Parameters
angleThe source angle.

Definition at line 165 of file Math.cs.

166  {
167  if (angle < 0f) {
168  if (angle < -360f) {
169  return ((360 + (angle % 360f)) + ((angle - (angle % 360f))) * -1);
170  } else {
171  return 360f + angle;
172  }
173  }
174  return angle;
175  }