diff --git a/Assets/Cryville/Common/Buffers/TargetString.cs b/Assets/Cryville/Common/Buffers/TargetString.cs index 78690f9..67fd86a 100644 --- a/Assets/Cryville/Common/Buffers/TargetString.cs +++ b/Assets/Cryville/Common/Buffers/TargetString.cs @@ -73,7 +73,7 @@ namespace Cryville.Common.Buffers { if (!_invalidated) return; _invalidated = false; var ev = OnUpdate; - if (ev != null) OnUpdate.Invoke(); + if (ev != null) ev.Invoke(); } IEnumerator IEnumerable.GetEnumerator() { diff --git a/Assets/Cryville/Common/Math/FractionUtils.cs b/Assets/Cryville/Common/Math/FractionUtils.cs index a2d26ed..b5b8e20 100644 --- a/Assets/Cryville/Common/Math/FractionUtils.cs +++ b/Assets/Cryville/Common/Math/FractionUtils.cs @@ -48,5 +48,31 @@ namespace Cryville.Common.Math { } } } + + /// + /// Gets the greatest common divisor (GCD) of two integers. + /// + /// The first integer. + /// The second integer. + /// The greatest common divisor (GCD) of the two integers. + public static int GreatestCommonDivisor(int n, int d) { + while (d != 0) { + int t = d; + d = n % d; + n = t; + } + return n; + } + + /// + /// Simplifies a fraction. + /// + /// The numerator. + /// The denominator. + public static void Simplify(ref int n, ref int d) { + var gcd = GreatestCommonDivisor(n, d); + n /= gcd; + d /= gcd; + } } }