[cairo] Check collision via cairo_clip_extents

Yang Hong yanghong at thundersoft.com
Fri Nov 23 09:16:54 UTC 2018

Dear Cairo developers


I'm writing a 2D game which need to check collision between
triangle/trapezoid/rectangle/hexagon blocks on the canvas.


I tried to use cairo_clip_extents() to find intersect of triangle and
rectangle, but it doesn't work, because the returned bounding is bigger than
the accurate intersect. Please refer to the attached collision checking
model, I want get the bounding of the area C to check if the triangle is
intersected with the rectangle. This model only works between rectangles,
the cairo_region_t also not help on this.


I also tried cairo_fill_extents, it returns the whole bounding of the
current path, which is not what I want.


While the C area is correctly filled with clip, I want to know is there any
API to get the bound of this area, so I can use it to check if collision
exists. Or is it possible to add API to do so, I have looked into the source
code of cairo, please give me some comment, I'd like to add this API by


The attached cairo-sandbox.c is the code I used to test the checking model.


    gcc -o sandbox cairo-sandbox.c -lcairo -g


    eog image.png


Best regards


Hong Yang - TS


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20181123/3bd6ee04/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: collision-checking-model.txt
URL: <https://lists.cairographics.org/archives/cairo/attachments/20181123/3bd6ee04/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cairo-sandbox.c
Type: application/octet-stream
Size: 6977 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20181123/3bd6ee04/attachment.obj>

More information about the cairo mailing list