Qt4-preview-feedback Archive, April 2007
Illdefined interface for boolean operations on QPolygon/QPolygonF
Message 1 in thread
Hi,
I'm in need of boolean operations on polygons, so I was quite happy when I saw
that they are coming with Qt 4.3, although it's probably too late for the
project I'm currently developping.
But I noticed that the interface is ill-defined. The following three methods
(here taken from QPolygonF, but the problem is the same with QPolygon)
- QPolygonF intersected ( const QPolygonF & r ) const
- QPolygonF subtracted ( const QPolygonF & r ) const
- QPolygonF united ( const QPolygonF & r ) const
all return just a QPolygonF, but in realty each of the method may return more
than one polygon as a result. Eg if you have unit squares at point (0,0) and
(5,5) the unification of them is not one polygon but two. Subtracting may put
a hole into the first polygon or divide it. Even with intersection there are
cases where the result is several polygons and not just one.
I see two possible solutions:
1. return a QList<QPolygonF>
This is nicer if you are just interested in polygons, but if you want to
operate on more than two polygons you'll have to add three additional methods
which accept a QList<QPolygonF> as parameter, otherwise you are in the void
2. return a QPainterPath
If you are just interested in polygons (and especially QPolygon with 'F' this
may be awkward), but QPainterPath already provides every necessary method
(and even a subtractedInverted()) and has a correct interface (because one
QPainterPath can contain several polygons).
Thanks,
Rammi
To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx
Message 2 in thread
On Sunday 22 April 2007 09:10, Rammi wrote:
> Hi,
>
> I'm in need of boolean operations on polygons, so I was quite happy when I
> saw that they are coming with Qt 4.3, although it's probably too late for
> the project I'm currently developping.
>
> But I noticed that the interface is ill-defined. The following three
> methods (here taken from QPolygonF, but the problem is the same with
> QPolygon) - QPolygonF intersected ( const QPolygonF & r ) const
> - QPolygonF subtracted ( const QPolygonF & r ) const
> - QPolygonF united ( const QPolygonF & r ) const
> all return just a QPolygonF, but in realty each of the method may return
> more than one polygon as a result.
No, they can't. The QPolygon operations always return the fill polygon for a
particular operation and not a random set of polygons that can be combined to
produce the fill. If you need direct geometrical representation of the
results you'll need to use QPainterPath's.
To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx
Message 3 in thread
Am Sonntag, 22. April 2007 18:05 schrieb Zack Rusin:
> On Sunday 22 April 2007 09:10, Rammi wrote:
> > Hi,
> >
> > I'm in need of boolean operations on polygons, so I was quite happy when
> > I saw that they are coming with Qt 4.3, although it's probably too late
> > for the project I'm currently developping.
> >
> > But I noticed that the interface is ill-defined. The following three
> > methods (here taken from QPolygonF, but the problem is the same with
> > QPolygon) - QPolygonF intersected ( const QPolygonF & r ) const
> > - QPolygonF subtracted ( const QPolygonF & r ) const
> > - QPolygonF united ( const QPolygonF & r ) const
> > all return just a QPolygonF, but in realty each of the method may return
> > more than one polygon as a result.
>
> No, they can't. The QPolygon operations always return the fill polygon for
> a particular operation and not a random set of polygons that can be
> combined to produce the fill. If you need direct geometrical representation
> of the results you'll need to use QPainterPath's.
>
I see. Then the only problem left is that this information is missing in the
documentation, at least in the official docs on http://doc.trolltech.com/4.3/
Thanks for your feedback,
Rammi
To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx