diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-05-12 16:50:24 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-05-18 08:55:16 +0000 |
commit | c25bce109ef4a2a1fa1bfd7ecd6aba871546dbff (patch) | |
tree | 31c2ad89f4cf6ebf5f9fe469cfc0ae173d2765c9 /src/gui | |
parent | acc134c8ea5f756dd605d0de50ca1a263383de2d (diff) |
Add QPolygon::intersects() methods
Corresponds to the similar function QPainterPath::intersects() and is
faster than calculating the intersection and then checking if it is
empty.
Change-Id: I694bb2206ed330a456a41d4118a952a68177b7a2
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qpolygon.cpp | 43 | ||||
-rw-r--r-- | src/gui/painting/qpolygon.h | 4 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp index 126b752811..3bf6004fcc 100644 --- a/src/gui/painting/qpolygon.cpp +++ b/src/gui/painting/qpolygon.cpp @@ -909,6 +909,8 @@ QPolygon QPolygon::united(const QPolygon &r) const Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed. + + \sa intersects() */ QPolygon QPolygon::intersected(const QPolygon &r) const @@ -938,6 +940,26 @@ QPolygon QPolygon::subtracted(const QPolygon &r) const } /*! + \since 5.10 + + Returns \c true if the current polygon intersects at any point the given polygon \a p. + Also returns \c true if the current polygon contains or is contained by any part of \a p. + + Set operations on polygons will treat the polygons as + areas. Non-closed polygons will be treated as implicitly closed. + + \sa intersected() +*/ + +bool QPolygon::intersects(const QPolygon &p) const +{ + QPainterPath subject; subject.addPolygon(*this); + QPainterPath clip; clip.addPolygon(p); + + return subject.intersects(clip); +} + +/*! \since 4.3 Returns a polygon which is the union of this polygon and \a r. @@ -964,6 +986,7 @@ QPolygonF QPolygonF::united(const QPolygonF &r) const Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed. + \sa intersects() */ QPolygonF QPolygonF::intersected(const QPolygonF &r) const @@ -992,6 +1015,26 @@ QPolygonF QPolygonF::subtracted(const QPolygonF &r) const } /*! + \since 5.10 + + Returns \c true if the current polygon intersects at any point the given polygon \a p. + Also returns \c true if the current polygon contains or is contained by any part of \a p. + + Set operations on polygons will treat the polygons as + areas. Non-closed polygons will be treated as implicitly closed. + + \sa intersected() +*/ + +bool QPolygonF::intersects(const QPolygonF &p) const +{ + QPainterPath subject; subject.addPolygon(*this); + QPainterPath clip; clip.addPolygon(p); + + return subject.intersects(clip); +} + +/*! Returns the polygon as a QVariant. */ diff --git a/src/gui/painting/qpolygon.h b/src/gui/painting/qpolygon.h index f192e8d10b..8e74a499fd 100644 --- a/src/gui/painting/qpolygon.h +++ b/src/gui/painting/qpolygon.h @@ -98,6 +98,8 @@ public: Q_REQUIRED_RESULT QPolygon united(const QPolygon &r) const; Q_REQUIRED_RESULT QPolygon intersected(const QPolygon &r) const; Q_REQUIRED_RESULT QPolygon subtracted(const QPolygon &r) const; + + bool intersects(const QPolygon &r) const; }; Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QPolygon) @@ -175,6 +177,8 @@ public: Q_REQUIRED_RESULT QPolygonF united(const QPolygonF &r) const; Q_REQUIRED_RESULT QPolygonF intersected(const QPolygonF &r) const; Q_REQUIRED_RESULT QPolygonF subtracted(const QPolygonF &r) const; + + bool intersects(const QPolygonF &r) const; }; Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QPolygonF) |