77using Mages . Core ;
88using Flow . Launcher . Plugin . Calculator . ViewModels ;
99using Flow . Launcher . Plugin . Calculator . Views ;
10+ using System . IO ;
11+ using System . Net . Quic ;
1012
1113namespace 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