The function above is just a start.
I didn't account for the case when at single x vaule there's more than one y value but that can be easily remedied.
Simple validation of returned indexes would solve the issue:
int prev = idx_start-1;
while( prev >= 0 && curve.sample( idx_start ) == curve.sample( prev ) )
{
--prev;
--idx_start;
}
int next = idx_end+1;
while( next < curve.dataSize() && curve.sample( idx_end ) == curve.sample( next ) )
{
++next;
++idx_end;
}
int prev = idx_start-1;
while( prev >= 0 && curve.sample( idx_start ) == curve.sample( prev ) )
{
--prev;
--idx_start;
}
int next = idx_end+1;
while( next < curve.dataSize() && curve.sample( idx_end ) == curve.sample( next ) )
{
++next;
++idx_end;
}
To copy to clipboard, switch view to plain text mode
As to your second issue.
If you want all points acroos x axis regardless if they fit on y axis in current zoom rectangle - above function can be used.
If you want points acroos x axis only if they fit on y axis in current zoom rectangle - above function can be used.
In the second case only work required on your part is to remove from the cut-out *data* segment points that overshoot upper and lower values of the zoom rectangle.
Bookmarks