Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point in QPainter::drawConvexPolgon

From the docs:

QPainter offers two methods of painting QPolygons: drawPolygon and drawConvexPolygon.

Nowhere in the documentation is it made clear what the difference between them is. Additionally, the drawConvexPolygon docs state

If the supplied polygon is not convex, i.e. it contains at least one angle larger than 180 degrees, the results are undefined.

So... what is it for? I hoped the method would somehow find the convex hull of my polygon and paint that, however that doesn't seem to be the case.

like image 450
Nils Werner Avatar asked Oct 04 '22 19:10

Nils Werner


2 Answers

The QPainter::drawConvexPolygon() documentation says:

On some platforms (e.g. X11), the drawConvexPolygon() function can be faster than the drawPolygon() function.

So,

  • drawPolygon() is more generic as it also allows to paint non-convex polygons (but drawing might be slower)
  • drawConvexPolygon() can only be used to draw convex polygons, but might be faster on specific platforms

For example, when doing 3D-rendering, you can use a Polygon Mesh which consists of convex polygons only to make rendering simpler, in which case the faster drawConvexPolygon() would be the better choice (since you need to paint a large number of convex polygons).

like image 181
Andreas Fester Avatar answered Oct 13 '22 10:10

Andreas Fester


Determining which part of the polygon is the outside and inside (for filling purposes) makes different choices depending on if the polygon contains a convex region. Think about how to determine the inside of a star shape vs. the inside of a rectangle.

like image 33
john.pavan Avatar answered Oct 13 '22 12:10

john.pavan