From 815f48fe06d8919ce7c9dc1a17719f37cb48bb48 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Tue, 13 Dec 2022 09:21:52 +0800 Subject: [PATCH] Update Cryville.Common. --- .../Cryville/Common/Buffers/TargetString.cs | 2 +- Assets/Cryville/Common/Math/FractionUtils.cs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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; + } } }