double list= {0, 2, 5, 11}
XYPoints list= {(1,0), (3,0), (4, 0), (7,0)}
Result needs to be a new XYPoints list= {(0,0), (1,0), (2,0), (3,0), (4,0), (5,0), (7,0),(11,0)}
I decided to merge the two lists as follows, but I keep getting a Index out of range exception, and I cannot figure out why.
Below is my code. Assume that the function InterpoalteIntensity returns 0. Also, the exception occurs on the line :
if (pointList[i].XValue < values[j])which is strange, because I check for i to be in bounds just above it :
if (i < pointList.Count)and i is never less than 0;
List<XYPoint> resultList = new List<XYPoint>();
int i = 0;
int j = 0;
while (j < values.Count || i < pointList.Count)
{
if (i < pointList.Count)
{
if (pointList[i].XValue < values[j])
{
resultList.Add(pointList[i]);
i++;
}
else
{
if (i == 0)
{
//// We cannot interpolate before the first point, add 0 intensity
resultList.Add(new XYPoint(values[j], 0));
}
else
{
double interpolatedIntensity = InterpolateIntensity(pointList[i - 1], pointList[i], values[j]);
resultList.Add(new XYPoint(values[j], interpolatedIntensity));
}
j++;
}
}
else if (j < values.Count)
{
//// We cannot interpolate after the last point, add 0 intensity
resultList.Add(new XYPoint(values[j], 0));
j++;
}
else
{
break;
}
}
return resultList;

New Topic/Question
Reply



MultiQuote




|