void tst_QLine::testSet() { { QLine l; l.setP1(QPoint(1, 2)); l.setP2(QPoint(3, 4)); QCOMPARE(l.x1(), 1); QCOMPARE(l.y1(), 2); QCOMPARE(l.x2(), 3); QCOMPARE(l.y2(), 4); l.setPoints(QPoint(5, 6), QPoint(7, 8)); QCOMPARE(l.x1(), 5); QCOMPARE(l.y1(), 6); QCOMPARE(l.x2(), 7); QCOMPARE(l.y2(), 8); l.setLine(9, 10, 11, 12); QCOMPARE(l.x1(), 9); QCOMPARE(l.y1(), 10); QCOMPARE(l.x2(), 11); QCOMPARE(l.y2(), 12); } { QLineF l; l.setP1(QPointF(1, 2)); l.setP2(QPointF(3, 4)); QCOMPARE(l.x1(), 1.0); QCOMPARE(l.y1(), 2.0); QCOMPARE(l.x2(), 3.0); QCOMPARE(l.y2(), 4.0); l.setPoints(QPointF(5, 6), QPointF(7, 8)); QCOMPARE(l.x1(), 5.0); QCOMPARE(l.y1(), 6.0); QCOMPARE(l.x2(), 7.0); QCOMPARE(l.y2(), 8.0); l.setLine(9.0, 10.0, 11.0, 12.0); QCOMPARE(l.x1(), 9.0); QCOMPARE(l.y1(), 10.0); QCOMPARE(l.x2(), 11.0); QCOMPARE(l.y2(), 12.0); } }
QPointF Edge::qualityTextPoint(const QLineF &linePos) { QPointF middlePoint; middlePoint.setX((linePos.x1() + linePos.x2()) / 2); middlePoint.setY((linePos.y1() + linePos.y2()) / 2); middlePoint.setY(middlePoint.y()-20); return middlePoint; }
/*! Show the snap line. fade-in animation is started on the line if the line is positioned at a different place. Before starting the fade-in animation, the fade-out animation is stoped if it is running. */ void HsSnapLine::showLine(const QLineF &snapLine) { QLineF displayLine = snapLine; qreal angle = displayLine.angle(); if (qAbs(angle) == 0.0 || qAbs(angle) == 180.0) { //this is a horizontal line //adding 1 is required below, as the line is 3 pixels wide and is translated by 1 point before displaying if (displayLine.y1() != (line().y1()+1.0) ) { //this horizontal line is at new position horizontally if (isFadeOutAnimationRunning()) { //if fade-out animation is running, stop it, animation is running at old position stopFadeOutAnimation(); } //start fade-in animation at new position. startFadeInAnimation(); } else { //this horizontal line is at the old position horizontally if (isFadeOutAnimationRunning()) { //if fade-out animation is running, stop it, animation is running at old position stopFadeOutAnimation(); //start fade-in animation at the old position startFadeInAnimation(); } } displayLine.translate(0.0, -1.0); } if (qAbs(angle) == 90.0 || qAbs(angle) == 270.0) { //this is a vertical line if (displayLine.x1() != (line().x1()+1)) { //this Vertical line is at different position vertically if (isFadeOutAnimationRunning()) { stopFadeOutAnimation(); } startFadeInAnimation(); } else { if (isFadeOutAnimationRunning()) { stopFadeOutAnimation(); startFadeInAnimation(); } } displayLine.translate(-1.0, 0.0); } QLinearGradient gradient(displayLine.p1(), displayLine.p2()); gradient.setColorAt(0.0, Qt::white); QColor snapLineColor = HbColorScheme::color("qtc_hs_snapguide"); if (!snapLineColor.isValid()) { //if valid color is not loaded from the theme, the darkCyan color is used as a backup.color snapLineColor = Qt::darkCyan; } gradient.setColorAt(0.4, snapLineColor); gradient.setColorAt(0.6, snapLineColor); gradient.setColorAt(1.0, Qt::white); QBrush brush(gradient); QPen pen; pen.setWidth(3); pen.setCapStyle(Qt::RoundCap); pen.setBrush(brush); setPen(pen); setLine(displayLine); show(); }
void QgsAnnotationItem::updateBalloon() { //first test if the point is in the frame. In that case we don't need a balloon. if ( !mMapPositionFixed || ( mOffsetFromReferencePoint.x() < 0 && ( mOffsetFromReferencePoint.x() + mFrameSize.width() ) > 0 && mOffsetFromReferencePoint.y() < 0 && ( mOffsetFromReferencePoint.y() + mFrameSize.height() ) > 0 ) ) { mBalloonSegment = -1; return; } //edge list QList<QLineF> segmentList; segmentList << segment( 0 ); segmentList << segment( 1 ); segmentList << segment( 2 ); segmentList << segment( 3 ); //find closest edge / closest edge point double minEdgeDist = DBL_MAX; int minEdgeIndex = -1; QLineF minEdge; QgsPoint minEdgePoint; QgsPoint origin( 0, 0 ); for ( int i = 0; i < 4; ++i ) { QLineF currentSegment = segmentList.at( i ); QgsPoint currentMinDistPoint; double currentMinDist = origin.sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint ); if ( currentMinDist < minEdgeDist ) { minEdgeIndex = i; minEdgePoint = currentMinDistPoint; minEdgeDist = currentMinDist; minEdge = currentSegment; } } if ( minEdgeIndex < 0 ) { return; } //make that configurable for the item double segmentPointWidth = 10; mBalloonSegment = minEdgeIndex; QPointF minEdgeEnd = minEdge.p2(); mBalloonSegmentPoint1 = QPointF( minEdgePoint.x(), minEdgePoint.y() ); if ( sqrt( minEdgePoint.sqrDist( minEdgeEnd.x(), minEdgeEnd.y() ) ) < segmentPointWidth ) { mBalloonSegmentPoint1 = pointOnLineWithDistance( minEdge.p2(), minEdge.p1(), segmentPointWidth ); } mBalloonSegmentPoint2 = pointOnLineWithDistance( mBalloonSegmentPoint1, minEdge.p2(), 10 ); }
QRectF UBGeometryUtils::lineToInnerRect(const QLineF& pLine, const qreal& pWidth) { qreal centerX = (pLine.x1() + pLine.x2()) / 2; qreal centerY = (pLine.y1() + pLine.y2()) / 2; qreal side = sqrt((pWidth * pWidth) / 2); qreal halfSide = side / 2; return QRectF(centerX - halfSide, centerY - halfSide, side, side); }
void QTableManager::EUpdate(QgraphicsItemTable *table, qreal Vx, qreal Vy) { QRectF *up = new QRectF(table->GetUpRect()); QRectF *down = new QRectF(table->GetDownRect()); QRectF *right = new QRectF(table->GetRightRect()); QRectF *left = new QRectF(table->GetLeftRect()); //QPointF sbottom = sec->bottomRight() for ( int i = 0 ; i<ProjectData->NodeCount();i++){ QLineF line = ProjectData->getNode(i)->link->line(); QPointF *point = new QPointF(line.x1(),line.y1()); QPointF *point2 = new QPointF(line.x2(),line.y2()); qreal xbottom = 0 ; qreal ybottom = 0 ; if (ProjectData->getNode(i)->start==table){ xbottom = point->x(); ybottom = point->y(); // ProjectData->getNode(i)->link->setLine(xbottom,ybottom,point2->x(),point2->y()); } if (ProjectData->getNode(i)->end==table){ xbottom = point2->x(); ybottom = point2->y(); //xbottom = (bottom.x()*xbottom)/(bottom.x()+Vx); // ybottom = (bottom.y()*ybottom)/(bottom.y()+Vy); // ProjectData->getNode(i)->link->setLine(point->x(),point->y(),point2->x()+Vx,point2->y()+Vy); } if ((xbottom!=0 || ybottom !=0)){ if (right->contains(*point)||right->contains(*point2) ){ xbottom+=Vx; // y media. } if (up->contains(*point)|| up->contains(*point2)){ // media x } if (down->contains(*point)|| down->contains(*point2)){ // media x ybottom +=Vy; } if (left->contains(*point)||left->contains(*point2) ){ // media y. } if (ProjectData->getNode(i)->end==table) ProjectData->getNode(i)->link->setLine(point->x(),point->y(),point2->x()+Vx/2,point2->y()+Vy/2); else ProjectData->getNode(i)->link->setLine(xbottom,ybottom,point2->x(),point2->y()); } } }
static QLineF preciselyMap( const QTransform& transform, const QLineF& line ) { qreal fx1 = line.x1(); qreal fy1 = line.y1(); qreal fx2 = line.x2(); qreal fy2 = line.y2(); qreal x1 = transform.m11() * fx1 + transform.m21() * fy1 + transform.dx(); qreal y1 = transform.m12() * fx1 + transform.m22() * fy1 + transform.dy(); qreal x2 = transform.m11() * fx2 + transform.m21() * fy2 + transform.dx(); qreal y2 = transform.m12() * fx2 + transform.m22() * fy2 + transform.dy(); return QLineF( x1, y1, x2, y2 ); }
void PSV_ChartItem::updateCurrentMes(const QPointF &point) { QLineF vLine = m_vLineItem->line(); vLine.setP1(QPointF(point.x(),vLine.y1())); vLine.setP2(QPointF(point.x(),vLine.y2())); m_vLineItem->setLine(vLine); QLineF hLine = m_hLineItem->line(); hLine.setP1(QPointF(hLine.x1(),point.y())); hLine.setP2(QPointF(hLine.x2(),point.y())); m_hLineItem->setLine(hLine); m_currentMesItem->setHtml(getCurrentHtmMes(point.x())); m_currentMesItem->setPos(point.x(),point.y()+10); }
void SceneGridHandler::drawLineX(qreal pointX, QRectF const &sceneRect) { pointX -= sceneRect.x(); QLineF const newLine(pointX, 0, pointX, sceneRect.height()); // checking whether the scene already has this line or not. // if not (lineIsFound is false), then adding it foreach (QLineF const &line, mLines) { if (qAbs(line.x1() - newLine.x1()) < indistinguishabilitySpace && line.x2() == line.x1()) { return; } } mLines.push_back(newLine); }
void tst_QLine::testNormalVector() { QFETCH(double, x1); QFETCH(double, y1); QFETCH(double, x2); QFETCH(double, y2); QFETCH(double, nvx); QFETCH(double, nvy); QLineF l(x1, y1, x2, y2); QLineF n = l.normalVector(); QCOMPARE(l.x1(), n.x1()); QCOMPARE(l.y1(), n.y1()); QCOMPARE(n.dx(), qreal(nvx)); QCOMPARE(n.dy(), qreal(nvy)); }
void tst_QLine::testAngle2() { QFETCH(qreal, x1); QFETCH(qreal, y1); QFETCH(qreal, x2); QFETCH(qreal, y2); QFETCH(qreal, angle); QLineF line(x1, y1, x2, y2); QCOMPARE(line.angle(), angle); QLineF polar = QLineF::fromPolar(line.length(), angle); QVERIFY(qAbs(line.x1() - polar.x1()) < epsilon); QVERIFY(qAbs(line.y1() - polar.y1()) < epsilon); QVERIFY(qAbs(line.x2() - polar.x2()) < epsilon); QVERIFY(qAbs(line.y2() - polar.y2()) < epsilon); }
void WatchPaintEngine::damagePenStroke(const QLineF &line) { if (!_hasPen) return; const qreal a = line.angle(); const qreal sn = sinf(a); const qreal cs = cosf(a); const qreal w = _penWidth == 0.0 ? 1.0 : _penWidth; const qreal x1 = line.x1(); const qreal x2 = line.x2(); const qreal y1 = line.y1(); const qreal y2 = line.y2(); QPointF p1(x1-(w*sn/2.0f), y1+(w*cs/2.0f)); QPointF p2(x2+(w*sn/2.0f), y2-(w*cs/2.0f)); QRectF r = QRectF(p1, p2).normalized(); damageRect(r); }
qreal Slit::scalar(const Ray * ray) const { QLineF vector = ray->line(); qreal rx = vector.x1(); //x coordinate of ray starting point qreal ry = vector.y1(); //y coordinate of ray starting point qreal rdx = vector.dx(); //horizontal component of the ray's vector qreal rdy = vector.dy(); //vertical component of the ray's vector //calculate on which side of a ray do the slit's edges lie qreal l = rdy * (m_leftEdge.x() - rx) - rdx * (m_leftEdge.y() - ry); qreal r = rdy * (m_rightEdge.x() - rx) - rdx * (m_rightEdge.y() - ry); qreal sl = rdy * (m_leftSlitEdge.x() - rx) - rdx * (m_leftSlitEdge.y() - ry); qreal sr = rdy * (m_rightSlitEdge.x() - rx) - rdx * (m_rightSlitEdge.y() - ry); //pair of points lie on the same side of ray - intersection impossible if(((Settings::fuzzyIsGreaterThanZero(l) && Settings::fuzzyIsGreaterThanZero(sl)) || (Settings::fuzzyIsLessThanZero(l) && Settings::fuzzyIsLessThanZero(sl)))&&((Settings::fuzzyIsGreaterThanZero(r) && Settings::fuzzyIsGreaterThanZero(sr)) || (Settings::fuzzyIsLessThanZero(r) && Settings::fuzzyIsLessThanZero(sr)))) return -1.0; qreal sx = m_leftEdge.x(); //x coordinate of slit segment edge qreal sy = m_leftEdge.y(); //y coordinate of slit segment edge qreal sdx = m_rightEdge.x() - sx; //horizontal component of the slit segment's vector qreal sdy = m_rightEdge.y() - sy; //vertical component of the slit segment's vector //plug: (x = rx + d * rdx) and (y = ry + d * rdy) into line equation: (sdy * (x - sx) - sdx * (y - sy) = 0) and solve for d return (sdx * ry - sdy * rx + sdy * sx - sdx * sy) / (sdy * rdx - sdx * rdy); }
qreal PortHandler::nearestPointOfLinePort(int linePortNumber, QPointF const &location) const { qreal nearestPointOfLinePort = 0; QLineF linePort = transformPortForNodeSize(mLinePorts[linePortNumber]); qreal const y1 = linePort.y1(); qreal const y2 = linePort.y2(); qreal const x1 = linePort.x1(); qreal const x2 = linePort.x2(); if (x1 == x2) { nearestPointOfLinePort = (location.y() - y1) / (y2 - y1); } else if (y1 == y2) { nearestPointOfLinePort = (location.x() - x1) / (x2 - x1); } else { qreal const k = (y2 - y1) / (x2 - x1); qreal const b2 = location.y() + 1 / k * location.x(); qreal const b = y1 - k * x1; qreal const x3 = k / (1 + k * k) * (b2 - b); nearestPointOfLinePort = (x3 - x1) / (x2 - x1); } return nearestPointOfLinePort; }
QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pWidth) { qreal x1 = pLine.x1(); qreal y1 = pLine.y1(); qreal x2 = pLine.x2(); qreal y2 = pLine.y2(); qreal alpha = (90.0 - pLine.angle()) * PI / 180.0; qreal hypothenuse = pWidth / 2; // TODO UB 4.x PERF cache sin/cos table qreal opposite = sin(alpha) * hypothenuse; qreal adjacent = cos(alpha) * hypothenuse; QPointF p1a(x1 - adjacent, y1 - opposite); QPointF p1b(x1 + adjacent, y1 + opposite); QPointF p2a(x2 - adjacent, y2 - opposite); QPointF p2b(x2 + adjacent, y2 + opposite); QPainterPath painterPath; painterPath.moveTo(p1a); painterPath.lineTo(p2a); painterPath.arcTo(x2 - hypothenuse, y2 - hypothenuse, pWidth, pWidth, (90.0 + pLine.angle()), -180.0); //painterPath.lineTo(p2b); painterPath.lineTo(p1b); painterPath.arcTo(x1 - hypothenuse, y1 - hypothenuse, pWidth, pWidth, -1 * (90.0 - pLine.angle()), -180.0); painterPath.closeSubpath(); return painterPath.toFillPolygon(); }
/*! * \brief Places a line into given rectangle * \param the line * \param the rectangle * \return QLineF beginning and ending at the edges of the rectangle. */ QLineF GT::intersectLineRect(const QLineF &st, const QRectF &rect) { QLineF start = st; QPointF iss[3]; int i = 0; // Půlnoční velkorysý odhad: double longEnough = fabs(rect.bottom()) + fabs(rect.top()) + fabs(rect.left()) + fabs(rect.right()) + fabs(start.x1()) + fabs(start.x2()) + fabs(start.y1()) + fabs(start.y2()); start.setLength(longEnough); if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.bottomLeft(),rect.bottomRight()), iss + i)) i++; if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.bottomLeft(),rect.topLeft()), iss + i)) i++; if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.topRight(),rect.bottomRight()), iss + i)) i++; if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.topRight(),rect.topLeft()), iss + i)) i++; start.setLength(-longEnough); if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.bottomLeft(),rect.bottomRight()), iss + i)) i++; if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.bottomLeft(),rect.topLeft()), iss + i)) i++; if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.topRight(),rect.bottomRight()), iss + i)) i++; if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.topRight(),rect.topLeft()), iss + i)) i++; if (2 == i) return QLineF(iss[0],iss[1]); else return QLineF(); }
WWorldLineF transform(const QLineF& line) { return WWorldLineF(line.x1(), line.y1(), line.x2(), line.y2()); }
void TOSMWidget::drawLine(QPainter &painter, QLineF line) { painter.drawLine(w2s_x(line.x1()), w2s_y(line.y1()), w2s_x(line.x2()), w2s_y(line.y2())); }
QTCEXPORT(void,qtc_QGraphicsLineItem_line_qth)(void* x0, double* _ret_x1, double* _ret_y1, double* _ret_x2, double* _ret_y2) { QLineF tc = ((QGraphicsLineItem*)x0)->line(); *_ret_x1 = tc.x1(); *_ret_y1 = tc.y1(); *_ret_x2 = tc.x2(); *_ret_y2 = tc.y2(); return; }
void PSV_Public::printMes(const QVariant &mes, const QString &frefix) { QString message; int type = mes.type(); switch(type) { case QVariant::Bool : message = mes.toBool() ? "true":"false"; break; case QVariant::Color : { QColor color = mes.value<QColor>(); message = QObject::tr("colorname:%1,r=%2,g=%3,b=%4") .arg(color.name()) .arg(color.red()) .arg(color.green()) .arg(color.blue()); } break; case QVariant::Date: message = mes.toDate().toString("yyyy-MM-dd"); break; case QVariant::DateTime: message = mes.toDateTime().toString("yyyy-MM-dd hh:mm:ss"); break; case QVariant::Double: message = QString::number(mes.toDouble()); break; case QVariant::UInt: case QVariant::Int: message = QString::number(mes.toInt()); break; case QVariant::ULongLong: case QVariant::LongLong: message = QString::number(mes.toLongLong()); break; case QVariant::Line: { QLine line = mes.toLine(); message = QObject::tr("Line x1=%1,y1=%2,x2=%3,y2=%4") .arg(line.x1()).arg(line.y1()).arg(line.x2()).arg(line.y2()); } break; case QVariant::LineF: { QLineF lineF = mes.toLineF(); message = QObject::tr("LineF x1=%1,y1=%2,x2=%3,y2=%4") .arg(lineF.x1()).arg(lineF.y1()).arg(lineF.x2()).arg(lineF.y2()); } break; case QVariant::Point: { QPoint point = mes.toPoint(); message = QObject::tr("point x=%1,y=%2") .arg(point.x()).arg(point.y()); } break; case QVariant::PointF: { QPointF pointF = mes.toPointF(); message = QObject::tr("pointF x=%1,y=%2") .arg(pointF.x()).arg(pointF.y()); } break; case QVariant::Rect: { QRect rect = mes.toRect(); message = QObject::tr("rect x=%1,y=%2,width=%3,height=%4") .arg(rect.x()).arg(rect.y()).arg(rect.width()).arg(rect.height()); } break; case QVariant::RectF: { QRectF rectF = mes.toRect(); message = QObject::tr("rectF x=%1,y=%2,width=%3,height=%4") .arg(rectF.x()).arg(rectF.y()).arg(rectF.width()).arg(rectF.height()); } break; default: message = QObject::tr("type = %1,<%2>").arg(type).arg(mes.toString()); break; } QString outMes = QObject::tr("%1 %2").arg(frefix).arg(message); qDebug()<<QObject::tr("PSV_LIB:<%1>%2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")).arg(outMes); }
static bool lineXLessThan(const QLineF &firstLine, const QLineF &secondLine) { return firstLine.x1() < secondLine.x2(); }
void tst_QLine::testIntersection_data() { QTest::addColumn<double>("xa1"); QTest::addColumn<double>("ya1"); QTest::addColumn<double>("xa2"); QTest::addColumn<double>("ya2"); QTest::addColumn<double>("xb1"); QTest::addColumn<double>("yb1"); QTest::addColumn<double>("xb2"); QTest::addColumn<double>("yb2"); QTest::addColumn<int>("type"); QTest::addColumn<double>("ix"); QTest::addColumn<double>("iy"); QTest::newRow("parallel") << 1.0 << 1.0 << 3.0 << 4.0 << 5.0 << 6.0 << 7.0 << 9.0 << int(QLineF::NoIntersection) << 0.0 << 0.0; QTest::newRow("unbounded") << 1.0 << 1.0 << 5.0 << 5.0 << 0.0 << 4.0 << 3.0 << 4.0 << int(QLineF::UnboundedIntersection) << 4.0 << 4.0; QTest::newRow("bounded") << 1.0 << 1.0 << 5.0 << 5.0 << 0.0 << 4.0 << 5.0 << 4.0 << int(QLineF::BoundedIntersection) << 4.0 << 4.0; QTest::newRow("almost vertical") << 0.0 << 10.0 << 20.0000000000001 << 10.0 << 10.0 << 0.0 << 10.0 << 20.0 << int(QLineF::BoundedIntersection) << 10.0 << 10.0; QTest::newRow("almost horizontal") << 0.0 << 10.0 << 20.0 << 10.0 << 10.0000000000001 << 0.0 << 10.0 << 20.0 << int(QLineF::BoundedIntersection) << 10.0 << 10.0; QTest::newRow("long vertical") << 100.1599256468623 << 100.7861905065196 << 100.1599256468604 << -9999.78619050651 << 10.0 << 50.0 << 190.0 << 50.0 << int(QLineF::BoundedIntersection) << 100.1599256468622 << 50.0; QLineF baseA(0, -50, 0, 50); QLineF baseB(-50, 0, 50, 0); for (int i = 0; i < 1000; ++i) { QLineF a = QLineF::fromPolar(50, i); a.setP1(-a.p2()); QLineF b = QLineF::fromPolar(50, i * 0.997 + 90); b.setP1(-b.p2()); // make the qFuzzyCompare be a bit more lenient a = a.translated(1, 1); b = b.translated(1, 1); QTest::newRow(("rotation-" + QByteArray::number(i)).constData()) << (double)a.x1() << (double)a.y1() << (double)a.x2() << (double)a.y2() << (double)b.x1() << (double)b.y1() << (double)b.x2() << (double)b.y2() << int(QLineF::BoundedIntersection) << 1.0 << 1.0; } }