31 static const qreal
eps = 1e-10;
33 QPointF vanishingX(t.m11() / t.m13(), t.m12() / t.m13());
34 QPointF vanishingY(t.m21() / t.m23(), t.m22() / t.m23());
36 if (qAbs(t.m13()) <
eps && qAbs(t.m23()) <
eps) {
39 }
else if (qAbs(t.m23()) <
eps) {
40 QPointF diff = t.map(QPointF(0.0, 10.0)) - t.map(QPointF());
41 vanishingY = vanishingX + diff;
42 }
else if (qAbs(t.m13()) <
eps) {
43 QPointF diff = t.map(QPointF(10.0, 0.0)) - t.map(QPointF());
44 vanishingX = vanishingY + diff;
47 *horizon = QLineF(vanishingX, vanishingY);
58 QPolygonF
getCroppedPolygon(
const QLineF &baseHorizon,
const QRect &rc,
const qreal crossCoeff) {
59 if (rc.isEmpty())
return QPolygonF();
61 QRectF boundsRect(rc);
62 QPolygonF polygon(boundsRect);
66 const qreal offsetLength = 10.0;
67 const QPointF horizonOffset = offsetLength * crossCoeff *
70 const QLineF horizon = baseHorizon.translated(horizonOffset);
73 const QPointF &basePoint = horizon.p1();
74 const QPointF horizonVec = horizon.p2() - basePoint;
78 QPointF prevPoint = polygon[polygon.size() - 1];
81 for (
int i = 0; i < polygon.size(); i++) {
82 const QPointF &pt = polygon[i];
86 if ((cross >= 0 && prevCross >= 0) || (cross == 0 && prevCross < 0)) {
88 }
else if (cross * prevCross < 0) {
90 QLineF edge(prevPoint, pt);
91 QLineF::IntersectType intersectionType =
92 horizon.intersects(edge, &intersection);
96 result << intersection;
107 if (result.size() > 0 && !result.isClosed()) {
108 result << result.first();