<font color="#333333">Hi Uli<br></font><br>Sorry for the confusion, the size of the triangle/rectangle is pre-defined by the length of edges, and I want to scale them dynamic. I'd use cairo_scsle() here.<br><br>I want to check the collision between the triangle and the rectangle when move them on a cavas, it's a 2D game.<br><br>Please check the attached txt file in previous email, I want get the bounding of the C area. Take a look at the first composition of the triangle/rectangle in the image.png output by the cairo_sandbox.c, The small grey triangle is the C area which is the intersection of the triangle/rectangle. cairo_clip_extents return a rec as height as the triangle, it's higher than the grey triangle.<br><br>Hope the question is clear now:) I'm using Racket to write this game in Ubuntu 16.04, cairo is the backend of the drawing API, so I try to find such API in cairo.<br><br>Best regards<br>Hong Yang<br><br><span id="smartisan_signature" style="font-size: 0.8em; display:inline; color:#888888;"><p dir="ltr"></p>
</span><style type="text/css">* body { background-color: #ffffff; line-height: 1.4;word-wrap: break-word; word-break: normal; } div {word-wrap: break-word; word-break: normal; } p {word-wrap: break-word; word-break: normal; text-indent: 0pt !important; } span {word-wrap: break-word; word-break: normal; } a {word-wrap: break-word; word-break: normal; } td {word-wrap: break-word; word-break: break-all; }</style><div class="quote"><div style="margin: 0 0px; font-size: 105%"><font style="line-height: 1.4" color="#629140"><span>Uli Schlachter <psychon@znc.in>
于 2018年11月24日 上午12:54写道:</span></font></div><br type="attribution"><blockquote class="quote" style="margin:0 0 0 0;border-left:1px rgba(0, 0, 0, .15) solid;padding-left:5px"><p dir="ltr">Hi,
<br>
<br>
first of all, your scale parameter confused me a lot. :-)
<br>
<br>
Then: I do not really think that cairo clip extents is the right API for
<br>
collision detection, but okay...
<br>
<br>
On 23.11.18 10:16, Yang Hong wrote:
<br>
> I tried to use cairo_clip_extents() to find intersect of triangle and
<br>
> rectangle, but it doesn't work, because the returned bounding is bigger than
<br>
> the accurate intersect.
<br>
<br>
I fail to see this "too big". What's the output that you want to get
<br>
from this?
<br>
<br>
Let's look at each printf:
<br>
<br>
[...]
<br>
> cairo_new_path(cr);
<br>
> create_triangle(cr, rec36, ARRAY_SIZE(rec36), 1);
<br>
[...]
<br>
> cairo_clip(cr);
<br>
> cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
<br>
> //cairo_fill_extents(cr, &x1, &y1, &x2, &y2);
<br>
>
<br>
> printf("Clip extents: %f, %f, %f, %f\n", x1, y1, x2, y2);
<br>
<br>
This prints 0 0 60 120 for me (well, with lots of trailing ".0000"). And
<br>
indeed, rec36 contains the points (0,0), (3,0), (3,6), (0,6). The
<br>
extents of this are (0,0) to (3,6), which after multiplying by scale=20
<br>
gives (0,0) and (60,120), which is just what cairo is giving you.
<br>
<br>
[...]
<br>
> cairo_reset_clip(cr);
<br>
> cairo_new_path(cr);
<br>
> create_triangle(cr, tri4, ARRAY_SIZE(tri4), 1);
<br>
[...]
<br>
> cairo_clip(cr);
<br>
<br>
tri4 has the points (3,0), (6,3), (0,3). The extents of this are (0,0)
<br>
to (6,3).
<br>
<br>
>
<br>
> cairo_translate(cr, 100, 0);
<br>
> cairo_new_path(cr);
<br>
> create_triangle(cr, rec36, ARRAY_SIZE(rec36), 1);
<br>
[...]
<br>
> x1 = y1 = x2 = y2 = 0.0;
<br>
> cairo_clip(cr);
<br>
> cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
<br>
> //cairo_fill_extents(cr, &x1, &y1, &x2, &y2);
<br>
>
<br>
> printf("Clip extents: %f, %f, %f, %f\n", x1, y1, x2, y2);
<br>
<br>
Okay... output for me here is 0 0 20 60.
<br>
Extents of tri4 are (-5,0) to (1,3) (because of the translate by (100,0)
<br>
above, which is (5,0) when divided by scale=20).
<br>
Extents of rec36 are (0,0) to (3,6).
<br>
<br>
The intersection of these to is from (0,0) to (1,3) (and all of this is
<br>
actually "touched" by one of the shapes, so the extents here are right,
<br>
as far as I can see). After multiplying by scale=20, this is exactly the
<br>
numbers you get here.
<br>
<br>
[etc for the other cases; I got a bit bored here].
<br>
<br>
So, I fail to understand the problem. Sorry.
<br>
<br>
Could you perhaps send an example that actually just reproduces the
<br>
problem and explain why you think that cairo should produce different
<br>
values here (and what those values are)?
<br>
<br>
Uli
<br>
--
<br>
Bitte nicht mit dem verbleibenden Auge in den Laser gucken.
<br>
- Vincent Ebert
<br>
</p>
</blockquote></div>