[cairo] Fwd: Cairo fill extents results with rotation transform

Moazin K moazinkhatri at gmail.com
Sat Apr 17 20:56:57 UTC 2021


Thanks, that works. :-)

On Sun, Apr 18, 2021 at 1:37 AM Heiko Lewin <hlewin at gmx.de> wrote:

> PS: Try this
>
>
>  cairo_set_source_rgb(state->cr, 1.0, 0.0, 0.0);
>  cairo_translate(state->cr, 500, 500);
>  cairo_rotate(state->cr, M_PI / 4);
>  cairo_translate(state->cr, -500, -500);
>  cairo_rectangle(state->cr, 400, 400, 200, 200);
>  double x0, y0, x1, y1;
>
>   cairo_identity_matrix(state->cr);
>
>   cairo_fill_extents(state->cr, &x0, &y0, &x1, &y1);
>   cairo_fill(state->cr);
> ...
>
> Am 17.04.2021 um 22:15 schrieb Heiko Lewin:
>
> Hello!
>
> The _entents-functions return coordinates in the current
> user-coordinate-system, that is the same transform as when drawing the
> rectangle needs to be applied for meaningful results.
> Am 17.04.2021 um 22:03 schrieb Moazin K:
>
> Hi all,
>
> While playing with the `*_extents` functions of Cairo, I discovered that
> `cairo_fill_extents` and `cairo_stroke_extents` give slightly poor results
> when a rotation transform has been applied on the path.
>
> My code is pretty simple:
>
>   cairo_set_source_rgb(state->cr, 1.0, 0.0, 0.0);
>   cairo_translate(state->cr, 500, 500);
>   cairo_rotate(state->cr, M_PI / 4);
>   cairo_translate(state->cr, -500, -500);
>   cairo_rectangle(state->cr, 400, 400, 200, 200);
>   double x0, y0, x1, y1;
>   cairo_fill_extents(state->cr, &x0, &y0, &x1, &y1);
>   cairo_fill(state->cr);
>
>   cairo_identity_matrix(state->cr);
>   cairo_set_source_rgb(state->cr, 0.0, 0.0, 1.0);
>   cairo_set_line_width(state->cr, 1);
>   cairo_rectangle(state->cr, x0, y0, x1 - x0 + 1, y1 - y0 + 1);
>   cairo_stroke(state->cr);
>
> Extents come out to be:
> [x0 y0 x1 y1] -> [299.999266 299.999266 700.000734 700.000734]
>
> The picture `cairo-rotate-problem.png` visualizes this. I think the result
> should be as shown in `cairo-rotate-problem-right-result-imho.png`. Please
> tell me if this is the expected behavior or a bug or enhancement and I can
> appropriately create an issue on the Gitlab issue tracker.
>
> It didn't make sense to me why the function behaves this way, when
> calculating the tight bounds is actually easy. I can get my desired results
> by removing the transform, calculating extents and then transforming those
> extents to get a quadrilateral on which I can fit a rectangle to get the
> tight bounds.
>
> Thank you,
> Moazin
>
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> https://lists.cairographics.org/mailman/listinfo/cairo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20210418/4d7c79b3/attachment-0001.htm>


More information about the cairo mailing list