Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. (687;10)
  2. (12;20)
  3. (24;30)
  4. (10125;40)
  5. (0;50)
  6. (111;60)
  7. (-2;70)
  8.  
  9. private ZedGraph.PointPair findPoint(ZedGraph.CurveItem curve, double x)
  10. {
  11. if (curve.NPts == 1)
  12. return curve.Points[0];
  13.  
  14. // Look for the min and max value
  15. double min = curve.Points[0].X;
  16. double max = curve.Points[curve.NPts - 1].X;
  17.  
  18. double delta = curve.Points[1].X - min;
  19.  
  20. // Prevent error if mouse is out of bounds.
  21. if (x > max)
  22. x = curve.Points[curve.NPts - 1].X;
  23. else if (x < min)
  24. x = curve.Points[0].X;
  25.  
  26. double index = (x - min) / delta;
  27. int nearestIndex = (int)Math.Round(index, 0);
  28.  
  29. if (nearestIndex < curve.NPts)
  30. {
  31. return curve.Points[nearestIndex];
  32. }
  33. return curve.Points[curve.NPts - 1];
  34. }
  35.  
  36. private ZedGraph.PointPair findPoint(ZedGraph.CurveItem curve, double x)
  37. {
  38. // Look for the min and max value
  39. double min = curve.Points[0].X;
  40. double max = curve.Points[curve.NPts - 1].X;
  41.  
  42. // Prevent error if mouse is out of bounds.
  43. if (x <= min) return curve.Points[0];
  44. if (x >= max) return curve.Points[curve.NPts - 1];
  45.  
  46. double delta = (max - min) / (curve.NPts - 1);
  47. int index = (int)Math.round((x - min) / delta, 0);
  48.  
  49. Debug.Assert(Math.Abs(x - curve.Points[index].X) <= delta / 2, "Interpolation error");
  50. return curve.Points[index];
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement