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

Moazin K moazinkhatri at gmail.com
Sat Apr 17 20:03:45 UTC 2021


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20210418/ad4c24e7/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cairo-rotate-problem.png
Type: image/png
Size: 17119 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20210418/ad4c24e7/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cairo-rotate-problem-right-result-imho.png
Type: image/png
Size: 17658 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20210418/ad4c24e7/attachment-0003.png>


More information about the cairo mailing list