From 81d5065b38f1b56456e4d8fbc3595802276a1e75 Mon Sep 17 00:00:00 2001 From: Koisu Date: Thu, 19 Jun 2025 14:33:24 -0700 Subject: [PATCH 1/4] Added function to convert rad to deg and vice versa --- Plugins/Flow.Launcher.Plugin.Calculator/Main.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index b1e4cd606..be07fd079 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -7,6 +7,8 @@ using System.Windows.Controls; using Mages.Core; using Flow.Launcher.Plugin.Calculator.ViewModels; using Flow.Launcher.Plugin.Calculator.Views; +using System.IO; +using System.Net.Quic; namespace Flow.Launcher.Plugin.Calculator { @@ -15,12 +17,13 @@ namespace Flow.Launcher.Plugin.Calculator private static readonly Regex RegValidExpressChar = new Regex( @"^(" + @"ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|" + - @"sin|cos|tan|arcsin|arccos|arctan|" + + @"sin|cos|tan|arcsin|arccos|arctan|rad2deg|deg2rad|" + @"eigval|eigvec|eig|sum|polar|plot|round|sort|real|zeta|" + @"bin2dec|hex2dec|oct2dec|" + @"factorial|sign|isprime|isinfty|" + @"==|~=|&&|\|\||(?:\<|\>)=?|" + @"[ei]|[0-9]|[\+\%\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + + @")+$", RegexOptions.Compiled); private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); private static Engine MagesEngine; @@ -44,7 +47,12 @@ namespace Flow.Launcher.Plugin.Calculator { { "e", Math.E }, // e is not contained in the default mages engine } - }); + } + ); + ; + Func rad2deg = (rad) => rad * (180.0 / Math.PI); + MagesEngine.SetFunction("rad2deg", rad2deg); + MagesEngine.SetFunction("deg2rad", (double x) => x * (Math.PI / 180.0)); } public List Query(Query query) @@ -68,7 +76,7 @@ namespace Flow.Launcher.Plugin.Calculator expression = query.Search; break; } - + // Replace all spaces in the expression var result = MagesEngine.Interpret(expression); if (result?.ToString() == "NaN") From 4e03b766a99980f2a4bafe21c686340cc6c8e0ab Mon Sep 17 00:00:00 2001 From: Koisu Date: Thu, 19 Jun 2025 14:35:18 -0700 Subject: [PATCH 2/4] cleanup --- Plugins/Flow.Launcher.Plugin.Calculator/Main.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index be07fd079..b2a1c82e3 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -7,8 +7,7 @@ using System.Windows.Controls; using Mages.Core; using Flow.Launcher.Plugin.Calculator.ViewModels; using Flow.Launcher.Plugin.Calculator.Views; -using System.IO; -using System.Net.Quic; + namespace Flow.Launcher.Plugin.Calculator { @@ -23,7 +22,6 @@ namespace Flow.Launcher.Plugin.Calculator @"factorial|sign|isprime|isinfty|" + @"==|~=|&&|\|\||(?:\<|\>)=?|" + @"[ei]|[0-9]|[\+\%\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + - @")+$", RegexOptions.Compiled); private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); private static Engine MagesEngine; @@ -47,9 +45,7 @@ namespace Flow.Launcher.Plugin.Calculator { { "e", Math.E }, // e is not contained in the default mages engine } - } - ); - ; + }); Func rad2deg = (rad) => rad * (180.0 / Math.PI); MagesEngine.SetFunction("rad2deg", rad2deg); MagesEngine.SetFunction("deg2rad", (double x) => x * (Math.PI / 180.0)); @@ -76,7 +72,7 @@ namespace Flow.Launcher.Plugin.Calculator expression = query.Search; break; } - // Replace all spaces in the expression + var result = MagesEngine.Interpret(expression); if (result?.ToString() == "NaN") From 0c34eb0096ce7b45fca6819fac123a38e6a4891b Mon Sep 17 00:00:00 2001 From: Koisu Date: Thu, 19 Jun 2025 14:56:40 -0700 Subject: [PATCH 3/4] fix formatting --- Plugins/Flow.Launcher.Plugin.Calculator/Main.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index b2a1c82e3..bd6067a1c 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -46,8 +46,7 @@ namespace Flow.Launcher.Plugin.Calculator { "e", Math.E }, // e is not contained in the default mages engine } }); - Func rad2deg = (rad) => rad * (180.0 / Math.PI); - MagesEngine.SetFunction("rad2deg", rad2deg); + MagesEngine.SetFunction("rad2deg", (double rad) => rad * (180.0 / Math.PI)); MagesEngine.SetFunction("deg2rad", (double x) => x * (Math.PI / 180.0)); } From 762e1c75c306e9a12ea626db7e810f30fd7183d8 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Fri, 20 Jun 2025 09:01:29 +0800 Subject: [PATCH 4/4] Fix Typo --- Plugins/Flow.Launcher.Plugin.Calculator/Main.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index bd6067a1c..9cd735274 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -172,9 +172,9 @@ namespace Flow.Launcher.Plugin.Calculator private bool IsBracketComplete(string query) { - var matchs = RegBrackets.Matches(query); + var matches = RegBrackets.Matches(query); var leftBracketCount = 0; - foreach (Match match in matchs) + foreach (Match match in matches) { if (match.Value == "(" || match.Value == "[") {