CPlotView:FindPoint
The Find method returns the index of the point in the class data matrix nearest a target coordinate.
index = CPlotView:FindPoint( x, y ) |
x,y is the target coordinate.
index is the index of the nearest point, beginning at 1.
On success, index > 0 is returned.
On failure, 0 is returned.
This method finds the point in the class data matrix that is nearest the specified coordinate. Typically, this method is used to find a point when the index returned by Add is unknown or after the data points have been shuffled.
This method corrects for the fact that the x and y scales may differ. The point returned is geometrically closest to the target point if the points were plotted with the scale equal in both axes.
The following script fragment finds the closest points to an x,y target position:
V = CPlotView:new() |
-- create a new CPlotView |
V:Add( 22.52, 70.5, 3, 12) |
-- add a point |
V:Add( 23.52, 150.5, 5, 8) |
-- another point |
V:Add( 18.2, 100, 2.5) |
-- another point |
n = V:FindPoint( 19, 148) |
-- target coordinate to match |
Printf("n = %d", n) |
-- result: n = 2 |