Interpolation with test done

This commit is contained in:
Иван Ивашкин
2024-10-31 17:35:31 +05:00
parent 96b0fbd6a3
commit bcea9639f6
12 changed files with 130 additions and 24 deletions

View File

@@ -35,6 +35,9 @@ namespace StructureHelperCommon.Models.Functions.Decorator
{
var graphSettings = base.GetGraphSettings();
var graphLimitGraphPoint = new List<GraphPoint>();
var leftPoint = new GraphPoint(leftBound, GetByX(leftBound));
var rightPoint = new GraphPoint(rightBound, GetByX(rightBound));
graphLimitGraphPoint.Add(leftPoint);
foreach (GraphPoint point in graphSettings.GraphPoints)
{
if (point.X > leftBound && point.X < rightBound)
@@ -42,6 +45,7 @@ namespace StructureHelperCommon.Models.Functions.Decorator
graphLimitGraphPoint.Add(point);
}
}
graphLimitGraphPoint.Add(rightPoint);
graphSettings.GraphPoints = graphLimitGraphPoint;
return graphSettings;
}

View File

@@ -36,6 +36,9 @@ namespace StructureHelperCommon.Models.Functions.Decorator
{
var graphSettings = base.GetGraphSettings();
var graphLimitGraphPoint = new List<GraphPoint>();
var downPoint = new GraphPoint(downBound, GetByX(downBound));
var upPoint = new GraphPoint(upBound, GetByX(upBound));
graphLimitGraphPoint.Add(downPoint);
foreach (GraphPoint point in graphSettings.GraphPoints)
{
if (point.Y > downBound && point.Y < upBound)
@@ -43,6 +46,7 @@ namespace StructureHelperCommon.Models.Functions.Decorator
graphLimitGraphPoint.Add(point);
}
}
graphLimitGraphPoint.Add(upPoint);
graphSettings.GraphPoints = graphLimitGraphPoint;
return graphSettings;
}

View File

@@ -26,10 +26,8 @@ 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; 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; }

View File

@@ -8,6 +8,7 @@ namespace StructureHelperCommon.Models.Functions
{
public class GraphPoint : ICloneable
{
public bool Exclude { get; set; }
public double X { get; set; }
public double Y { get; set; }
@@ -15,6 +16,7 @@ namespace StructureHelperCommon.Models.Functions
{
X = x;
Y = y;
Exclude = false;
}
public object Clone()
{

View File

@@ -27,7 +27,6 @@ namespace StructureHelperCommon.Models.Functions
public string Name { get; set; }
public string Description { get; set; }
public List<GraphPoint> Table { get; set; }
public Guid Id => throw new NotImplementedException();
public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public double MinArg { get; set; }
@@ -72,21 +71,36 @@ namespace StructureHelperCommon.Models.Functions
public double GetByX(double xValue)
{
//Реализовать взятие значения из таблицы и интерполяцию по таблице
return 100;
GraphPoint leftBound = null;
GraphPoint rightBound = null;
for (int i = 0; i < Table.Count - 1; i++)
{
leftBound = Table[i];
rightBound = Table[i + 1];
if (xValue == leftBound.X)
{
return leftBound.Y;
}
else if (xValue > leftBound.X && xValue < rightBound.X)
{
return MathUtils.Interpolation(xValue, leftBound.X, rightBound.X, leftBound.Y, rightBound.Y);
}
else if (xValue == rightBound.X)
{
return rightBound.Y;
}
}
return 0;
//Можно добавить экстраполяцию
}
public GraphSettings GetGraphSettings()
{
var graphSettings = new GraphSettings(Color, Color);
foreach(GraphPoint point in Table)
foreach (GraphPoint point in Table)
{
var graphPoint = new GraphPoint(point.X, GetByX(point.X));
graphSettings.GraphPoints.Add(graphPoint);
}
}
return graphSettings;
}
}