-
Notifications
You must be signed in to change notification settings - Fork 981
Description
Bug Report
Issue:
When interpolating data arrays with more then 160 elements using PeriodicSpline or EndSlopeSpline a System.InvalidOperationException is triggered.
System.InvalidOperationException
HResult=0x80131509
Message=Operation is not valid due to the current state of the object.
Source=ScottPlot
StackTrace:
at ScottPlot.Statistics.Interpolation.PeriodicSpline.CalcParameters()
at ScottPlot.Statistics.Interpolation.PeriodicSpline..ctor(Double[] xs, Double[] ys, Int32 resolution)
at Chart_Test.MainWindow..ctor() in C:\Users\hoot\source\repos\Chart_Test\Chart_Test\MainWindow.xaml.cs:line 35
Reproducing:
Generate an array of 161 data points and interpolate using var esi = new PeriodicSpline(dataX, dataY, resolution: 10); or var esi = new EndSlopeSpline(dataX, dataY, resolution: 10);.
This issue can also reproduced with NaturalSpline but the maximum length of the array is higher. I have tested 2048 data points and it triggers the same exception.
double[] dataX = new double[161];
double[] dataY = new double[161];
Random random = new Random();
for (int i = 0; i < 161; i++) {
dataX[i] = -85 + i * 11.43;
dataY[i] = random.Next(-30, -20);
}
var esi = new PeriodicSpline(dataX, dataY, resolution: 10);
ScatterPlot scatterPlot = new ScatterPlot(dataX, dataY);
ScatterPlot scatterPlotInterpolated = new ScatterPlot(esi.interpolatedXs, esi.interpolatedYs);
scatterPlot.MarkerSize = 0;
scatterPlotInterpolated.MarkerSize = 0;
scatterPlot.Color = System.Drawing.Color.Blue;
scatterPlotInterpolated.Color = System.Drawing.Color.Red;
WpfPlot1.Plot.Add(scatterPlot);
WpfPlot1.Plot.Add(scatterPlotInterpolated);
WpfPlot1.Plot.SetAxisLimitsX(-85, -85 + 11.43 * 4);
WpfPlot1.Plot.SetAxisLimitsY(-110, -20);
WpfPlot1.Refresh();System Details
- ScottPlot Version: 4.1.127
- Operating System: Windows 11
- Application Type: WPF
- .NET Version: NET Framework 4.6.1