[vtk-developers] Charts and float/int conversion

Jim Peterson jimcp at cox.net
Tue Sep 21 18:53:05 EDT 2010


David Gobbi wrote:
> inline vtkContext2D::FloatToInt(float x)
> {
>   return static_cast<int>(x + 1.0625) - 1;
> }
>
> This provides a tolerance of 1/16 of a pixel for the float-to-int
> conversion. The "1" and "- 1" ensure that float values in the range
> [-1.0, 0.0] are rounded down, instead of being rounded toward zero.
>
>   David
>   
David,
pardon my ignorance, but if we are rounding float to int, why do we want 
-0.1 to round to -1 and not 0? in other words, why not x + 1.5 instead 
of x + 1.0625?

Thanks,
Jim




More information about the vtk-developers mailing list