private void FunctionToolStripMenuItem1_Click(object sender, EventArgs e) { FunctionProperties functionProperties = new FunctionProperties(); if (functionProperties.ShowDialog() != DialogResult.OK) { return; } Vfunction vFunc = new Vfunction(functionProperties.Function) { Width = GlobalScopePanel.Width }; foreach (var variable in GlobalScope.Scope.LocalVariables) { vFunc.Function.Scope.ScopeAccessVariable.Add(variable); } foreach (var var in functionProperties.Function.Parameters) { vFunc.Function.Scope.ScopeAccessVariable.Add(new Variable(var.Name) { Type = var.Type }); } vFunc.SetReturnVar(); GlobalScopePanel.Controls.Add(vFunc); GlobalScope.FunctionList.Add(functionProperties.Function); UpdateScope(); }
private void settingsButton_Click(object sender, EventArgs e) { FunctionProperties functionProperties = new FunctionProperties(Function); if (functionProperties.ShowDialog() != DialogResult.OK) { return; } Function = functionProperties.Function; VCode = Function; PopulateProperties(); }
public void FunctionTest() { FunctionProperties FP = new FunctionProperties("SIN(x)"); Assert.AreEqual(0, FP.Function(0)); FP = new FunctionProperties("COS(x)"); Assert.AreEqual(1, FP.Function(0)); FP = new FunctionProperties("TAN(x)"); Assert.AreEqual(0, FP.Function(0)); FP = new FunctionProperties("COT(x)"); Assert.AreEqual(0, Math.Round(FP.Function(Math.PI / 2))); }
public void PolynomialDerivativeTest() { //with ^ //with factor FunctionProperties FP = new FunctionProperties(""); Assert.AreEqual(-8, FP.PolynomialDerivative("-2x^2", 2)); FP = new FunctionProperties(""); Assert.AreEqual(8, FP.PolynomialDerivative("2x^2", 2)); //without factor FP = new FunctionProperties(""); Assert.AreEqual(-4, FP.PolynomialDerivative("-x^2", 2)); FP = new FunctionProperties(""); Assert.AreEqual(4, FP.PolynomialDerivative("x^2", 2)); // without ^ //with x //with factor FP = new FunctionProperties(""); Assert.AreEqual(-2, FP.PolynomialDerivative("-2x", 2)); FP = new FunctionProperties(""); Assert.AreEqual(2, FP.PolynomialDerivative("2x", 2)); //without factor FP = new FunctionProperties(""); Assert.AreEqual(-1, FP.PolynomialDerivative("-x", 2)); FP = new FunctionProperties(""); Assert.AreEqual(1, FP.PolynomialDerivative("x", 2)); //without x FP = new FunctionProperties(""); Assert.AreEqual(0, FP.PolynomialDerivative("-2", 2)); FP = new FunctionProperties(""); Assert.AreEqual(0, FP.PolynomialDerivative("8", 2)); }
public void PolynomialIntegrateTest() { //with ^ //with factor FunctionProperties FP = new FunctionProperties(""); Assert.AreEqual(((double)-16 / 3), FP.PolynomialIntegrate("-2x^2", 2)); FP = new FunctionProperties(""); Assert.AreEqual(((double)16 / 3), FP.PolynomialIntegrate("2x^2", 2)); //without factor FP = new FunctionProperties(""); Assert.AreEqual(((double)-8 / 3), FP.PolynomialIntegrate("-x^2", 2)); FP = new FunctionProperties(""); Assert.AreEqual(((double)8 / 3), FP.PolynomialIntegrate("x^2", 2)); // without ^ //with x //with factor FP = new FunctionProperties(""); Assert.AreEqual(-4, FP.PolynomialIntegrate("-2x", 2)); FP = new FunctionProperties(""); Assert.AreEqual(4, FP.PolynomialIntegrate("2x", 2)); //without factor FP = new FunctionProperties(""); Assert.AreEqual(-2, FP.PolynomialIntegrate("-x", 2)); FP = new FunctionProperties(""); Assert.AreEqual(2, FP.PolynomialIntegrate("x", 2)); //without x FP = new FunctionProperties(""); Assert.AreEqual(-4, FP.PolynomialIntegrate("-2", 2)); FP = new FunctionProperties(""); Assert.AreEqual(16, FP.PolynomialIntegrate("8", 2)); }
protected override WriteResult Write(OpenXMLWpfMathRenderer renderer, BigOperatorAtom item) { var writeResult = WriteResult.Completed; if (item.Type == TexAtomType.BigOperator && item.BaseAtom is SymbolAtom symAtom) { // something like \int, \sum, \prod etc. LimitLocationValues?limitLocation = null; switch (symAtom.Name) { case "int": case "iint": case "iiint": case "iiiint": case "idotsint": case "oint": limitLocation = LimitLocationValues.SubscriptSuperscript; break; default: limitLocation = LimitLocationValues.UnderOver; break; } if (!_nameToBigOperatorSymbol.TryGetValue(symAtom.Name, out var accentString)) { accentString = null; } var nary = renderer.Push(new Nary()); var naryProps = nary.AppendChild(new NaryProperties()); if (accentString != null) { naryProps.AppendChild(new AccentChar { Val = accentString }); } if (limitLocation.HasValue) { naryProps.AppendChild(new LimitLocation { Val = limitLocation.Value }); } var controlProperties = new ControlProperties( new W.RunProperties( new W.RunFonts() { Ascii = "Cambria Math", HighAnsi = "Cambria Math" }, new W.Italic() ) ); naryProps.AppendChild(controlProperties); if (item.LowerLimitAtom != null) { var sub = renderer.Push(new SubArgument()); renderer.Write(item.LowerLimitAtom); renderer.PopTo(sub); } if (item.UpperLimitAtom != null) { var super = renderer.Push(new SuperArgument()); renderer.Write(item.UpperLimitAtom); renderer.PopTo(super); } var baseA = renderer.Push(new Base()); var callback = new CallbackPopAfterNextElement(renderer, item, elementToPopTo: nary); // renderer.PopTo(nary); we don't pop here, the pop is done after the next element was written (see line before) writeResult = WriteResult.CompletionDeferred; } else if (item.Type == TexAtomType.BigOperator && item.BaseAtom is RowAtom rowAtom) { // this is treated as a function if rowAtom contains character elements if (rowAtom.Elements.Any(a => !(a is CharAtom))) { throw new NotImplementedException(); // then we have to look what this is? } else { // all childs of RowAtom are CharAtoms, // we put them together to get the function name string functionName = string.Empty; foreach (CharAtom ca in rowAtom.Elements) { functionName += ca.Character; } var functionProperties = new FunctionProperties( new ControlProperties( new W.RunProperties( new W.RunFonts() { Ascii = "Cambria Math", HighAnsi = "Cambria Math" }, new W.Italic() ) ) ); var mathFunction = renderer.Push(new MathFunction(functionProperties)); var functionNameEle = renderer.Push(new FunctionName()); var runEle = renderer.Push(new Run()); runEle.AppendChild( new RunProperties( new Style() { Val = StyleValues.Plain } ) ); runEle.AppendChild( new W.RunProperties( new W.RunFonts() { Ascii = "Cambria Math", HighAnsi = "Cambria Math" }, new W.Italic() ) ); runEle.AppendChild(new DocumentFormat.OpenXml.Math.Text { Text = functionName }); renderer.PopTo(functionNameEle); renderer.Push(new Base()); var callback = new CallbackPopAfterNextElement(renderer, item, elementToPopTo: mathFunction); // renderer.PopTo(mathFunction); we don't pop here, the pop is done after the next element was written (see line before) writeResult = WriteResult.CompletionDeferred; } } else { renderer.Write(item.BaseAtom); writeResult = WriteResult.Completed; } return(writeResult); }