Converting double to int correctly in drawing
- From: evanevankan2@xxxxxxxxxxxx
- Date: Wed, 2 Apr 2008 05:51:11 -0700 (PDT)
I'm doing a program in C that does some drawing.
Depending on the values of 'start' and 'stop' I want to draw a
rectangle of
appropriate height.
'start' and 'stop' are integers and has values in the interval [0,
MAX]
'height' is the maxium height of the rectangle, it will have this
height if
start = 0 and stop = MAX.
x = 0;
width = 100;
draw_rectangle(x, (double)start/MAX * height, width, (double)(stop -
start)/MAX * height);
But draw_rectangle takes ints, so if the expressions have decimals
they will be
truncated, and the resultning rectangle will not be right. For example
if start = 10 and
stop = MAX it will not (depending on the actual value of MAX) draw the
rectangle all
the way down, it misses the last pixel.
So my question is how to fix this, how to convert correctly to ints? I
can't just add
one pixel to the end, since my code works for values where the
expressions does not
contain decimals.
Thanks!
.
- Follow-Ups:
- Re: Converting double to int correctly in drawing
- From: Jim Langston
- Re: Converting double to int correctly in drawing
- From: Alf P. Steinbach
- Re: Converting double to int correctly in drawing
- From: Ed Prochak
- Re: Converting double to int correctly in drawing
- Prev by Date: Re: Search for an algorithm to deal cards with preset conditions
- Next by Date: Re: Converting double to int correctly in drawing
- Previous by thread: Cheap Omega Speedmaster Legend Watches Replica - Omega Watches Wholesale
- Next by thread: Re: Converting double to int correctly in drawing
- Index(es):
Relevant Pages
|