33// Created by: DavidFDev
44
55using System . Diagnostics . Contracts ;
6+ using System . Runtime . CompilerServices ;
67using UnityEngine ;
78
89namespace DavidFDev . Maths
@@ -22,6 +23,7 @@ public static class MathsHelper
2223 /// <param name="shift"></param>
2324 /// <returns></returns>
2425 [ Pure ]
26+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
2527 public static float Approach ( float start , float end , float shift )
2628 {
2729 if ( start < end )
@@ -40,6 +42,7 @@ public static float Approach(float start, float end, float shift)
4042 /// <param name="shift"></param>
4143 /// <returns></returns>
4244 [ Pure ]
45+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4346 public static float ApproachAngle ( float start , float end , float shift )
4447 {
4548 float deltaAngle = Mathf . DeltaAngle ( start , end ) ;
@@ -58,6 +61,7 @@ public static float ApproachAngle(float start, float end, float shift)
5861 /// <param name="shift"></param>
5962 /// <returns></returns>
6063 [ Pure ]
64+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
6165 public static float Reduce ( float start , float shift )
6266 {
6367 return Approach ( start , 0f , shift ) ;
@@ -70,6 +74,7 @@ public static float Reduce(float start, float shift)
7074 /// <param name="shift"></param>
7175 /// <returns></returns>
7276 [ Pure ]
77+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
7378 public static float ReduceAngle ( float start , float shift )
7479 {
7580 return ApproachAngle ( start , 0f , shift ) ;
@@ -84,6 +89,7 @@ public static float ReduceAngle(float start, float shift)
8489 /// <param name="max"></param>
8590 /// <returns></returns>
8691 [ Pure ]
92+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
8793 public static float Pulse ( float time , float frequency , float min , float max )
8894 {
8995 float half = ( max - min ) * 0.5f ;
@@ -97,6 +103,7 @@ public static float Pulse(float time, float frequency, float min, float max)
97103 /// <param name="frequency">How many false..true..false per second (lower is slower).</param>
98104 /// <returns></returns>
99105 [ Pure ]
106+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
100107 public static bool FlipFlop ( float time , float frequency )
101108 {
102109 return Pulse ( time , frequency , 0f , 1f ) >= 0.5f ;
@@ -109,6 +116,7 @@ public static bool FlipFlop(float time, float frequency)
109116 /// <param name="frequency">Blip speed (lower is slower).</param>
110117 /// <returns></returns>
111118 [ Pure ]
119+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
112120 public static bool Blip ( float time , float frequency )
113121 {
114122 return Pulse ( time , frequency , 0f , 1f ) == 1f ;
@@ -120,6 +128,7 @@ public static bool Blip(float time, float frequency)
120128 /// <param name="value"></param>
121129 /// <returns></returns>
122130 [ Pure ]
131+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
123132 public static float Sign ( float value )
124133 {
125134 return value < 0f ? - 1f : ( value > 0f ? 1f : 0f ) ;
@@ -132,6 +141,7 @@ public static float Sign(float value)
132141 /// <param name="threshold"></param>
133142 /// <returns></returns>
134143 [ Pure ]
144+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
135145 public static float SignThreshold ( float value , float threshold )
136146 {
137147 return Mathf . Abs ( value ) >= threshold ? Sign ( value ) : 0f ;
@@ -143,6 +153,7 @@ public static float SignThreshold(float value, float threshold)
143153 /// <param name="value"></param>
144154 /// <returns></returns>
145155 [ Pure ]
156+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
146157 public static Vector2 Sign ( Vector2 value )
147158 {
148159 return new Vector2 ( Sign ( value . x ) , Sign ( value . y ) ) ;
@@ -154,6 +165,7 @@ public static Vector2 Sign(Vector2 value)
154165 /// <param name="value"></param>
155166 /// <returns></returns>
156167 [ Pure ]
168+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
157169 public static Vector3 Sign ( Vector3 value )
158170 {
159171 return new Vector3 ( Sign ( value . x ) , Sign ( value . y ) , Sign ( value . z ) ) ;
@@ -167,6 +179,7 @@ public static Vector3 Sign(Vector3 value)
167179 /// <param name="max"></param>
168180 /// <returns></returns>
169181 [ Pure ]
182+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
170183 public static bool Between ( float value , float min , float max )
171184 {
172185 return value >= min && value <= max ;
@@ -180,6 +193,7 @@ public static bool Between(float value, float min, float max)
180193 /// <param name="max"></param>
181194 /// <returns></returns>
182195 [ Pure ]
196+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
183197 public static bool Between ( int value , int min , int max )
184198 {
185199 return value >= min && value <= max ;
@@ -191,6 +205,7 @@ public static bool Between(int value, int min, int max)
191205 /// <param name="value"></param>
192206 /// <returns></returns>
193207 [ Pure ]
208+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
194209 public static bool IsEven ( int value )
195210 {
196211 return value % 2 == 0 ;
@@ -202,6 +217,7 @@ public static bool IsEven(int value)
202217 /// <param name="value"></param>
203218 /// <returns></returns>
204219 [ Pure ]
220+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
205221 public static bool IsOdd ( int value )
206222 {
207223 return ! IsEven ( value ) ;
@@ -215,6 +231,7 @@ public static bool IsOdd(int value)
215231 /// <param name="max"></param>
216232 /// <returns></returns>
217233 [ Pure ]
234+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
218235 public static float Map01 ( float value , float min , float max )
219236 {
220237 return ( value - min ) * 1f / ( max - min ) ;
@@ -228,6 +245,7 @@ public static float Map01(float value, float min, float max)
228245 /// <param name="max"></param>
229246 /// <returns></returns>
230247 [ Pure ]
248+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
231249 public static float Map10 ( float value , float min , float max )
232250 {
233251 return 1f - Map01 ( value , min , max ) ;
@@ -243,6 +261,7 @@ public static float Map10(float value, float min, float max)
243261 /// <param name="to2"></param>
244262 /// <returns></returns>
245263 [ Pure ]
264+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
246265 public static float Map ( float value , float from1 , float from2 , float to1 , float to2 )
247266 {
248267 return ( value - from1 ) / ( to1 - from1 ) * ( to2 - from2 ) + from2 ;
@@ -254,6 +273,7 @@ public static float Map(float value, float from1, float from2, float to1, float
254273 /// <param name="degrees"></param>
255274 /// <returns></returns>
256275 [ Pure ]
276+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
257277 public static Vector2 GetDirection ( float degrees )
258278 {
259279 return new Vector2 ( Mathf . Cos ( degrees * Mathf . Deg2Rad ) , Mathf . Sin ( degrees * Mathf . Deg2Rad ) ) ;
@@ -265,6 +285,7 @@ public static Vector2 GetDirection(float degrees)
265285 /// <param name="direction"></param>
266286 /// <returns></returns>
267287 [ Pure ]
288+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
268289 public static float GetAngle ( Vector2 direction )
269290 {
270291 return Mathf . Atan2 ( direction . y , direction . x ) * Mathf . Rad2Deg ;
@@ -277,6 +298,7 @@ public static float GetAngle(Vector2 direction)
277298 /// <param name="directionB"></param>
278299 /// <returns></returns>
279300 [ Pure ]
301+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
280302 public static float GetAngleBetween ( Vector2 directionA , Vector2 directionB )
281303 {
282304 return GetAngle ( directionA - directionB ) ;
@@ -291,6 +313,7 @@ public static float GetAngleBetween(Vector2 directionA, Vector2 directionB)
291313 /// <param name="degrees"></param>
292314 /// <returns></returns>
293315 [ Pure ]
316+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
294317 public static bool WithinAngle ( Vector2 source , Vector2 target , Vector2 coneDirection , float degrees )
295318 {
296319 Vector2 direction = ( target - source ) . normalized ;
@@ -306,6 +329,7 @@ public static bool WithinAngle(Vector2 source, Vector2 target, Vector2 coneDirec
306329 /// <param name="degrees"></param>
307330 /// <returns></returns>
308331 [ Pure ]
332+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
309333 public static Vector2 RotateVector ( Vector2 value , float degrees )
310334 {
311335 return GetDirection ( GetAngle ( value ) + degrees ) ;
@@ -319,6 +343,7 @@ public static Vector2 RotateVector(Vector2 value, float degrees)
319343 /// <param name="pivot"></param>
320344 /// <returns></returns>
321345 [ Pure ]
346+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
322347 public static Vector2 RotateVector ( Vector2 value , float degrees , Vector2 pivot )
323348 {
324349 Vector2 direction = value - pivot ;
0 commit comments