Skip to content

Commit 81d5065

Browse files
Added function to convert rad to deg and vice versa
1 parent 40e5c04 commit 81d5065

File tree

1 file changed

+11
-3
lines changed
  • Plugins/Flow.Launcher.Plugin.Calculator

1 file changed

+11
-3
lines changed

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using Mages.Core;
88
using Flow.Launcher.Plugin.Calculator.ViewModels;
99
using Flow.Launcher.Plugin.Calculator.Views;
10+
using System.IO;
11+
using System.Net.Quic;
1012

1113
namespace Flow.Launcher.Plugin.Calculator
1214
{
@@ -15,12 +17,13 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider
1517
private static readonly Regex RegValidExpressChar = new Regex(
1618
@"^(" +
1719
@"ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|" +
18-
@"sin|cos|tan|arcsin|arccos|arctan|" +
20+
@"sin|cos|tan|arcsin|arccos|arctan|rad2deg|deg2rad|" +
1921
@"eigval|eigvec|eig|sum|polar|plot|round|sort|real|zeta|" +
2022
@"bin2dec|hex2dec|oct2dec|" +
2123
@"factorial|sign|isprime|isinfty|" +
2224
@"==|~=|&&|\|\||(?:\<|\>)=?|" +
2325
@"[ei]|[0-9]|[\+\%\-\*\/\^\., ""]|[\(\)\|\!\[\]]" +
26+
2427
@")+$", RegexOptions.Compiled);
2528
private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
2629
private static Engine MagesEngine;
@@ -44,7 +47,12 @@ public void Init(PluginInitContext context)
4447
{
4548
{ "e", Math.E }, // e is not contained in the default mages engine
4649
}
47-
});
50+
}
51+
);
52+
;
53+
Func<double, double> rad2deg = (rad) => rad * (180.0 / Math.PI);
54+
MagesEngine.SetFunction("rad2deg", rad2deg);
55+
MagesEngine.SetFunction("deg2rad", (double x) => x * (Math.PI / 180.0));
4856
}
4957

5058
public List<Result> Query(Query query)
@@ -68,7 +76,7 @@ public List<Result> Query(Query query)
6876
expression = query.Search;
6977
break;
7078
}
71-
79+
// Replace all spaces in the expression
7280
var result = MagesEngine.Interpret(expression);
7381

7482
if (result?.ToString() == "NaN")

0 commit comments

Comments
 (0)