Question about extents and transformations

[email protected] Mon, 09 Dec 2019 11:04:37 +0100
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
This is a multipart message in MIME format.

------_=_1f6176ee19f315b43228c4b2_=_
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi.

I=E2=80=99m trying to use the cairo_path_extents procedure to get a rough
bounding box of shapes drawn by cairo, and I found this surprising
behaviour:

The documentation for cairo_path_extents() states: =E2=80=9CComputes a boun=
ding
box in user-space coordinates=E2=80=9D, that=E2=80=99s why I expect the ext=
ents of a
given path to always be the same, whichever transformation might be
applied.

It appears to be the case for scaling and translations, but rotation gives
me different extents. Am I missing something or is this a bug?


------_=_1f6176ee19f315b43228c4b2_=_
Content-Disposition: attachment; filename=rotation-extents.c
Content-Type: text/plain:
Content-Transfer-Encoding: quoted-printable

#include <stdio.h>
#include <math.h>
#include <cairo/cairo.h>

int main() {
    double x1, y1, x2, y2;
    cairo_surface_t* surface =3D cairo_image_surface_create(CAIRO_FORMAT_RG=
B24, 10, 10);
    cairo_t* context =3D cairo_create(surface);

    cairo_translate(context, 50, 20);
    cairo_scale(context, 100, 100);
    cairo_rectangle(context, 0, 0, 1, 1);
    cairo_path_extents(context, &x1, &y1, &x2, &y2);
    printf("extents with translate and scale: (%lf, %lf)  (%lf, %lf)\n", x1=
, y1, x2, y2);

    cairo_identity_matrix(context);
    cairo_new_path(context);

    cairo_rotate(context, 0.25 * M_PI);
    cairo_rectangle(context, 0, 0, 1, 1);
    cairo_path_extents(context, &x1, &y1, &x2, &y2);
    printf("extents with rotate: (%lf, %lf)  (%lf, %lf)\n", x1, y1, x2, y2)=
;

    cairo_destroy(context);
    cairo_surface_destroy(surface);
    return 0;
}


------_=_1f6176ee19f315b43228c4b2_=_
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo

------_=_1f6176ee19f315b43228c4b2_=_--