UnityEssentials
Small but useful tools and features for Unity
MathfExtensions.cs
Go to the documentation of this file.
1 using System;
2 
3 namespace UnityEngine
4 {
5 
9 
10  public static class MathfExtensions
11  {
18  public static bool IsMultipleOf(this float v, float n, float tolerance = 0.001f)
19  {
20  return Math.Abs(v % n) < tolerance;
21  }
28  public static bool IsMultipleOf(this float v, int n, float tolerance = 0.001f)
29  {
30  return Math.Abs(Math.Abs(v % n)) < tolerance;
31  }
37  public static bool IsMultipleOf(this int v, int n)
38  {
39  return v % n == 0;
40  }
47  public static bool IsMultipleOf(this int v, float n, float tolerance = 0.001f)
48  {
49  return Math.Abs(Math.Abs(v % n)) < tolerance;
50  }
51  }
52 }
Extensions for the Mathf class
static bool IsMultipleOf(this float v, float n, float tolerance=0.001f)
Calculates if the float is multiple of another float.
static bool IsMultipleOf(this int v, float n, float tolerance=0.001f)
Calculates if the int is multiple of a float.
static bool IsMultipleOf(this int v, int n)
Calculates if the int is multiple of another int.
static bool IsMultipleOf(this float v, int n, float tolerance=0.001f)
Calculates if the float is multiple of an int.