PDA

View Full Version : Qt4 : QPolygonF, how to recognize donuts ?



puiseux
24th November 2014, 18:28
hello,

P and Q are two QPolygonF, with Q strictly included in P. (think about donut, Q is the hole)

This instruction :


PmQ = P.subtracted(Q)

provides a new polygon PmQ, I can easily break down to obtain two polygons, say A and B. One is P, other is Q.

Later on, I need two recognize

- does PmQ comes from subtraction or union of two polygons ?
- which one is the hole ? Is it A or B ?


As I do this a lot of times, I'd like to avoid testing if A is included in B or B included in A.

Is there a simple solution ?

Thanks for your answer.

wysota
25th November 2014, 09:09
The hole is the one which has its bounding rectangle contained in the bounding rectangle of the other polygon.

ChrisW67
25th November 2014, 11:40
Qt's polygon classes do not support representing an object with a disconnected hole. The result of the subtraction is likely not what you are expecting.

puiseux
25th November 2014, 11:53
As far as i use it, QPolygonF union, subtraction, intersection give (almost) what I'm expected.
If two polygons P, Q have a non empty intersection, P.subtracted(Q) provides the real P \ Q if Q not entirely included in P.
If Q is include in P, the result is what i expect, provided i can interpret the result.
Results in other cases are sufficient for my use.
There are some approximations but if I need more precision, I've found GEOS.
Anyway, thanks for your answer and for your great work in Qt.