[cl-gd-devel] with-transformation off-by-one bug?

Michael J. Forster mike at sharedlogic.ca
Thu Sep 13 13:29:56 UTC 2007


On 13-Sep-07, at 4:14 AM, Edi Weitz wrote:

> On Tue, 11 Sep 2007 11:13:24 -0500, "Michael J. Forster"  
> <mike at sharedlogic.ca> wrote:
>
>> I'm using WITH-TRANSFORMATION to simplify the graph plotting, and
>> it's not behaving the way I would expect.  As I read it in the
>> documentation, this...
>>
>> (with-transformation (:x1 0
>>                        :width width
>>                        :y1 0
>>                        :height height)
>>    ...)
>>
>>
>> ... should transform the coordinate system from this...
>>
>> 0,0 -----> width - 1
>> |
>> |
>> |
>> V
>> height - 1
>>
>> ... to this...
>>
>> height - 1
>> ^
>> |
>> |
>> |
>> 0,0 -----> width - 1
>
> Hmm, why do you think that?  I would expect a transformation from
>
>  0,0 -----> image-width
>  |
>  |
>  |
>  V
>  image-height
>
> to
>
>  height
>  ^
>  |
>  |
>  |
>  0,0 -----> width
>
> Why do you want to subtract 1?  What do you expect to happen if WIDTH
> or HEIGHT /are/ 1?

I was thinking of lines on a graph as zero-based vectors.  Thus, a
vector of length (or axis of width or height) n is indexed from 0
to n-1.  And, indeed, with the following...

(let ((height 100)
       (width 100)
       (x-axis-width (list width 1))
       (y-axis-height (list 1 height))
       (x-axis-width-1 (list (1- width) 1))
       (y-axis-height-1 (list 1 (1- height))))
   (cl-gd:with-image* (width height)
     (set-pixels x-axis-width)
     (set-pixels y-axis-height)
     (set-pixels x-axis-width-1)
     (set-pixels y-axis-height-1)
     ...))

... only the last two pixels are displayed on my 100x100 pixel image.
The axes are indexed from 0 to n-1.  If WIDTH and HEIGHT are 1, I only
expect to see the pixel generated by...

(set-pixels '(0 0))

Is my brain off by one?


Thanks and best regards,

Mike

--
Michael J. Forster <mike at sharedlogic.ca>




More information about the Cl-gd-devel mailing list