Add function parser

This commit is contained in:
Иван Ивашкин
2024-12-15 15:47:04 +05:00
parent 7c9bc1856b
commit 33820e972b
7 changed files with 42 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
public IShiftTraceLogger? TraceLogger { get; set; }
public Color Color { get; set; }
public string Trace { get; set; }
public FunctionDecorator(IOneVariableFunction function)
{

View File

@@ -25,6 +25,7 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
public double MinArg { get; set; }
public double MaxArg { get; set; }
public Color Color { get; set; }
public string Trace { get; set; }
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public bool Check();
public double GetByX(double xValue);

View File

@@ -13,11 +13,15 @@ using System.Windows.Documents;
using StructureHelperCommon.Services;
using LiveCharts.Wpf;
using StructureHelperCommon.Services.ColorServices;
using FunctionParser;
namespace StructureHelperCommon.Models.Functions
{
public class FormulaFunction : IOneVariableFunction
{
private double current_xValue;
private string formula;
private Expression expression;
private const string COPY = "copy";
public const string GROUP_TYPE_1 = "System function";
public const string GROUP_TYPE_2 = "User function";
@@ -27,13 +31,36 @@ namespace StructureHelperCommon.Models.Functions
public string Name { get; set; }
public string Description { get ; set; }
public int Step { get; set; }
public string Formula { get; set; }
public string Formula
{
get
{
return formula;
}
set
{
formula = value;
Expression = new Expression(value, new string[] { "x" }, null);
}
}
public Expression Expression
{
get
{
return expression;
}
set
{
expression = value;
}
}
public Guid Id => throw new NotImplementedException();
public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public double MinArg { get; set; }
public double MaxArg { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public Color Color { get; set; }
public string Trace { get; set; }
public FormulaFunction(bool isUser = false)
{
@@ -55,7 +82,6 @@ namespace StructureHelperCommon.Models.Functions
{
throw new NotImplementedException();
}
public object Clone()
{
var formulaFunction = new FormulaFunction();
@@ -76,7 +102,9 @@ namespace StructureHelperCommon.Models.Functions
public double GetByX(double xValue)
{
double yValue = 0;
yValue = Math.Round(Math.Pow(xValue, 2), 2); //Временно выражение квадратичной параболы, будет разбор выражения
current_xValue = xValue;
Check();
yValue = Math.Round(Expression.CalculateValue(new double[] { xValue }), 2);
return yValue;
}
public GraphSettings GetGraphSettings()

View File

@@ -34,6 +34,7 @@ namespace StructureHelperCommon.Models.Functions
public double MaxArg { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public Color Color { get; set; }
public string Trace { get; set; }
public TableFunction(bool isUser = false)
{

View File

@@ -15,6 +15,9 @@
</ItemGroup>
<ItemGroup>
<Reference Include="FunctionParser">
<HintPath>..\..\FunctionParser\FunctionParser\bin\Debug\FunctionParser.dll</HintPath>
</Reference>
<Reference Include="LoaderCalculator">
<HintPath>..\StructureHelper\Libraries\LoaderCalculator.dll</HintPath>
</Reference>