[racket] Problem with hline in

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sat May 26 11:17:52 EDT 2012

On Sat, May 26, 2012 at 10:09 AM, Jens Axel Søgaard
<jensaxel at soegaard.net> wrote:
> 2012/5/26 Robby Findler <robby at eecs.northwestern.edu>:
>> It is possible something is wrong with hline and/or its interaction
>> with scaling, I'm not sure. But this adds enough space:
>>
>> #lang racket
>> (require slideshow/pict)
>> (hc-append (blank 15 0)
>>           (vc-append (scale (hline 30 1) 30)
>>                      (blank 0 15))
>>           (blank 15 0))
>
> So an educated guess on how much space to add would be
> the line width times the scaling?

Right. In general, that should be a robust formula, but there will be
rounding issues for widhts and heights that are odd (a 15 pixel line
will take up 16 pixels, I think, drawing the end pixels in a lighter
color).

>> I wonder if something is wrong somewhere, tho, because the bounding
>> box of the above appears to have some pixels of empty space on the
>> top.
>>
>> The space on the left and right is count for the pen cap, not the line
>> itself so that seems fine.
>>
>> As for cropping, the DrRacket REPL is the thing that does the cropping
>> (and, in some cases, it may not be cropping, actually, but two
>> different parts of the window are fighting with each other for the
>> pixels when something draws outside of its bounding box, as a scaled
>> hline does).
>
> Okay, I thought there was a guarantee that the drawing happened
> inside the bounding box.

That is not a guarantee and importantly not one (for picts, generally
speaking, that is). refocus is a common way that guarantee fails to
hold, for example.

> Something is fishy with hline or my understanding of hline though.
> In order to avoid using scale I tried this:
>
>    (pict->bitmap (hline (* 20 30) 20))
>
> and got a one pixel line. See attached image.
> (On version 5.3.0.6--2012-05-11 btw)

If I understand correctly, hline is drawing a horizontal line centered
in the bounding box given, perhaps a strange definition of a thing,
I'll easily admit.

This is even stranger given how pixels and line drawing interact.

So maybe the easiest thing is to drop down to use 'dc' to draw the
precise lines you want.

If you spell that out here, I can probably give you some guidance on
how to do it?

Robby


Posted on the users mailing list.