Twinside / Rasterific

A drawing engine in Haskell
BSD 3-Clause "New" or "Revised" License
140 stars 11 forks source link

Possibly a bug triggered by too small coordinates? #57

Closed apirogov closed 4 years ago

apirogov commented 4 years ago

I was trying to render some geometric objects. I defined my base object with unit length and the idea was that the object can be scaled up and moved using withTransformation, but I noticed some lines of my objects were missing. After trying to pin down the problem, it seems to me that the problem is in fact somewhere in Rasterific (I use the current 0.7.5.2. version from Stackage).

Consider the following minimal example:

writePng "test.png" $ renderDrawing 20 20 (PixelRGBA8 255 255 255 255) 
                    $ withTransformation (scale 100 100) 
                    $ withTexture (uniformTexture $ PixelRGBA8 0 0 0 255)
                    $ stroke 0.01 JoinRound (CapRound, CapRound) $ line (V2 0 0) (V2 0.2 0.2)

The expected result would be a little straight diagonal black line from (0,0) to (20,20). The actual result is that the line is not drawn and the image is blank.

Now if you change V2 0.2 0.2 to e.g. V2 0.25 0.25, then the line does appear. I would guess that somewhere rounding occurs and when my untransformed coordinates are too small, they just vanish and break the primitive? Or am I doing something I am not supposed to do?

Twinside commented 4 years ago

Hi,

stroke width is not transformed/scaled, only geometry is, so having 1/100 of width shouldn't display anything

apirogov commented 4 years ago

But I think that stroke is transformed, and that this is good! If you switch the example as I said, you get a ~1px thick line. But if I set stroke to 1, then the whole image is black. Or how is the correct explanation for these effects? I was doing a lot of things with full confidence that stroke width proportionally scales and it worked perfectly as I expected.

I always set stroke width relative to the width of the object, have an object of unit size and scale it to required size, and it works.