Skip to content

Commit 989c2e2

Browse files
committed
feat: Add nan or infity
1 parent ddada2a commit 989c2e2

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

Assets/JCSUnity/Scripts/Effects/3D/JCS_3DShakeEffect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private void PlayeSound()
257257
/// <param name="shakeDelta"> Shake delta value. </param>
258258
private void ApplyShakeByTransformType(Vector3 delta)
259259
{
260-
if (JCS_Mathf.IsNaN(delta) || JCS_Mathf.IsInfinity(delta))
260+
if (JCS_Mathf.IsNaNOrInfinity(delta))
261261
return;
262262

263263
switch (this.mTransformType)
@@ -306,7 +306,7 @@ private void ApplyShakeByTransformType(Vector3 delta)
306306
/// <param name="shakeDelta"> Shake delta value. </param>
307307
private void RevertShakeByTransformType(Vector3 delta)
308308
{
309-
if (JCS_Mathf.IsNaN(delta) || JCS_Mathf.IsInfinity(delta))
309+
if (JCS_Mathf.IsNaNOrInfinity(delta))
310310
return;
311311

312312
switch (this.mTransformType)

Assets/JCSUnity/Scripts/Util/JCS_Mathf.cs

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public static Vector3 Floor(Vector3 vec)
6060
/// <summary>
6161
/// Returns f rounded to the nearest integer.
6262
/// </summary>
63-
public static float Round(float f) { return Mathf.Round(f); }
63+
public static float Round(float f)
64+
{
65+
return Mathf.Round(f);
66+
}
6467
public static Vector2 Round(Vector2 vec)
6568
{
6669
return new Vector2(Round(vec.x), Round(vec.y));
@@ -126,7 +129,7 @@ public static Vector3 ToNegative(Vector3 vec3)
126129
}
127130

128131
/// <summary>
129-
/// Check if the value is positive.
132+
/// Return true if the number is positive.
130133
/// </summary>
131134
/// <param name="val"> value to check </param>
132135
/// <returns> true: is positive, false: is negative </returns>
@@ -135,7 +138,7 @@ public static Vector3 ToNegative(Vector3 vec3)
135138
public static bool IsPositive(double val) { return (val > 0.0 && val != 0.0) ? true : false; }
136139

137140
/// <summary>
138-
/// Check if the value is negative.
141+
/// Return true if the number is negative.
139142
/// </summary>
140143
/// <param name="val"> value to check </param>
141144
/// <returns> true: is negative, false: is positive </returns>
@@ -144,7 +147,7 @@ public static Vector3 ToNegative(Vector3 vec3)
144147
public static bool IsNegative(double val) { return (val < 0.0 && val != 0.0) ? true : false; }
145148

146149
/// <summary>
147-
/// To Reverse the value.
150+
/// To reverse the value.
148151
/// </summary>
149152
/// <param name="val"> value to reverse </param>
150153
/// <returns> reverse value </returns>
@@ -153,7 +156,7 @@ public static Vector3 ToNegative(Vector3 vec3)
153156
public static double ToReverse(double val) { return -val; }
154157

155158
/// <summary>
156-
/// Reciprocal of the value
159+
/// To reciprocal of the value.
157160
/// </summary>
158161
/// <param name="val"> value to reciprocal </param>
159162
/// <returns> reciprocal value </returns>
@@ -252,29 +255,6 @@ public static int ApproachTo(int currentVal, int targetVal)
252255
return 0;
253256
}
254257

255-
/// <summary>
256-
/// check if the vector value is infinity
257-
/// </summary>
258-
/// <param name="check"></param>
259-
/// <returns></returns>
260-
public static bool IsInfinity(Vector2 check)
261-
{
262-
return (float.IsInfinity(check.x) ||
263-
float.IsInfinity(check.y));
264-
}
265-
266-
/// <summary>
267-
/// check if the vector value is infinity
268-
/// </summary>
269-
/// <param name="check"></param>
270-
/// <returns></returns>
271-
public static bool IsInfinity(Vector3 check)
272-
{
273-
return (float.IsInfinity(check.x) ||
274-
float.IsInfinity(check.y) ||
275-
float.IsInfinity(check.z));
276-
}
277-
278258
/// <summary>
279259
/// Return min value compare the two pass
280260
/// in values.
@@ -300,31 +280,49 @@ public static float Max(float a, float b)
300280
}
301281

302282
/// <summary>
303-
/// Check if the number is valid.
283+
/// Return true if the number is infinity.
304284
/// </summary>
305-
/// <param name="vec"> vector to check </param>
306-
/// <returns>
307-
/// true: is nan
308-
/// false: valid value
309-
/// </returns>
310-
public static bool IsNaN(Vector3 vec)
285+
public static bool IsInfinity(Vector2 check)
311286
{
312-
return (float.IsNaN(vec.x) || float.IsNaN(vec.y) || float.IsNaN(vec.z));
287+
return (float.IsInfinity(check.x) ||
288+
float.IsInfinity(check.y));
289+
}
290+
public static bool IsInfinity(Vector3 check)
291+
{
292+
return (float.IsInfinity(check.x) ||
293+
float.IsInfinity(check.y) ||
294+
float.IsInfinity(check.z));
313295
}
314296

315297
/// <summary>
316-
/// Check if the number is valid.
298+
/// Return true if the number is NaN.
317299
/// </summary>
318-
/// <param name="vec"> vector to check </param>
319-
/// <returns>
320-
/// true: is nan
321-
/// false: valid value
322-
/// </returns>
300+
public static bool IsNaN(Vector3 vec)
301+
{
302+
return (float.IsNaN(vec.x) || float.IsNaN(vec.y) || float.IsNaN(vec.z));
303+
}
323304
public static bool IsNaN(Vector2 vec)
324305
{
325306
return (float.IsNaN(vec.x) || float.IsNaN(vec.y));
326307
}
327308

309+
/// <summary>
310+
/// Return true if the number is either NaN or infinity.
311+
/// </summary>
312+
public static bool IsNaNOrInfinity(float f)
313+
{
314+
return float.IsNaN(f) || float.IsInfinity(f);
315+
}
316+
public static bool IsNaNOrInfinity(Vector3 vec)
317+
{
318+
return IsNaN(vec) || IsInfinity(vec);
319+
}
320+
public static bool IsNaNOrInfinity(Vector2 vec)
321+
{
322+
return IsNaN(vec) || IsInfinity(vec);
323+
}
324+
325+
328326
/// <summary>
329327
/// Do law of sine.
330328
/// </summary>

0 commit comments

Comments
 (0)