Files
StructureHelper/StructureHelperCommon/Models/Functions/FormulaFunction.cs
2024-10-29 19:31:45 +05:00

101 lines
3.2 KiB
C#

using Microsoft.VisualBasic.ApplicationServices;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
namespace StructureHelperCommon.Models.Functions
{
public class FormulaFunction : IOneVariableFunction
{
private const string COPY = "copy";
public const string GROUP_TYPE_1 = "System function";
public const string GROUP_TYPE_2 = "User function";
public bool IsUser { get; set; }
public FunctionType Type { get; set; }
public string Group { get; set; }
public string Name { get; set; }
public string Description { get ; set; }
public int Step { get; set; }
private List<GraphPoint> table;
public List<GraphPoint> Table
{
get
{
return CalculateTable();
}
set
{
table = value;
}
}
public string Formula { get; set; }
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 FormulaFunction(bool isUser = false)
{
Type = FunctionType.FormulaFunction;
if (isUser)
{
IsUser = true;
Group = GROUP_TYPE_2;
}
else
{
IsUser = false;
Group = GROUP_TYPE_1;
}
}
public bool Check()
{
throw new NotImplementedException();
}
public object Clone()
{
var formulaFunction = new FormulaFunction();
//Здесь будет стратегия
formulaFunction.Type = Type;
formulaFunction.Name = $"{Name} {COPY}";
formulaFunction.Description = Description;
formulaFunction.Formula = Formula;
formulaFunction.IsUser = true;
formulaFunction.Group = GROUP_TYPE_2;
formulaFunction.Step = Step;
formulaFunction.MinArg = MinArg;
formulaFunction.MaxArg = MaxArg;
return formulaFunction;
}
public double GetByX(double xValue)
{
double yValue = 0;
yValue = Math.Round(Math.Pow(xValue, 2), 2); //Временное тестовой выражение квадратичной параболы, будет разбор выражения
return yValue;
}
public List<GraphPoint> CalculateTable()
{
var table = new List<GraphPoint>();
var stepLenght = Math.Abs(MaxArg - MinArg) / Step;
for (double x = MinArg; x < MaxArg; x += stepLenght)
{
var graphPoint = new GraphPoint(x, GetByX(x));
table.Add(graphPoint);
}
return table;
}
}
}