Example #1
0
QPainterPath BezierCurve::toPath(qreal t1, qreal t2, int samplePoints) const
{
    Q_ASSERT(t1 >= 0);
    Q_ASSERT(t1 <= 1);
    Q_ASSERT(t2 >= 0);
    Q_ASSERT(t2 <= 1);

    QPainterPath path;
    path.moveTo(pointAtPercent(t1));

    const qreal tau = (t2 - t1) / samplePoints;
    for (int i = 1; i <= samplePoints; ++i) {
        path.lineTo(pointAtPercent(t1 + i * tau));
    }
    return path;
}
Example #2
0
QPainterPath BezierCurve::toPath(int samplePoints) const
{
    QPainterPath path;
    path.moveTo(m_p1);
    for (int i = 1; i <= samplePoints; ++i) {
        path.lineTo(pointAtPercent(static_cast<qreal>(i) / samplePoints));
    }
    return path;
}
Example #3
0
qreal BezierCurve::intersect(const QPainterPath & path)
{
    const int samplePoints = 50;

    const qreal tau = 1.0 / samplePoints;

    for (int a = 0; a < samplePoints; ++a) {
        QLineF line1(pointAtPercent(a * tau),
                     pointAtPercent((a + 1) * tau));
        for (int b = 0; b < samplePoints; ++b) {
            QLineF line2(path.pointAtPercent(b * tau),
                         path.pointAtPercent((b + 1) * tau));

            QPointF crossing;
            if (QLineF::BoundedIntersection == line1.intersect(line2, &crossing)) {
                return a * tau;
            }
        }
    }

    return 0.0;
}
QPainterPath
ConnectionPainter::
getPainterStroke(ConnectionGeometry const& geom)
{
  auto cubic = cubicPath(geom);

  QPointF const& source = geom.source();
  QPainterPath result(source);

  unsigned segments = 20;

  for (auto i = 0ul; i < segments; ++i)
  {
    double ratio = double(i + 1) / segments;
    result.lineTo(cubic.pointAtPercent(ratio));
  }

  QPainterPathStroker stroker; stroker.setWidth(10.0);

  return stroker.createStroke(result);
}