QLineF: add intersects() as a replacement for intersect()

QLineF::intersect() does not follow the naming rules for functions.
Therefore add a replacement function intersects() instead and also
rename the return type from IntersectType to IntersectionType

[ChangeLog][QtCore][QLineF] added QLineF::intersects() as a replacement
for QLineF::intersect()

Change-Id: I744b960ea339cb817facb12f296f78cca3e7d938
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
Reviewed-by: Konstantin Shegunov <kshegunov@gmail.com>
This commit is contained in:
Christian Ehrlicher 2019-03-03 12:14:43 +01:00
parent 220028d37c
commit c530ca1c17
5 changed files with 36 additions and 12 deletions

View File

@ -113,15 +113,13 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
QLineF centerLine(myStartItem->pos(), myEndItem->pos()); QLineF centerLine(myStartItem->pos(), myEndItem->pos());
QPolygonF endPolygon = myEndItem->polygon(); QPolygonF endPolygon = myEndItem->polygon();
QPointF p1 = endPolygon.first() + myEndItem->pos(); QPointF p1 = endPolygon.first() + myEndItem->pos();
QPointF p2;
QPointF intersectPoint; QPointF intersectPoint;
QLineF polyLine;
for (int i = 1; i < endPolygon.count(); ++i) { for (int i = 1; i < endPolygon.count(); ++i) {
p2 = endPolygon.at(i) + myEndItem->pos(); QPointF p2 = endPolygon.at(i) + myEndItem->pos();
polyLine = QLineF(p1, p2); QLineF polyLine = QLineF(p1, p2);
QLineF::IntersectType intersectType = QLineF::IntersectionType intersectionType =
polyLine.intersect(centerLine, &intersectPoint); polyLine.intersects(centerLine, &intersectPoint);
if (intersectType == QLineF::BoundedIntersection) if (intersectionType == QLineF::BoundedIntersection)
break; break;
p1 = p2; p1 = p2;
} }

View File

@ -347,7 +347,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line)
function to determine whether the QLineF represents a valid line function to determine whether the QLineF represents a valid line
or a null line. or a null line.
The intersect() function determines the IntersectType for this The intersects() function determines the IntersectionType for this
line and a given line, while the angleTo() function returns the line and a given line, while the angleTo() function returns the
angle between the lines. In addition, the unitVector() function angle between the lines. In addition, the unitVector() function
returns a line that has the same starting point as this line, but returns a line that has the same starting point as this line, but
@ -370,6 +370,11 @@ QDataStream &operator>>(QDataStream &stream, QLine &line)
/*! /*!
\enum QLineF::IntersectType \enum QLineF::IntersectType
\obsolete Use QLineF::IntersectionType instead
*/
/*!
\enum QLineF::IntersectionType
Describes the intersection between two lines. Describes the intersection between two lines.
@ -657,8 +662,10 @@ QLineF QLineF::unitVector() const
return f; return f;
} }
#if QT_DEPRECATED_SINCE(5, 14)
/*! /*!
\fn QLineF::IntersectType QLineF::intersect(const QLineF &line, QPointF *intersectionPoint) const \fn QLineF::IntersectType QLineF::intersect(const QLineF &line, QPointF *intersectionPoint) const
\obsolete Use intersects() instead
Returns a value indicating whether or not \e this line intersects Returns a value indicating whether or not \e this line intersects
with the given \a line. with the given \a line.
@ -669,6 +676,23 @@ QLineF QLineF::unitVector() const
*/ */
QLineF::IntersectType QLineF::intersect(const QLineF &l, QPointF *intersectionPoint) const QLineF::IntersectType QLineF::intersect(const QLineF &l, QPointF *intersectionPoint) const
{
return intersects(l, intersectionPoint);
}
#endif
/*!
\fn QLineF::IntersectionType QLineF::intersects(const QLineF &line, QPointF *intersectionPoint) const
\since 5.14
Returns a value indicating whether or not \e this line intersects
with the given \a line.
The actual intersection point is extracted to \a intersectionPoint
(if the pointer is valid). If the lines are parallel, the
intersection point is undefined.
*/
QLineF::IntersectionType QLineF::intersects(const QLineF &l, QPointF *intersectionPoint) const
{ {
// ipmlementation is based on Graphics Gems III's "Faster Line Segment Intersection" // ipmlementation is based on Graphics Gems III's "Faster Line Segment Intersection"
const QPointF a = pt2 - pt1; const QPointF a = pt2 - pt1;

View File

@ -215,6 +215,7 @@ class Q_CORE_EXPORT QLineF {
public: public:
enum IntersectType { NoIntersection, BoundedIntersection, UnboundedIntersection }; enum IntersectType { NoIntersection, BoundedIntersection, UnboundedIntersection };
using IntersectionType = IntersectType;
Q_DECL_CONSTEXPR inline QLineF(); Q_DECL_CONSTEXPR inline QLineF();
Q_DECL_CONSTEXPR inline QLineF(const QPointF &pt1, const QPointF &pt2); Q_DECL_CONSTEXPR inline QLineF(const QPointF &pt1, const QPointF &pt2);
@ -248,10 +249,11 @@ public:
Q_REQUIRED_RESULT QLineF unitVector() const; Q_REQUIRED_RESULT QLineF unitVector() const;
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QLineF normalVector() const; Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline QLineF normalVector() const;
// ### Qt 6: rename intersects() or intersection() and rename IntersectType IntersectionType IntersectionType intersects(const QLineF &l, QPointF *intersectionPoint) const;
IntersectType intersect(const QLineF &l, QPointF *intersectionPoint) const;
#if QT_DEPRECATED_SINCE(5, 14) #if QT_DEPRECATED_SINCE(5, 14)
QT_DEPRECATED_VERSION_X(5, 14, "Use intersects() instead")
IntersectType intersect(const QLineF &l, QPointF *intersectionPoint) const;
QT_DEPRECATED_X("Use angleTo() instead, take care that the return value is between 0 and 360 degree.") QT_DEPRECATED_X("Use angleTo() instead, take care that the return value is between 0 and 360 degree.")
qreal angle(const QLineF &l) const; qreal angle(const QLineF &l) const;
#endif #endif

View File

@ -456,7 +456,7 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine
QLineF prevLine(qt_fixed_to_real(m_back2X), qt_fixed_to_real(m_back2Y), QLineF prevLine(qt_fixed_to_real(m_back2X), qt_fixed_to_real(m_back2Y),
qt_fixed_to_real(m_back1X), qt_fixed_to_real(m_back1Y)); qt_fixed_to_real(m_back1X), qt_fixed_to_real(m_back1Y));
QPointF isect; QPointF isect;
QLineF::IntersectType type = prevLine.intersect(nextLine, &isect); QLineF::IntersectionType type = prevLine.intersects(nextLine, &isect);
if (join == FlatJoin) { if (join == FlatJoin) {
QLineF shortCut(prevLine.p2(), nextLine.p1()); QLineF shortCut(prevLine.p2(), nextLine.p1());

View File

@ -205,7 +205,7 @@ void tst_QLine::testIntersection()
QPointF ip; QPointF ip;
QLineF::IntersectType itype = a.intersect(b, &ip); QLineF::IntersectionType itype = a.intersect(b, &ip);
QCOMPARE(int(itype), type); QCOMPARE(int(itype), type);
if (type != QLineF::NoIntersection) { if (type != QLineF::NoIntersection) {