Wrong axis if scene rect smaller than need.

--HG--
branch : develop
This commit is contained in:
dismine 2014-11-11 10:16:37 +02:00
parent b3bfa1b027
commit 7f2546d02c
2 changed files with 16 additions and 8 deletions

View File

@ -33,6 +33,7 @@
#include <QPointF> #include <QPointF>
#include <QRectF> #include <QRectF>
#include <QtCore/qmath.h> #include <QtCore/qmath.h>
#include <climits>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -191,17 +192,24 @@ QLineF VGObject::BuildLine(const QPointF &p1, const qreal &length, const qreal &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VGObject::BuildRay(const QPointF &firstPoint, const qreal &angle, const QRectF &scRect) QPointF VGObject::BuildRay(const QPointF &firstPoint, const qreal &angle, const QRectF &scRect)
{ {
qreal diagonal = qSqrt(pow(scRect.height(), 2) + pow(scRect.width(), 2)); QRectF rect = scRect;
QLineF line = BuildLine(firstPoint, diagonal, angle); if (rect.contains(firstPoint) == false)
{
// If point outside of scene rect use the biggest rect that can be.
QRectF rectangle(INT_MIN, INT_MIN, INT_MAX, INT_MAX);
rect = rect.united(rectangle);
}
const qreal diagonal = qSqrt(pow(rect.height(), 2) + pow(rect.width(), 2));
const QLineF line = BuildLine(firstPoint, diagonal, angle);
return LineIntersectRect(scRect, line); return LineIntersectRect(rect, line);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QLineF VGObject::BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect) QLineF VGObject::BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect)
{ {
QPointF endP1 = BuildRay(p, angle+180, scRect); const QPointF endP1 = BuildRay(p, angle+180, scRect);
QPointF endP2 = BuildRay(p, angle, scRect); const QPointF endP2 = BuildRay(p, angle, scRect);
return QLineF(endP1, endP2); return QLineF(endP1, endP2);
} }
@ -219,7 +227,7 @@ QLineF VGObject::BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &s
* @param line line. * @param line line.
* @return point intersection. * @return point intersection.
*/ */
QPointF VGObject::LineIntersectRect(QRectF rec, QLineF line) QPointF VGObject::LineIntersectRect(const QRectF &rec, const QLineF &line)
{ {
qreal x1, y1, x2, y2; qreal x1, y1, x2, y2;
rec.getCoords(&x1, &y1, &x2, &y2); rec.getCoords(&x1, &y1, &x2, &y2);
@ -244,7 +252,7 @@ QPointF VGObject::LineIntersectRect(QRectF rec, QLineF line)
{ {
return point; return point;
} }
Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "There is no point of intersection."); Q_ASSERT_X(type == QLineF::BoundedIntersection, Q_FUNC_INFO, "There is no point of intersection.");
return point; return point;
} }

View File

@ -71,7 +71,7 @@ public:
static QLineF BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect); static QLineF BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect);
static QLineF BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect); static QLineF BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect);
static QPointF LineIntersectRect(QRectF rec, QLineF line); static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line);
static qint32 LineIntersectCircle(const QPointF &center, qreal radius, const QLineF &line, QPointF &p1, static qint32 LineIntersectCircle(const QPointF &center, qreal radius, const QLineF &line, QPointF &p1,
QPointF &p2); QPointF &p2);
static QPointF ClosestPoint(const QLineF &line, const QPointF &point); static QPointF ClosestPoint(const QLineF &line, const QPointF &point);