Qt 4.8
Classes | Macros | Functions
qpainterpath.cpp File Reference
#include "qpainterpath.h"
#include "qpainterpath_p.h"
#include <qbitmap.h>
#include <qdebug.h>
#include <qiodevice.h>
#include <qlist.h>
#include <qmatrix.h>
#include <qpen.h>
#include <qpolygon.h>
#include <qtextlayout.h>
#include <qvarlengtharray.h>
#include <qmath.h>
#include <private/qbezier_p.h>
#include <private/qfontengine_p.h>
#include <private/qnumeric_p.h>
#include <private/qobject_p.h>
#include <private/qpathclipper_p.h>
#include <private/qstroker_p.h>
#include <private/qtextengine_p.h>
#include <limits.h>

Go to the source code of this file.

Classes

struct  QPainterPathPrivateDeleter
 

Macros

#define PM_DISPLAY
 
#define PM_INIT
 
#define PM_MEASURE(x)
 
#define QT_BEZIER_A(bezier, coord)
 
#define QT_BEZIER_B(bezier, coord)
 
#define QT_BEZIER_C(bezier, coord)
 
#define QT_BEZIER_CHECK_T(bezier, t)
 
#define SIGN(x)   ((x < 0)?-1:1)
 

Functions

static QBezier bezierAtT (const QPainterPath &path, qreal t, qreal *startingLength, qreal *bezierLength)
 
static bool epsilonCompare (const QPointF &a, const QPointF &b, const QSizeF &epsilon)
 
QDataStreamoperator<< (QDataStream &s, const QPainterPath &p)
 
QDebug operator<< (QDebug s, const QPainterPath &p)
 
QDataStreamoperator>> (QDataStream &s, QPainterPath &p)
 
void qt_find_ellipse_coords (const QRectF &r, qreal angle, qreal length, QPointF *startPoint, QPointF *endPoint)
 
static bool qt_isect_curve_horizontal (const QBezier &bezier, qreal y, qreal x1, qreal x2, int depth=0)
 
static bool qt_isect_curve_vertical (const QBezier &bezier, qreal x, qreal y1, qreal y2, int depth=0)
 
static QRectF qt_painterpath_bezier_extrema (const QBezier &b)
 
static bool qt_painterpath_check_crossing (const QPainterPath *path, const QRectF &rect)
 
static void qt_painterpath_isect_curve (const QBezier &bezier, const QPointF &pt, int *winding, int depth=0)
 
static void qt_painterpath_isect_line (const QPointF &p1, const QPointF &p2, const QPointF &pos, int *winding)
 
static bool qt_painterpath_isect_line_rect (qreal x1, qreal y1, qreal x2, qreal y2, const QRectF &rect)
 
void qt_path_stroke_cubic_to (qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey, void *data)
 
void qt_path_stroke_line_to (qfixed x, qfixed y, void *data)
 
void qt_path_stroke_move_to (qfixed x, qfixed y, void *data)
 
QPainterPath qt_stroke_dash (const QPainterPath &path, qreal *dashes, int dashCount)
 
static qreal slopeAt (qreal t, qreal a, qreal b, qreal c, qreal d)
 

Macro Definition Documentation

◆ PM_DISPLAY

#define PM_DISPLAY

Definition at line 71 of file qpainterpath.cpp.

◆ PM_INIT

#define PM_INIT

Definition at line 69 of file qpainterpath.cpp.

◆ PM_MEASURE

#define PM_MEASURE (   x)

Definition at line 70 of file qpainterpath.cpp.

◆ QT_BEZIER_A

#define QT_BEZIER_A (   bezier,
  coord 
)
Value:
3 * (-bezier.coord##1 \
+ 3*bezier.coord##2 \
- 3*bezier.coord##3 \
+bezier.coord##4)

Definition at line 1419 of file qpainterpath.cpp.

Referenced by qt_painterpath_bezier_extrema().

◆ QT_BEZIER_B

#define QT_BEZIER_B (   bezier,
  coord 
)
Value:
6 * (bezier.coord##1 \
- 2*bezier.coord##2 \
+ bezier.coord##3)

Definition at line 1424 of file qpainterpath.cpp.

Referenced by qt_painterpath_bezier_extrema().

◆ QT_BEZIER_C

#define QT_BEZIER_C (   bezier,
  coord 
)
Value:
3 * (- bezier.coord##1 \
+ bezier.coord##2)

Definition at line 1428 of file qpainterpath.cpp.

Referenced by qt_painterpath_bezier_extrema().

◆ QT_BEZIER_CHECK_T

#define QT_BEZIER_CHECK_T (   bezier,
 
)
Value:
if (t >= 0 && t <= 1) { \
QPointF p(b.pointAt(t)); \
if (p.x() < minx) minx = p.x(); \
else if (p.x() > maxx) maxx = p.x(); \
if (p.y() < miny) miny = p.y(); \
else if (p.y() > maxy) maxy = p.y(); \
}

Definition at line 1431 of file qpainterpath.cpp.

Referenced by qt_painterpath_bezier_extrema().

◆ SIGN

#define SIGN (   x)    ((x < 0)?-1:1)

Function Documentation

◆ bezierAtT()

static QBezier bezierAtT ( const QPainterPath path,
qreal  t,
qreal startingLength,
qreal bezierLength 
)
inlinestatic

Definition at line 3027 of file qpainterpath.cpp.

Referenced by QPainterPath::angleAtPercent(), QPainterPath::pointAtPercent(), and QPainterPath::slopeAtPercent().

3028 {
3029  *startingLength = 0;
3030  if (t > 1)
3031  return QBezier();
3032 
3033  qreal curLen = 0;
3034  qreal totalLength = path.length();
3035 
3036  const int lastElement = path.elementCount() - 1;
3037  for (int i=0; i <= lastElement; ++i) {
3038  const QPainterPath::Element &e = path.elementAt(i);
3039 
3040  switch (e.type) {
3042  break;
3044  {
3045  QLineF line(path.elementAt(i-1), e);
3046  qreal llen = line.length();
3047  curLen += llen;
3048  if (i == lastElement || curLen/totalLength >= t) {
3049  *bezierLength = llen;
3050  QPointF a = path.elementAt(i-1);
3051  QPointF delta = e - a;
3052  return QBezier::fromPoints(a, a + delta / 3, a + 2 * delta / 3, e);
3053  }
3054  break;
3055  }
3057  {
3058  QBezier b = QBezier::fromPoints(path.elementAt(i-1),
3059  e,
3060  path.elementAt(i+1),
3061  path.elementAt(i+2));
3062  qreal blen = b.length();
3063  curLen += blen;
3064 
3065  if (i + 2 == lastElement || curLen/totalLength >= t) {
3066  *bezierLength = blen;
3067  return b;
3068  }
3069 
3070  i += 2;
3071  break;
3072  }
3073  default:
3074  break;
3075  }
3076  *startingLength = curLen;
3077  }
3078  return QBezier();
3079 }
ElementType type
the type of element
Definition: qpainterpath.h:81
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
double qreal
Definition: qglobal.h:1193
qreal length() const
Returns the length of the line.
Definition: qline.cpp:698
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
long ASN1_INTEGER_get ASN1_INTEGER * a
qreal length(qreal error=0.01) const
Definition: qbezier.cpp:529
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
qreal length() const
Returns the length of the current path.
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ epsilonCompare()

static bool epsilonCompare ( const QPointF a,
const QPointF b,
const QSizeF epsilon 
)
inlinestatic

Definition at line 2318 of file qpainterpath.cpp.

Referenced by QPainterPath::operator==().

2319 {
2320  return qAbs(a.x() - b.x()) <= epsilon.width()
2321  && qAbs(a.y() - b.y()) <= epsilon.height();
2322 }
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ operator<<() [1/2]

QDataStream& operator<< ( QDataStream s,
const QPainterPath p 
)

Definition at line 2509 of file qpainterpath.cpp.

Referenced by QPainterPath::detach().

2510 {
2511  if (p.isEmpty()) {
2512  s << 0;
2513  return s;
2514  }
2515 
2516  s << p.elementCount();
2517  for (int i=0; i < p.d_func()->elements.size(); ++i) {
2518  const QPainterPath::Element &e = p.d_func()->elements.at(i);
2519  s << int(e.type);
2520  s << double(e.x) << double(e.y);
2521  }
2522  s << p.d_func()->cStart;
2523  s << int(p.d_func()->fillRule);
2524  return s;
2525 }
ElementType type
the type of element
Definition: qpainterpath.h:81
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
Qt::FillRule fillRule
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ operator<<() [2/2]

QDebug operator<< ( QDebug  s,
const QPainterPath p 
)

Definition at line 3618 of file qpainterpath.cpp.

3619 {
3620  s.nospace() << "QPainterPath: Element count=" << p.elementCount() << endl;
3621  const char *types[] = {"MoveTo", "LineTo", "CurveTo", "CurveToData"};
3622  for (int i=0; i<p.elementCount(); ++i) {
3623  s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ')' << endl;
3624 
3625  }
3626  return s;
3627 }
ElementType type
the type of element
Definition: qpainterpath.h:81
QTextStream & endl(QTextStream &stream)
Writes &#39; &#39; to the stream and flushes the stream.
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
static const struct @32 types[]
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ operator>>()

QDataStream& operator>> ( QDataStream s,
QPainterPath p 
)

Definition at line 2539 of file qpainterpath.cpp.

2540 {
2541  int size;
2542  s >> size;
2543 
2544  if (size == 0)
2545  return s;
2546 
2547  p.ensureData(); // in case if p.d_func() == 0
2548  if (p.d_func()->elements.size() == 1) {
2549  Q_ASSERT(p.d_func()->elements.at(0).type == QPainterPath::MoveToElement);
2550  p.d_func()->elements.clear();
2551  }
2552  p.d_func()->elements.reserve(p.d_func()->elements.size() + size);
2553  for (int i=0; i<size; ++i) {
2554  int type;
2555  double x, y;
2556  s >> type;
2557  s >> x;
2558  s >> y;
2559  Q_ASSERT(type >= 0 && type <= 3);
2560  if (!qt_is_finite(x) || !qt_is_finite(y)) {
2561 #ifndef QT_NO_DEBUG
2562  qWarning("QDataStream::operator>>: NaN or Inf element found in path, skipping it");
2563 #endif
2564  continue;
2565  }
2567  p.d_func()->elements.append(elm);
2568  }
2569  s >> p.d_func()->cStart;
2570  int fillRule;
2571  s >> fillRule;
2572  Q_ASSERT(fillRule == Qt::OddEvenFill || Qt::WindingFill);
2573  p.d_func()->fillRule = Qt::FillRule(fillRule);
2574  p.d_func()->dirtyBounds = true;
2575  p.d_func()->dirtyControlBounds = true;
2576  return s;
2577 }
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
FillRule
Definition: qnamespace.h:1485
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::FillRule fillRule
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ qt_find_ellipse_coords()

void qt_find_ellipse_coords ( const QRectF r,
qreal  angle,
qreal  length,
QPointF startPoint,
QPointF endPoint 
)

Definition at line 97 of file qpainterpath.cpp.

Referenced by QPainterPath::arcMoveTo(), QVectorPath::convertToPainterPath(), qt_curves_for_arc(), and qt_t_for_arc_angle().

99 {
100  if (r.isNull()) {
101  if (startPoint)
102  *startPoint = QPointF();
103  if (endPoint)
104  *endPoint = QPointF();
105  return;
106  }
107 
108  qreal w2 = r.width() / 2;
109  qreal h2 = r.height() / 2;
110 
111  qreal angles[2] = { angle, angle + length };
112  QPointF *points[2] = { startPoint, endPoint };
113 
114  for (int i = 0; i < 2; ++i) {
115  if (!points[i])
116  continue;
117 
118  qreal theta = angles[i] - 360 * qFloor(angles[i] / 360);
119  qreal t = theta / 90;
120  // truncate
121  int quadrant = int(t);
122  t -= quadrant;
123 
124  t = qt_t_for_arc_angle(90 * t);
125 
126  // swap x and y?
127  if (quadrant & 1)
128  t = 1 - t;
129 
130  qreal a, b, c, d;
131  QBezier::coefficients(t, a, b, c, d);
132  QPointF p(a + b + c*QT_PATH_KAPPA, d + c + b*QT_PATH_KAPPA);
133 
134  // left quadrants
135  if (quadrant == 1 || quadrant == 2)
136  p.rx() = -p.x();
137 
138  // top quadrants
139  if (quadrant == 0 || quadrant == 1)
140  p.ry() = -p.y();
141 
142  *points[i] = r.center() + QPointF(w2 * p.x(), h2 * p.y());
143  }
144 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
int qFloor(qreal v)
Definition: qmath.h:73
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static void coefficients(qreal t, qreal &a, qreal &b, qreal &c, qreal &d)
Definition: qbezier_p.h:152
#define QT_PATH_KAPPA
Definition: qstroker_p.h:113
long ASN1_INTEGER_get ASN1_INTEGER * a
qreal qt_t_for_arc_angle(qreal angle)
Definition: qstroker.cpp:796
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal angle(const QPointF &p1, const QPointF &p2)
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ qt_isect_curve_horizontal()

static bool qt_isect_curve_horizontal ( const QBezier bezier,
qreal  y,
qreal  x1,
qreal  x2,
int  depth = 0 
)
static

Definition at line 2023 of file qpainterpath.cpp.

Referenced by qt_painterpath_check_crossing().

2024 {
2025  QRectF bounds = bezier.bounds();
2026 
2027  if (y >= bounds.top() && y < bounds.bottom()
2028  && bounds.right() >= x1 && bounds.left() < x2) {
2029  const qreal lower_bound = qreal(.01);
2030  if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound))
2031  return true;
2032 
2033  QBezier first_half, second_half;
2034  bezier.split(&first_half, &second_half);
2035  if (qt_isect_curve_horizontal(first_half, y, x1, x2, depth + 1)
2036  || qt_isect_curve_horizontal(second_half, y, x1, x2, depth + 1))
2037  return true;
2038  }
2039  return false;
2040 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
static bool qt_isect_curve_horizontal(const QBezier &bezier, qreal y, qreal x1, qreal x2, int depth=0)
double qreal
Definition: qglobal.h:1193
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRectF bounds() const
Definition: qbezier.cpp:223
void split(QBezier *firstHalf, QBezier *secondHalf) const
Definition: qbezier_p.h:224
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528

◆ qt_isect_curve_vertical()

static bool qt_isect_curve_vertical ( const QBezier bezier,
qreal  x,
qreal  y1,
qreal  y2,
int  depth = 0 
)
static

Definition at line 2042 of file qpainterpath.cpp.

Referenced by qt_painterpath_check_crossing().

2043 {
2044  QRectF bounds = bezier.bounds();
2045 
2046  if (x >= bounds.left() && x < bounds.right()
2047  && bounds.bottom() >= y1 && bounds.top() < y2) {
2048  const qreal lower_bound = qreal(.01);
2049  if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound))
2050  return true;
2051 
2052  QBezier first_half, second_half;
2053  bezier.split(&first_half, &second_half);
2054  if (qt_isect_curve_vertical(first_half, x, y1, y2, depth + 1)
2055  || qt_isect_curve_vertical(second_half, x, y1, y2, depth + 1))
2056  return true;
2057  }
2058  return false;
2059 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRectF bounds() const
Definition: qbezier.cpp:223
void split(QBezier *firstHalf, QBezier *secondHalf) const
Definition: qbezier_p.h:224
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
static bool qt_isect_curve_vertical(const QBezier &bezier, qreal x, qreal y1, qreal y2, int depth=0)

◆ qt_painterpath_bezier_extrema()

static QRectF qt_painterpath_bezier_extrema ( const QBezier b)
static

Definition at line 1441 of file qpainterpath.cpp.

Referenced by QPainterPath::computeBoundingRect().

1442 {
1443  qreal minx, miny, maxx, maxy;
1444 
1445  // initialize with end points
1446  if (b.x1 < b.x4) {
1447  minx = b.x1;
1448  maxx = b.x4;
1449  } else {
1450  minx = b.x4;
1451  maxx = b.x1;
1452  }
1453  if (b.y1 < b.y4) {
1454  miny = b.y1;
1455  maxy = b.y4;
1456  } else {
1457  miny = b.y4;
1458  maxy = b.y1;
1459  }
1460 
1461  // Update for the X extrema
1462  {
1463  qreal ax = QT_BEZIER_A(b, x);
1464  qreal bx = QT_BEZIER_B(b, x);
1465  qreal cx = QT_BEZIER_C(b, x);
1466  // specialcase quadratic curves to avoid div by zero
1467  if (qFuzzyIsNull(ax)) {
1468 
1469  // linear curves are covered by initialization.
1470  if (!qFuzzyIsNull(bx)) {
1471  qreal t = -cx / bx;
1472  QT_BEZIER_CHECK_T(b, t);
1473  }
1474 
1475  } else {
1476  const qreal tx = bx * bx - 4 * ax * cx;
1477 
1478  if (tx >= 0) {
1479  qreal temp = qSqrt(tx);
1480  qreal rcp = 1 / (2 * ax);
1481  qreal t1 = (-bx + temp) * rcp;
1482  QT_BEZIER_CHECK_T(b, t1);
1483 
1484  qreal t2 = (-bx - temp) * rcp;
1485  QT_BEZIER_CHECK_T(b, t2);
1486  }
1487  }
1488  }
1489 
1490  // Update for the Y extrema
1491  {
1492  qreal ay = QT_BEZIER_A(b, y);
1493  qreal by = QT_BEZIER_B(b, y);
1494  qreal cy = QT_BEZIER_C(b, y);
1495 
1496  // specialcase quadratic curves to avoid div by zero
1497  if (qFuzzyIsNull(ay)) {
1498 
1499  // linear curves are covered by initialization.
1500  if (!qFuzzyIsNull(by)) {
1501  qreal t = -cy / by;
1502  QT_BEZIER_CHECK_T(b, t);
1503  }
1504 
1505  } else {
1506  const qreal ty = by * by - 4 * ay * cy;
1507 
1508  if (ty > 0) {
1509  qreal temp = qSqrt(ty);
1510  qreal rcp = 1 / (2 * ay);
1511  qreal t1 = (-by + temp) * rcp;
1512  QT_BEZIER_CHECK_T(b, t1);
1513 
1514  qreal t2 = (-by - temp) * rcp;
1515  QT_BEZIER_CHECK_T(b, t2);
1516  }
1517  }
1518  }
1519  return QRectF(minx, miny, maxx - minx, maxy - miny);
1520 }
double qreal
Definition: qglobal.h:1193
#define QT_BEZIER_B(bezier, coord)
#define QT_BEZIER_CHECK_T(bezier, t)
qreal x4
Definition: qbezier_p.h:116
#define QT_BEZIER_A(bezier, coord)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal y4
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal qSqrt(qreal v)
Definition: qmath.h:205
#define QT_BEZIER_C(bezier, coord)

◆ qt_painterpath_check_crossing()

static bool qt_painterpath_check_crossing ( const QPainterPath path,
const QRectF rect 
)
static

Definition at line 2064 of file qpainterpath.cpp.

Referenced by QPainterPath::contains(), and QPainterPath::intersects().

2065 {
2066  QPointF last_pt;
2067  QPointF last_start;
2068  for (int i=0; i<path->elementCount(); ++i) {
2069  const QPainterPath::Element &e = path->elementAt(i);
2070 
2071  switch (e.type) {
2072 
2074  if (i > 0
2075  && qFuzzyCompare(last_pt.x(), last_start.x())
2076  && qFuzzyCompare(last_pt.y(), last_start.y())
2077  && qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(),
2078  last_start.x(), last_start.y(), rect))
2079  return true;
2080  last_start = last_pt = e;
2081  break;
2082 
2084  if (qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(), e.x, e.y, rect))
2085  return true;
2086  last_pt = e;
2087  break;
2088 
2090  {
2091  QPointF cp2 = path->elementAt(++i);
2092  QPointF ep = path->elementAt(++i);
2093  QBezier bezier = QBezier::fromPoints(last_pt, e, cp2, ep);
2094  if (qt_isect_curve_horizontal(bezier, rect.top(), rect.left(), rect.right())
2095  || qt_isect_curve_horizontal(bezier, rect.bottom(), rect.left(), rect.right())
2096  || qt_isect_curve_vertical(bezier, rect.left(), rect.top(), rect.bottom())
2097  || qt_isect_curve_vertical(bezier, rect.right(), rect.top(), rect.bottom()))
2098  return true;
2099  last_pt = ep;
2100  }
2101  break;
2102 
2103  default:
2104  break;
2105  }
2106  }
2107 
2108  // implicitly close last subpath
2109  if (last_pt != last_start
2110  && qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(),
2111  last_start.x(), last_start.y(), rect))
2112  return true;
2113 
2114  return false;
2115 }
ElementType type
the type of element
Definition: qpainterpath.h:81
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
static bool qt_isect_curve_horizontal(const QBezier &bezier, qreal y, qreal x1, qreal x2, int depth=0)
static bool qt_painterpath_isect_line_rect(qreal x1, qreal y1, qreal x2, qreal y2, const QRectF &rect)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
bool qFuzzyCompare(const QMatrix &m1, const QMatrix &m2)
The qFuzzyCompare function is for comparing two matrices using a fuzziness factor.
Definition: qmatrix.h:172
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
static bool qt_isect_curve_vertical(const QBezier &bezier, qreal x, qreal y1, qreal y2, int depth=0)

◆ qt_painterpath_isect_curve()

static void qt_painterpath_isect_curve ( const QBezier bezier,
const QPointF pt,
int *  winding,
int  depth = 0 
)
static

Definition at line 1846 of file qpainterpath.cpp.

Referenced by QPainterPath::contains().

1848 {
1849  qreal y = pt.y();
1850  qreal x = pt.x();
1851  QRectF bounds = bezier.bounds();
1852 
1853  // potential intersection, divide and try again...
1854  // Please note that a sideeffect of the bottom exclusion is that
1855  // horizontal lines are dropped, but this is correct according to
1856  // scan conversion rules.
1857  if (y >= bounds.y() && y < bounds.y() + bounds.height()) {
1858 
1859  // hit lower limit... This is a rough threshold, but its a
1860  // tradeoff between speed and precision.
1861  const qreal lower_bound = qreal(.001);
1862  if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound)) {
1863  // We make the assumption here that the curve starts to
1864  // approximate a line after while (i.e. that it doesn't
1865  // change direction drastically during its slope)
1866  if (bezier.pt1().x() <= x) {
1867  (*winding) += (bezier.pt4().y() > bezier.pt1().y() ? 1 : -1);
1868  }
1869  return;
1870  }
1871 
1872  // split curve and try again...
1873  QBezier first_half, second_half;
1874  bezier.split(&first_half, &second_half);
1875  qt_painterpath_isect_curve(first_half, pt, winding, depth + 1);
1876  qt_painterpath_isect_curve(second_half, pt, winding, depth + 1);
1877  }
1878 }
QPointF pt4() const
Definition: qbezier_p.h:97
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
double qreal
Definition: qglobal.h:1193
static void qt_painterpath_isect_curve(const QBezier &bezier, const QPointF &pt, int *winding, int depth=0)
QPointF pt1() const
Definition: qbezier_p.h:94
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRectF bounds() const
Definition: qbezier.cpp:223
void split(QBezier *firstHalf, QBezier *secondHalf) const
Definition: qbezier_p.h:224
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ qt_painterpath_isect_line()

static void qt_painterpath_isect_line ( const QPointF p1,
const QPointF p2,
const QPointF pos,
int *  winding 
)
static

Definition at line 1814 of file qpainterpath.cpp.

Referenced by QPainterPath::contains().

1818 {
1819  qreal x1 = p1.x();
1820  qreal y1 = p1.y();
1821  qreal x2 = p2.x();
1822  qreal y2 = p2.y();
1823  qreal y = pos.y();
1824 
1825  int dir = 1;
1826 
1827  if (qFuzzyCompare(y1, y2)) {
1828  // ignore horizontal lines according to scan conversion rule
1829  return;
1830  } else if (y2 < y1) {
1831  qreal x_tmp = x2; x2 = x1; x1 = x_tmp;
1832  qreal y_tmp = y2; y2 = y1; y1 = y_tmp;
1833  dir = -1;
1834  }
1835 
1836  if (y >= y1 && y < y2) {
1837  qreal x = x1 + ((x2 - x1) / (y2 - y1)) * (y - y1);
1838 
1839  // count up the winding number if we're
1840  if (x<=pos.x()) {
1841  (*winding) += dir;
1842  }
1843  }
1844 }
double qreal
Definition: qglobal.h:1193
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
bool qFuzzyCompare(const QMatrix &m1, const QMatrix &m2)
The qFuzzyCompare function is for comparing two matrices using a fuzziness factor.
Definition: qmatrix.h:172

◆ qt_painterpath_isect_line_rect()

static bool qt_painterpath_isect_line_rect ( qreal  x1,
qreal  y1,
qreal  x2,
qreal  y2,
const QRectF rect 
)
static

Definition at line 1943 of file qpainterpath.cpp.

Referenced by qt_painterpath_check_crossing().

1945 {
1946  qreal left = rect.left();
1947  qreal right = rect.right();
1948  qreal top = rect.top();
1949  qreal bottom = rect.bottom();
1950 
1951  enum { Left, Right, Top, Bottom };
1952  // clip the lines, after cohen-sutherland, see e.g. http://www.nondot.org/~sabre/graphpro/line6.html
1953  int p1 = ((x1 < left) << Left)
1954  | ((x1 > right) << Right)
1955  | ((y1 < top) << Top)
1956  | ((y1 > bottom) << Bottom);
1957  int p2 = ((x2 < left) << Left)
1958  | ((x2 > right) << Right)
1959  | ((y2 < top) << Top)
1960  | ((y2 > bottom) << Bottom);
1961 
1962  if (p1 & p2)
1963  // completely inside
1964  return false;
1965 
1966  if (p1 | p2) {
1967  qreal dx = x2 - x1;
1968  qreal dy = y2 - y1;
1969 
1970  // clip x coordinates
1971  if (x1 < left) {
1972  y1 += dy/dx * (left - x1);
1973  x1 = left;
1974  } else if (x1 > right) {
1975  y1 -= dy/dx * (x1 - right);
1976  x1 = right;
1977  }
1978  if (x2 < left) {
1979  y2 += dy/dx * (left - x2);
1980  x2 = left;
1981  } else if (x2 > right) {
1982  y2 -= dy/dx * (x2 - right);
1983  x2 = right;
1984  }
1985 
1986  p1 = ((y1 < top) << Top)
1987  | ((y1 > bottom) << Bottom);
1988  p2 = ((y2 < top) << Top)
1989  | ((y2 > bottom) << Bottom);
1990 
1991  if (p1 & p2)
1992  return false;
1993 
1994  // clip y coordinates
1995  if (y1 < top) {
1996  x1 += dx/dy * (top - y1);
1997  y1 = top;
1998  } else if (y1 > bottom) {
1999  x1 -= dx/dy * (y1 - bottom);
2000  y1 = bottom;
2001  }
2002  if (y2 < top) {
2003  x2 += dx/dy * (top - y2);
2004  y2 = top;
2005  } else if (y2 > bottom) {
2006  x2 -= dx/dy * (y2 - bottom);
2007  y2 = bottom;
2008  }
2009 
2010  p1 = ((x1 < left) << Left)
2011  | ((x1 > right) << Right);
2012  p2 = ((x2 < left) << Left)
2013  | ((x2 > right) << Right);
2014 
2015  if (p1 & p2)
2016  return false;
2017 
2018  return true;
2019  }
2020  return false;
2021 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
QTextStream & right(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream...
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QTextStream & left(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream...

◆ qt_path_stroke_cubic_to()

void qt_path_stroke_cubic_to ( qfixed  c1x,
qfixed  c1y,
qfixed  c2x,
qfixed  c2y,
qfixed  ex,
qfixed  ey,
void *  data 
)

Definition at line 2595 of file qpainterpath.cpp.

Referenced by QPainterPathStrokerPrivate::QPainterPathStrokerPrivate().

2599 {
2600  ((QPainterPath *) data)->cubicTo(qt_fixed_to_real(c1x), qt_fixed_to_real(c1y),
2603 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
static const char * data(const QByteArray &arr)
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

◆ qt_path_stroke_line_to()

void qt_path_stroke_line_to ( qfixed  x,
qfixed  y,
void *  data 
)

Definition at line 2590 of file qpainterpath.cpp.

Referenced by QPainterPathStrokerPrivate::QPainterPathStrokerPrivate().

2591 {
2592  ((QPainterPath *) data)->lineTo(qt_fixed_to_real(x), qt_fixed_to_real(y));
2593 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
static const char * data(const QByteArray &arr)
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

◆ qt_path_stroke_move_to()

void qt_path_stroke_move_to ( qfixed  x,
qfixed  y,
void *  data 
)

Definition at line 2585 of file qpainterpath.cpp.

Referenced by QPainterPathStrokerPrivate::QPainterPathStrokerPrivate().

2586 {
2587  ((QPainterPath *) data)->moveTo(qt_fixed_to_real(x), qt_fixed_to_real(y));
2588 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
static const char * data(const QByteArray &arr)
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

◆ qt_stroke_dash()

QPainterPath qt_stroke_dash ( const QPainterPath path,
qreal dashes,
int  dashCount 
)

◆ slopeAt()

static qreal slopeAt ( qreal  t,
qreal  a,
qreal  b,
qreal  c,
qreal  d 
)
inlinestatic

Definition at line 2922 of file qpainterpath.cpp.

Referenced by QPainterPath::angleAtPercent(), and QPainterPath::slopeAtPercent().

2923 {
2924  return 3*t*t*(d - 3*c + 3*b - a) + 6*t*(c - 2*b + a) + 3*(b - a);
2925 }
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
long ASN1_INTEGER_get ASN1_INTEGER * a