[cairo] Extents under rotation
Uli Schlachter
psychon at znc.in
Sun Dec 8 08:50:29 PST 2013
On 08.12.2013 16:19, Donn wrote:
> On 07/12/2013 20:22, Uli Schlachter wrote:
>> Uhm. So the above code should do just this, right?
> Uli,thanks for your input again.
>
> I put together this code (in Vala) using your idea:
[...]
> cr.arc (0.0, 0.0, 30.0, 0, 2*Math.PI);
> cr.set_source_rgb(1,1,0);
> cr.fill_preserve();
>
> cr.save();
> cr.identity_matrix();
> cr.path_extents(out x1, out y1, out x2, out y2);
>
> //Draw this device rect in green
> cr.new_path();
> cr.rectangle(x1,y1,(x2-x1),(y2-y1));
> cr.set_source_rgb(0,1,0);
> cr.set_line_width(3);
> cr.stroke();
>
> cr.restore();
>
> //Go from device into user
> cr.device_to_user(ref x1, ref y1);
> cr.device_to_user(ref x2, ref y2);
>
> //Draw this user rect in white.
> cr.new_path();
> cr.move_to(x1,y1);
> cr.line_to(x2,y1);
> cr.line_to(x2,y2);
> cr.line_to(x1,y2);
> cr.close_path();
>
[...]
That's not what I suggested. You cannot just transform the top-left and
bottom-right corner of the extents and assume that the other ones can be deduced
from that (this is not an axis-aligned rectangle in user space!).
Attached is a working version. The diff to your version is also attached.
Cheers,
Uli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.patch
Type: text/x-patch
Size: 955 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20131208/752b2d30/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.vala
Type: text/x-vala
Size: 2550 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20131208/752b2d30/attachment-0001.bin>
More information about the cairo
mailing list