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

Michael J. Forster mike at sharedlogic.ca
Fri Sep 14 10:17:16 UTC 2007


On 14-Sep-07, at 2:19 AM, Edi Weitz wrote:

> On Thu, 13 Sep 2007 08:29:56 -0500, "Michael J. Forster"  
> <mike at sharedlogic.ca> wrote:
>
>> 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))
>
> I think where CL-GD and you disagree is that currently the outermost
> "virtual" point (X2 or (+ X1 WIDTH)) is mapped to the first point
> which is /not/ on the real image (and similar for the other axis),
> i.e. the transformation arguments kind of describe a half-open
> interval.  I can see how this is inconvenient and I wouldn't mind
> changing that unless someone else provides important reasons not to do
> it.  Could you please check if the attached patch does what you want?
>
> As for your complaints about the x-axis transformation not being
> consistent with the y-axis transformation, are you sure you're not
> seeing rounding errors?  Or maybe this happened because of the "one
> off" stuff plus the fact that the "virtual" y-axis usually points into
> the opposite direction?
>

Hi Edi,

Thanks for getting back to me so quickly.  I will be away on business
for a couple of days, so if you'll let me ponder your comments and play
with the patch, I'll get back to you early next week.

And I hope you didn't take any of this as a complaint.  It's really a
matter of me wrapping my brain around CL-GD's behaviour in these
corner cases (no pun intended).  Regardless, WITH-TRANSFORMATION is
much nicer than the translation and scaling hacks required to use, say,
PHP's GD bindings.

Thanks again,

Mike

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




More information about the Cl-gd-devel mailing list