[PTRun]Add setting for different trigonometric units in Calculator (#36717)
* Added angle units to PowerToys Run Calculator plugin. * Update Resources.resx * Added GitHub SpellCheck rule for 'gradians'. --------- Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
This commit is contained in:
Родитель
1aaf764c14
Коммит
458e5c5509
|
@ -4,12 +4,10 @@ abgr
|
|||
ABlocked
|
||||
ABOUTBOX
|
||||
Abug
|
||||
accctrl
|
||||
Acceleratorkeys
|
||||
ACCEPTFILES
|
||||
ACCESSDENIED
|
||||
ACCESSTOKEN
|
||||
aclapi
|
||||
AClient
|
||||
AColumn
|
||||
acrt
|
||||
|
@ -54,12 +52,9 @@ APIENTRY
|
|||
APIIs
|
||||
Apm
|
||||
APPBARDATA
|
||||
appdata
|
||||
APPEXECLINK
|
||||
Appium
|
||||
APPLICATIONFRAMEHOST
|
||||
appmanifest
|
||||
appmodel
|
||||
APPNAME
|
||||
appref
|
||||
appsettings
|
||||
|
@ -83,11 +78,7 @@ ASSOCSTR
|
|||
ASYNCWINDOWPLACEMENT
|
||||
ASYNCWINDOWPOS
|
||||
atl
|
||||
atlbase
|
||||
atlcom
|
||||
atleast
|
||||
atlfile
|
||||
atlstr
|
||||
ATRIOX
|
||||
aumid
|
||||
Authenticode
|
||||
|
@ -135,7 +126,6 @@ bmi
|
|||
bms
|
||||
BNumber
|
||||
BODGY
|
||||
bootstrapper
|
||||
BOOTSTRAPPERINSTALLFOLDER
|
||||
bostrot
|
||||
BOTTOMALIGN
|
||||
|
@ -163,7 +153,6 @@ CALG
|
|||
callbackptr
|
||||
calpwstr
|
||||
Cangjie
|
||||
caniuse
|
||||
CANRENAME
|
||||
CAPTUREBLT
|
||||
CAPTURECHANGED
|
||||
|
@ -178,11 +167,9 @@ CDeclaration
|
|||
CDEF
|
||||
CElems
|
||||
CENTERALIGN
|
||||
ceq
|
||||
certlm
|
||||
certmgr
|
||||
cfp
|
||||
cguid
|
||||
CHANGECBCHAIN
|
||||
changecursor
|
||||
CHILDACTIVATE
|
||||
|
@ -207,19 +194,16 @@ CLSCTX
|
|||
Clusion
|
||||
cmder
|
||||
CMDNOTFOUNDMODULEINTERFACE
|
||||
Cmds
|
||||
CMIC
|
||||
CMINVOKECOMMANDINFO
|
||||
CMINVOKECOMMANDINFOEX
|
||||
CMock
|
||||
CMONITORS
|
||||
cmph
|
||||
cne
|
||||
CNF
|
||||
coclass
|
||||
codereview
|
||||
Codespaces
|
||||
codicon
|
||||
COINIT
|
||||
colorconv
|
||||
colorformat
|
||||
|
@ -231,18 +215,12 @@ comdef
|
|||
comdlg
|
||||
comexp
|
||||
cominterop
|
||||
commandline
|
||||
commctrl
|
||||
commdlg
|
||||
compmgmt
|
||||
COMPOSITIONFULL
|
||||
comutil
|
||||
CONFIGW
|
||||
CONFLICTINGMODIFIERKEY
|
||||
CONFLICTINGMODIFIERSHORTCUT
|
||||
CONOUT
|
||||
consts
|
||||
contentdialog
|
||||
contentfiles
|
||||
CONTEXTHELP
|
||||
CONTEXTMENUHANDLER
|
||||
|
@ -257,7 +235,6 @@ countof
|
|||
cph
|
||||
cplusplus
|
||||
CPower
|
||||
cppwinrt
|
||||
createdump
|
||||
CREATEPROCESS
|
||||
CREATESCHEDULEDTASK
|
||||
|
@ -267,8 +244,6 @@ CRECT
|
|||
CRH
|
||||
critsec
|
||||
Crossdevice
|
||||
CRSEL
|
||||
crx
|
||||
CSearch
|
||||
CSettings
|
||||
cso
|
||||
|
@ -306,11 +281,8 @@ DBLEPSILON
|
|||
DCapture
|
||||
DCBA
|
||||
DCOM
|
||||
dcommon
|
||||
dcomp
|
||||
DComposition
|
||||
DCR
|
||||
DCs
|
||||
ddd
|
||||
DDEIf
|
||||
DDevice
|
||||
|
@ -345,7 +317,6 @@ DESIGNINFO
|
|||
DESKTOPABSOLUTEEDITING
|
||||
DESKTOPABSOLUTEPARSING
|
||||
desktopshorcutinstalled
|
||||
desktopwindowxamlsource
|
||||
devblogs
|
||||
devdocs
|
||||
devenum
|
||||
|
@ -353,7 +324,6 @@ devmgmt
|
|||
DEVMODE
|
||||
DEVMODEW
|
||||
DEVMON
|
||||
devpkey
|
||||
DEVSOURCE
|
||||
DGR
|
||||
DIALOGEX
|
||||
|
@ -423,8 +393,6 @@ DWORDLONG
|
|||
dworigin
|
||||
dwrite
|
||||
dxgi
|
||||
dxgidebug
|
||||
dxgiformat
|
||||
easeofaccess
|
||||
ecount
|
||||
EData
|
||||
|
@ -434,15 +402,12 @@ EDITSHORTCUTS
|
|||
EDITTEXT
|
||||
EFile
|
||||
ekus
|
||||
emmintrin
|
||||
Emoji
|
||||
ENABLEDELAYEDEXPANSION
|
||||
ENABLEDPOPUP
|
||||
ENABLETAB
|
||||
ENABLETEMPLATE
|
||||
encodedlaunch
|
||||
encryptor
|
||||
endpointvolume
|
||||
ENDSESSION
|
||||
ENSUREVISIBLE
|
||||
ENTERSIZEMOVE
|
||||
|
@ -466,7 +431,6 @@ eula
|
|||
eurochange
|
||||
eventlog
|
||||
eventvwr
|
||||
evntrace
|
||||
evt
|
||||
EWXFORCE
|
||||
EWXFORCEIFHUNG
|
||||
|
@ -478,7 +442,6 @@ examplehandler
|
|||
examplepowertoy
|
||||
EXAND
|
||||
EXCLUDEFROMCAPTURE
|
||||
exdisp
|
||||
executionpolicy
|
||||
exename
|
||||
EXITSIZEMOVE
|
||||
|
@ -541,7 +504,6 @@ frm
|
|||
Froml
|
||||
FROMTOUCH
|
||||
fsmgmt
|
||||
Functiondiscoverykeys
|
||||
FZE
|
||||
gacutil
|
||||
Gaeilge
|
||||
|
@ -576,10 +538,10 @@ gpo
|
|||
GPOCA
|
||||
gpp
|
||||
gpu
|
||||
gradians
|
||||
GSM
|
||||
gtm
|
||||
guiddata
|
||||
guiddef
|
||||
GUITHREADINFO
|
||||
GValue
|
||||
gwl
|
||||
|
@ -626,7 +588,6 @@ Hif
|
|||
HIMAGELIST
|
||||
himl
|
||||
hinst
|
||||
hinstance
|
||||
HIWORD
|
||||
HKCC
|
||||
HKCOMB
|
||||
|
@ -659,7 +620,6 @@ hrgn
|
|||
hsb
|
||||
HSCROLL
|
||||
hsi
|
||||
hstring
|
||||
HTCLIENT
|
||||
hthumbnail
|
||||
HTOUCHINPUT
|
||||
|
@ -737,14 +697,12 @@ installscopeperuser
|
|||
INSTALLSTARTMENUSHORTCUT
|
||||
INSTALLSTATE
|
||||
Inste
|
||||
Intelli
|
||||
Interlop
|
||||
INTRESOURCE
|
||||
INVALIDARG
|
||||
invalidoperatioexception
|
||||
ipcmanager
|
||||
IPREVIEW
|
||||
ipreviewhandlervisualssetfont
|
||||
irprops
|
||||
isbi
|
||||
ISearch
|
||||
|
@ -769,7 +727,6 @@ jpe
|
|||
jpnime
|
||||
Jsons
|
||||
jsonval
|
||||
junja
|
||||
jxr
|
||||
keybd
|
||||
KEYBDDATA
|
||||
|
@ -787,7 +744,6 @@ keyvault
|
|||
KILLFOCUS
|
||||
killrunner
|
||||
kmph
|
||||
Knownfolders
|
||||
KSPROPERTY
|
||||
Kybd
|
||||
lastcodeanalysissucceeded
|
||||
|
@ -818,7 +774,6 @@ LIVEZOOM
|
|||
lld
|
||||
LLKH
|
||||
llkhf
|
||||
lmcons
|
||||
LMEM
|
||||
LMENU
|
||||
lnks
|
||||
|
@ -861,7 +816,6 @@ lprc
|
|||
LPSAFEARRAY
|
||||
lpstr
|
||||
lpsz
|
||||
lpt
|
||||
LPTHREAD
|
||||
LPTOP
|
||||
lptpm
|
||||
|
@ -920,18 +874,13 @@ MERGECOPY
|
|||
MERGEPAINT
|
||||
Metadatas
|
||||
metafile
|
||||
mfapi
|
||||
mfc
|
||||
mfidl
|
||||
mfobjects
|
||||
mfplat
|
||||
mftransform
|
||||
Mgmt
|
||||
mic
|
||||
midl
|
||||
mii
|
||||
mindaro
|
||||
Minimatch
|
||||
Minimizable
|
||||
MINIMIZEBOX
|
||||
MINIMIZEEND
|
||||
|
@ -946,10 +895,8 @@ mlcfg
|
|||
mmc
|
||||
mmcexe
|
||||
MMdd
|
||||
mmdeviceapi
|
||||
mmi
|
||||
mmsys
|
||||
mmsystem
|
||||
mockapi
|
||||
MODALFRAME
|
||||
MODESPRUNED
|
||||
|
@ -976,7 +923,6 @@ mscorlib
|
|||
msctls
|
||||
msdata
|
||||
MSDL
|
||||
msedge
|
||||
MSGFLT
|
||||
msiexec
|
||||
MSIFASTINSTALL
|
||||
|
@ -1030,7 +976,6 @@ netframework
|
|||
netsetup
|
||||
netsh
|
||||
newcolor
|
||||
newdev
|
||||
NEWDIALOGSTYLE
|
||||
NEWFILE
|
||||
newitem
|
||||
|
@ -1057,7 +1002,6 @@ NOCOPYBITS
|
|||
NOCOPYSECURITYATTRIBS
|
||||
NOCRLF
|
||||
nodeca
|
||||
nodoc
|
||||
NODRAWCAPTION
|
||||
NODRAWICON
|
||||
NOINHERITLAYOUT
|
||||
|
@ -1095,7 +1039,6 @@ NOTIFICATIONSDLL
|
|||
NOTIFYICONDATA
|
||||
NOTIFYICONDATAW
|
||||
NOTIMPL
|
||||
notlike
|
||||
NOTOPMOST
|
||||
NOTRACK
|
||||
NOTSRCCOPY
|
||||
|
@ -1108,15 +1051,12 @@ NResize
|
|||
nsunt
|
||||
NTAPI
|
||||
ntdll
|
||||
ntfs
|
||||
NTSTATUS
|
||||
NTSYSAPI
|
||||
NULLCURSOR
|
||||
nullonfailure
|
||||
numberbox
|
||||
nwc
|
||||
Objbase
|
||||
objidl
|
||||
ocr
|
||||
Ocrsettings
|
||||
odbccp
|
||||
|
@ -1148,7 +1088,6 @@ osvi
|
|||
OUTOFCONTEXT
|
||||
outpin
|
||||
Outptr
|
||||
outputtype
|
||||
outsettings
|
||||
OVERLAPPEDWINDOW
|
||||
overlaywindow
|
||||
|
@ -1167,7 +1106,6 @@ PARENTRELATIVEPARSING
|
|||
parray
|
||||
PARTIALCONFIRMATIONDIALOGTITLE
|
||||
PATCOPY
|
||||
pathcch
|
||||
PATHMUSTEXIST
|
||||
PATINVERT
|
||||
PATPAINT
|
||||
|
@ -1255,7 +1193,6 @@ pptal
|
|||
ppv
|
||||
prc
|
||||
Prefixer
|
||||
Preinstalled
|
||||
prependpath
|
||||
prevhost
|
||||
previewer
|
||||
|
@ -1272,7 +1209,6 @@ prm
|
|||
proactively
|
||||
PROCESSENTRY
|
||||
PROCESSKEY
|
||||
processthreadsapi
|
||||
PROCESSTRACE
|
||||
procmon
|
||||
PRODEXT
|
||||
|
@ -1282,7 +1218,6 @@ programdata
|
|||
projectname
|
||||
PROPBAG
|
||||
PROPERTYKEY
|
||||
propkey
|
||||
PROPVARIANT
|
||||
propvarutil
|
||||
PRTL
|
||||
|
@ -1346,7 +1281,6 @@ rectp
|
|||
RECTSOURCE
|
||||
recyclebin
|
||||
Redist
|
||||
redistributable
|
||||
reencode
|
||||
reencoded
|
||||
REFCLSID
|
||||
|
@ -1375,10 +1309,8 @@ remoteip
|
|||
Removelnk
|
||||
renamable
|
||||
RENAMEONCOLLISION
|
||||
Renamer
|
||||
reparented
|
||||
reparenting
|
||||
reparse
|
||||
reportfileaccesses
|
||||
requery
|
||||
requerying
|
||||
|
@ -1390,7 +1322,6 @@ RESIZETOFIT
|
|||
resmimetype
|
||||
RESOURCEID
|
||||
RESTORETOMAXIMIZED
|
||||
restrictederrorinfo
|
||||
resultlist
|
||||
RETURNONLYFSDIRS
|
||||
RGBQUAD
|
||||
|
@ -1405,7 +1336,6 @@ riid
|
|||
ringbuffer
|
||||
RKey
|
||||
RNumber
|
||||
roadmap
|
||||
rop
|
||||
ROUNDSMALL
|
||||
rpcrt
|
||||
|
@ -1418,14 +1348,12 @@ rstringalpha
|
|||
rstringdigit
|
||||
RTB
|
||||
RTLREADING
|
||||
ruleset
|
||||
runas
|
||||
rundll
|
||||
rungameid
|
||||
RUNLEVEL
|
||||
runtimeclass
|
||||
runtimepack
|
||||
runtimes
|
||||
ruuid
|
||||
rvm
|
||||
rwin
|
||||
|
@ -1486,21 +1414,17 @@ SHCNE
|
|||
SHCNF
|
||||
SHCONTF
|
||||
Shcore
|
||||
shellapi
|
||||
SHELLDETAILS
|
||||
SHELLDLL
|
||||
shellex
|
||||
SHELLEXECUTEINFO
|
||||
SHELLEXECUTEINFOW
|
||||
shellscalingapi
|
||||
SHFILEINFO
|
||||
SHFILEOPSTRUCT
|
||||
SHGDN
|
||||
SHGDNF
|
||||
SHGFI
|
||||
shinfo
|
||||
shldisp
|
||||
shlobj
|
||||
shlwapi
|
||||
shmem
|
||||
SHNAMEMAPPING
|
||||
|
@ -1628,7 +1552,6 @@ SVGIn
|
|||
SVGIO
|
||||
svgz
|
||||
SVSI
|
||||
SWC
|
||||
SWFO
|
||||
SWP
|
||||
SWRESTORE
|
||||
|
@ -1652,8 +1575,6 @@ SYSMENU
|
|||
SYSTEMAPPS
|
||||
SYSTEMMODAL
|
||||
SYSTEMTIME
|
||||
tailwindcss
|
||||
tapp
|
||||
TApplication
|
||||
TApplied
|
||||
targ
|
||||
|
@ -1694,7 +1615,6 @@ THH
|
|||
THICKFRAME
|
||||
THISCOMPONENT
|
||||
THotkey
|
||||
thumbcache
|
||||
TILEDWINDOW
|
||||
TILLSON
|
||||
timedate
|
||||
|
@ -1708,17 +1628,14 @@ tkconverters
|
|||
TLayout
|
||||
tlb
|
||||
tlbimp
|
||||
tlhelp
|
||||
TMPVAR
|
||||
TNP
|
||||
Toolhelp
|
||||
toolkitconverters
|
||||
Toolset
|
||||
toolwindow
|
||||
TOPDOWNDIB
|
||||
TOUCHEVENTF
|
||||
TOUCHINPUT
|
||||
touchpad
|
||||
TRACEHANDLE
|
||||
tracelogging
|
||||
tracerpt
|
||||
|
@ -1731,7 +1648,6 @@ triaging
|
|||
trl
|
||||
trx
|
||||
tsa
|
||||
Tsd
|
||||
TServer
|
||||
tstoi
|
||||
TStr
|
||||
|
@ -1761,15 +1677,11 @@ UNCPRIORITY
|
|||
UNDNAME
|
||||
unhiding
|
||||
UNICODETEXT
|
||||
uninstantiated
|
||||
uniquifier
|
||||
Uniquifies
|
||||
unitconverter
|
||||
unittests
|
||||
Unknwn
|
||||
UNLEN
|
||||
UNORM
|
||||
unregistering
|
||||
unremapped
|
||||
unvirtualized
|
||||
unwide
|
||||
|
@ -1783,11 +1695,9 @@ updown
|
|||
UPGRADINGPRODUCTCODE
|
||||
Uptool
|
||||
urld
|
||||
urlmon
|
||||
Usb
|
||||
USEDEFAULT
|
||||
USEFILEATTRIBUTES
|
||||
USERDATA
|
||||
USESHOWWINDOW
|
||||
USESTDHANDLES
|
||||
USRDLL
|
||||
|
@ -1814,7 +1724,6 @@ vdupq
|
|||
VERBSONLY
|
||||
VERBW
|
||||
VERIFYCONTEXT
|
||||
verrsrc
|
||||
VERSIONINFO
|
||||
VERTRES
|
||||
VERTSIZE
|
||||
|
@ -1862,7 +1771,6 @@ WANTPALM
|
|||
wbem
|
||||
WBounds
|
||||
Wca
|
||||
wcautil
|
||||
WCE
|
||||
wcex
|
||||
WClass
|
||||
|
@ -1884,10 +1792,7 @@ wifi
|
|||
wil
|
||||
winapi
|
||||
winappsdk
|
||||
wincodec
|
||||
Wincodecsdk
|
||||
wincolor
|
||||
windef
|
||||
windir
|
||||
WINDOWCREATED
|
||||
WINDOWEDGE
|
||||
|
@ -1896,18 +1801,12 @@ WINDOWNAME
|
|||
WINDOWPLACEMENT
|
||||
WINDOWPOSCHANGED
|
||||
WINDOWPOSCHANGING
|
||||
windowsapp
|
||||
WINDOWSBUILDNUMBER
|
||||
windowssearch
|
||||
windowssettings
|
||||
WINDOWSTYLES
|
||||
WINDOWSTYLESICON
|
||||
windowsx
|
||||
winerror
|
||||
WINEVENT
|
||||
winevt
|
||||
winexe
|
||||
winforms
|
||||
winget
|
||||
wingetcreate
|
||||
Winhook
|
||||
|
@ -1918,9 +1817,7 @@ WINNT
|
|||
winres
|
||||
winrt
|
||||
winsdk
|
||||
winsdkver
|
||||
winsta
|
||||
winternl
|
||||
WINTHRESHOLD
|
||||
WINVER
|
||||
winxamlmanager
|
||||
|
@ -1966,14 +1863,12 @@ wrl
|
|||
wscui
|
||||
wsf
|
||||
wsh
|
||||
wsl
|
||||
wstr
|
||||
wsz
|
||||
WTA
|
||||
WTNCA
|
||||
wtoi
|
||||
WTS
|
||||
wtsapi
|
||||
WTSAT
|
||||
Wubi
|
||||
WVC
|
||||
|
|
|
@ -279,5 +279,67 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
|||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(expectedResult, result.Result);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow("sin(90)", "sin((pi / 180) * (90))")]
|
||||
[DataRow("arcsin(0.5)", "(180 / pi) * (arcsin(0.5))")]
|
||||
[DataRow("sin(sin(30))", "sin((pi / 180) * (sin((pi / 180) * (30))))")]
|
||||
[DataRow("cos(tan(45))", "cos((pi / 180) * (tan((pi / 180) * (45))))")]
|
||||
[DataRow("arctan(sin(30))", "(180 / pi) * (arctan(sin((pi / 180) * (30))))")]
|
||||
[DataRow("sin(cos(tan(30)))", "sin((pi / 180) * (cos((pi / 180) * (tan((pi / 180) * (30))))))")]
|
||||
[DataRow("sin(arcsin(0.5))", "sin((pi / 180) * ((180 / pi) * (arcsin(0.5))))")]
|
||||
[DataRow("sin(30) + cos(60)", "sin((pi / 180) * (30)) + cos((pi / 180) * (60))")]
|
||||
[DataRow("sin(30 + 15)", "sin((pi / 180) * (30 + 15))")]
|
||||
[DataRow("sin(45) * cos(45) - tan(30)", "sin((pi / 180) * (45)) * cos((pi / 180) * (45)) - tan((pi / 180) * (30))")]
|
||||
[DataRow("arcsin(arccos(0.5))", "(180 / pi) * (arcsin((180 / pi) * (arccos(0.5))))")]
|
||||
[DataRow("sin(sin(sin(30)))", "sin((pi / 180) * (sin((pi / 180) * (sin((pi / 180) * (30))))))")]
|
||||
[DataRow("log(10)", "log(10)")]
|
||||
[DataRow("sin(30) + pi", "sin((pi / 180) * (30)) + pi")]
|
||||
[DataRow("sin(-30)", "sin((pi / 180) * (-30))")]
|
||||
[DataRow("sin((30))", "sin((pi / 180) * ((30)))")]
|
||||
[DataRow("arcsin(1) * 2", "(180 / pi) * (arcsin(1)) * 2")]
|
||||
[DataRow("cos(1/2)", "cos((pi / 180) * (1/2))")]
|
||||
[DataRow("sin ( 90 )", "sin ((pi / 180) * ( 90 ))")]
|
||||
[DataRow("cos(arcsin(sin(45)))", "cos((pi / 180) * ((180 / pi) * (arcsin(sin((pi / 180) * (45))))))")]
|
||||
public void UpdateTrigFunctions_Degrees(string input, string expectedResult)
|
||||
{
|
||||
// Call UpdateTrigFunctions in degrees mode
|
||||
string result = CalculateHelper.UpdateTrigFunctions(input, CalculateEngine.TrigMode.Degrees);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow("sin(90)", "sin((pi / 200) * (90))")]
|
||||
[DataRow("arcsin(0.5)", "(200 / pi) * (arcsin(0.5))")]
|
||||
[DataRow("sin(sin(30))", "sin((pi / 200) * (sin((pi / 200) * (30))))")]
|
||||
[DataRow("cos(tan(45))", "cos((pi / 200) * (tan((pi / 200) * (45))))")]
|
||||
[DataRow("arctan(sin(30))", "(200 / pi) * (arctan(sin((pi / 200) * (30))))")]
|
||||
[DataRow("sin(cos(tan(30)))", "sin((pi / 200) * (cos((pi / 200) * (tan((pi / 200) * (30))))))")]
|
||||
[DataRow("sin(arcsin(0.5))", "sin((pi / 200) * ((200 / pi) * (arcsin(0.5))))")]
|
||||
[DataRow("sin(30) + cos(60)", "sin((pi / 200) * (30)) + cos((pi / 200) * (60))")]
|
||||
[DataRow("sin(30 + 15)", "sin((pi / 200) * (30 + 15))")]
|
||||
[DataRow("sin(45) * cos(45) - tan(30)", "sin((pi / 200) * (45)) * cos((pi / 200) * (45)) - tan((pi / 200) * (30))")]
|
||||
[DataRow("arcsin(arccos(0.5))", "(200 / pi) * (arcsin((200 / pi) * (arccos(0.5))))")]
|
||||
[DataRow("sin(sin(sin(30)))", "sin((pi / 200) * (sin((pi / 200) * (sin((pi / 200) * (30))))))")]
|
||||
[DataRow("log(10)", "log(10)")]
|
||||
[DataRow("sin(30) + pi", "sin((pi / 200) * (30)) + pi")]
|
||||
[DataRow("sin(-30)", "sin((pi / 200) * (-30))")]
|
||||
[DataRow("sin((30))", "sin((pi / 200) * ((30)))")]
|
||||
[DataRow("arcsin(1) * 2", "(200 / pi) * (arcsin(1)) * 2")]
|
||||
[DataRow("cos(1/2)", "cos((pi / 200) * (1/2))")]
|
||||
[DataRow("sin ( 90 )", "sin ((pi / 200) * ( 90 ))")]
|
||||
[DataRow("cos(arcsin(sin(45)))", "cos((pi / 200) * ((200 / pi) * (arcsin(sin((pi / 200) * (45))))))")]
|
||||
public void UpdateTrigFunctions_Gradians(string input, string expectedResult)
|
||||
{
|
||||
// Call UpdateTrigFunctions in gradians mode
|
||||
string result = CalculateHelper.UpdateTrigFunctions(input, CalculateEngine.TrigMode.Gradians);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,13 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
|
||||
public const int RoundingDigits = 10;
|
||||
|
||||
public enum TrigMode
|
||||
{
|
||||
Radians,
|
||||
Degrees,
|
||||
Gradians,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interpret
|
||||
/// </summary>
|
||||
|
@ -52,6 +59,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
|
||||
input = CalculateHelper.FixHumanMultiplicationExpressions(input);
|
||||
|
||||
// Modify trig functions depending on angle unit setting
|
||||
input = CalculateHelper.UpdateTrigFunctions(input, Main.GetTrigMode());
|
||||
|
||||
var result = _magesEngine.Interpret(input);
|
||||
|
||||
// This could happen for some incorrect queries, like pi(2)
|
||||
|
|
|
@ -25,6 +25,11 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
@")+$",
|
||||
RegexOptions.Compiled);
|
||||
|
||||
private const string DegToRad = "(pi / 180) * ";
|
||||
private const string GradToRad = "(pi / 200) * ";
|
||||
private const string RadToDeg = "(180 / pi) * ";
|
||||
private const string RadToGrad = "(200 / pi) * ";
|
||||
|
||||
public static bool InputValid(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
|
@ -204,5 +209,86 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
// Gets the index of the closing bracket of a function
|
||||
private static int FindClosingBracketIndex(string input, int start)
|
||||
{
|
||||
int bracketCount = 0; // Set count to zero
|
||||
for (int i = start; i < input.Length; i++)
|
||||
{
|
||||
if (input[i] == '(')
|
||||
{
|
||||
bracketCount++;
|
||||
}
|
||||
else if (input[i] == ')')
|
||||
{
|
||||
bracketCount--;
|
||||
if (bracketCount == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1; // Unmatched brackets
|
||||
}
|
||||
|
||||
private static string ModifyTrigFunction(string input, string function, string modification)
|
||||
{
|
||||
// Get the RegEx pattern to match, depending on whether the function is inverse or normal
|
||||
string pattern = function.StartsWith("arc", StringComparison.Ordinal) ? string.Empty : @"(?<!c)";
|
||||
pattern += $@"{function}\s*\(";
|
||||
|
||||
int index = 0; // Index for match to ensure that the same match is not found twice
|
||||
|
||||
Regex regex = new Regex(pattern);
|
||||
Match match;
|
||||
|
||||
while ((match = regex.Match(input, index)).Success)
|
||||
{
|
||||
index = match.Index + match.Groups[0].Length + modification.Length; // Get the next index to look from for further matches
|
||||
|
||||
int endIndex = FindClosingBracketIndex(input, match.Index + match.Groups[0].Length - 1); // Find the index of the closing bracket of the function
|
||||
|
||||
// If no valid bracket index was found, try the next match
|
||||
if (endIndex == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string argument = input.Substring(match.Index + match.Groups[0].Length, endIndex - (match.Index + match.Groups[0].Length)); // Extract the argument between the brackets
|
||||
string replaced = function.StartsWith("arc", StringComparison.Ordinal) ? $"{modification}({match.Groups[0].Value}{argument}))" : $"{match.Groups[0].Value}{modification}({argument}))"; // The string to substitute in, handles differing formats of inverse functions
|
||||
|
||||
input = input.Remove(match.Index, endIndex - match.Index + 1); // Remove the match from the input
|
||||
input = input.Insert(match.Index, replaced); // Substitute with the new string
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
public static string UpdateTrigFunctions(string input, CalculateEngine.TrigMode mode)
|
||||
{
|
||||
string modifiedInput = input;
|
||||
if (mode == CalculateEngine.TrigMode.Degrees)
|
||||
{
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "sin", DegToRad);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "cos", DegToRad);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "tan", DegToRad);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "arcsin", RadToDeg);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "arccos", RadToDeg);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "arctan", RadToDeg);
|
||||
}
|
||||
else if (mode == CalculateEngine.TrigMode.Gradians)
|
||||
{
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "sin", GradToRad);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "cos", GradToRad);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "tan", GradToRad);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "arcsin", RadToGrad);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "arccos", RadToGrad);
|
||||
modifiedInput = ModifyTrigFunction(modifiedInput, "arctan", RadToGrad);
|
||||
}
|
||||
|
||||
return modifiedInput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
private const string InputUseEnglishFormat = nameof(InputUseEnglishFormat);
|
||||
private const string OutputUseEnglishFormat = nameof(OutputUseEnglishFormat);
|
||||
private const string ReplaceInput = nameof(ReplaceInput);
|
||||
private const string TrigMode = nameof(TrigMode);
|
||||
|
||||
private static readonly CalculateEngine CalculateEngine = new CalculateEngine();
|
||||
|
||||
|
@ -31,6 +32,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
private bool _inputUseEnglishFormat;
|
||||
private bool _outputUseEnglishFormat;
|
||||
private bool _replaceInput;
|
||||
private static CalculateEngine.TrigMode _trigMode;
|
||||
|
||||
public string Name => Resources.wox_plugin_calculator_plugin_name;
|
||||
|
||||
|
@ -67,6 +69,20 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
DisplayDescription = Resources.wox_plugin_calculator_replace_input_description,
|
||||
Value = true,
|
||||
},
|
||||
new PluginAdditionalOption
|
||||
{
|
||||
Key = TrigMode,
|
||||
DisplayLabel = Resources.wox_plugin_calculator_trig_unit_mode,
|
||||
DisplayDescription = Resources.wox_plugin_calculator_trig_unit_mode_description,
|
||||
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Combobox,
|
||||
ComboBoxValue = (int)CalculateEngine.TrigMode.Radians,
|
||||
ComboBoxItems =
|
||||
[
|
||||
new KeyValuePair<string, string>(Resources.wox_plugin_calculator_trig_unit_radians, "0"),
|
||||
new KeyValuePair<string, string>(Resources.wox_plugin_calculator_trig_unit_degrees, "1"),
|
||||
new KeyValuePair<string, string>(Resources.wox_plugin_calculator_trig_unit_gradians, "2"),
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
|
@ -183,6 +199,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
var inputUseEnglishFormat = false;
|
||||
var outputUseEnglishFormat = false;
|
||||
var replaceInput = true;
|
||||
var trigMode = CalculateEngine.TrigMode.Radians;
|
||||
|
||||
if (settings != null && settings.AdditionalOptions != null)
|
||||
{
|
||||
|
@ -194,11 +211,20 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|||
|
||||
var optionReplaceInput = settings.AdditionalOptions.FirstOrDefault(x => x.Key == ReplaceInput);
|
||||
replaceInput = optionReplaceInput?.Value ?? replaceInput;
|
||||
|
||||
var optionTrigMode = settings.AdditionalOptions.FirstOrDefault(x => x.Key == TrigMode);
|
||||
trigMode = (CalculateEngine.TrigMode)int.Parse(optionTrigMode.ComboBoxValue.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
_inputUseEnglishFormat = inputUseEnglishFormat;
|
||||
_outputUseEnglishFormat = outputUseEnglishFormat;
|
||||
_replaceInput = replaceInput;
|
||||
_trigMode = trigMode;
|
||||
}
|
||||
|
||||
public static CalculateEngine.TrigMode GetTrigMode()
|
||||
{
|
||||
return _trigMode;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -203,5 +203,50 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.Properties {
|
|||
return ResourceManager.GetString("wox_plugin_calculator_replace_input_description", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Degrees.
|
||||
/// </summary>
|
||||
public static string wox_plugin_calculator_trig_unit_degrees {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_calculator_trig_unit_degrees", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Gradians.
|
||||
/// </summary>
|
||||
public static string wox_plugin_calculator_trig_unit_gradians {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_calculator_trig_unit_gradians", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Trigonometry Unit.
|
||||
/// </summary>
|
||||
public static string wox_plugin_calculator_trig_unit_mode {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_calculator_trig_unit_mode", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Specifies the angle unit to use for trigonometry operations..
|
||||
/// </summary>
|
||||
public static string wox_plugin_calculator_trig_unit_mode_description {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_calculator_trig_unit_mode_description", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Radians.
|
||||
/// </summary>
|
||||
public static string wox_plugin_calculator_trig_unit_radians {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_calculator_trig_unit_radians", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,4 +167,24 @@
|
|||
<data name="wox_plugin_calculator_replace_input_description" xml:space="preserve">
|
||||
<value>When using direct activation, appending '=' to the expression will replace the input with the calculated result (e.g. '=5*3-2=' will change the query to '=13').</value>
|
||||
</data>
|
||||
<data name="wox_plugin_calculator_trig_unit_mode" xml:space="preserve">
|
||||
<value>Trigonometry Unit</value>
|
||||
<comment>Title text for trig unit mode.</comment>
|
||||
</data>
|
||||
<data name="wox_plugin_calculator_trig_unit_mode_description" xml:space="preserve">
|
||||
<value>Specifies the angle unit to use for trigonometry operations</value>
|
||||
<comment>Description text for trig mode setting.</comment>
|
||||
</data>
|
||||
<data name="wox_plugin_calculator_trig_unit_radians" xml:space="preserve">
|
||||
<value>Radians</value>
|
||||
<comment>Text for angle unit.</comment>
|
||||
</data>
|
||||
<data name="wox_plugin_calculator_trig_unit_degrees" xml:space="preserve">
|
||||
<value>Degrees</value>
|
||||
<comment>Text to use for angle unit.</comment>
|
||||
</data>
|
||||
<data name="wox_plugin_calculator_trig_unit_gradians" xml:space="preserve">
|
||||
<value>Gradians</value>
|
||||
<comment>Text for angle unit.</comment>
|
||||
</data>
|
||||
</root>
|
Загрузка…
Ссылка в новой задаче