Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QBezier Class Reference

#include <qbezier_p.h>

Public Functions

void addIfClose (qreal *length, qreal error) const
 
void addToPolygon (QPolygonF *p, qreal bezier_flattening_threshold=0.5) const
 
QBezier bezierOnInterval (qreal t0, qreal t1) const
 
QRectF bounds () const
 
QPointF derivedAt (qreal t) const
 
QLineF endTangent () const
 
QBezier getSubRange (qreal t0, qreal t1) const
 
qreal length (qreal error=0.01) const
 
QBezier mapBy (const QTransform &transform) const
 
QPointF midPoint () const
 
QLineF midTangent () const
 
QPointF normalVector (qreal t) const
 
void parameterSplitLeft (qreal t, QBezier *left)
 
QPointF pointAt (qreal t) const
 
QPointF pt1 () const
 
QPointF pt2 () const
 
QPointF pt3 () const
 
QPointF pt4 () const
 
QPointF secondDerivedAt (qreal t) const
 
int shifted (QBezier *curveSegments, int maxSegmets, qreal offset, float threshold) const
 
void split (QBezier *firstHalf, QBezier *secondHalf) const
 
QLineF startTangent () const
 
int stationaryYPoints (qreal &t0, qreal &t1) const
 
qreal tAtLength (qreal len) const
 
qreal tForY (qreal t0, qreal t1, qreal y) const
 
QPolygonF toPolygon (qreal bezier_flattening_threshold=0.5) const
 

Static Public Functions

static void coefficients (qreal t, qreal &a, qreal &b, qreal &c, qreal &d)
 
static QBezier fromPoints (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
 

Public Variables

qreal x1
 
qreal x2
 
qreal x3
 
qreal x4
 
qreal y1
 
qreal y2
 
qreal y3
 
qreal y4
 

Detailed Description

Definition at line 68 of file qbezier_p.h.

Functions

◆ addIfClose()

void QBezier::addIfClose ( qreal length,
qreal  error 
) const

Definition at line 538 of file qbezier.cpp.

Referenced by addIfClose(), and length().

539 {
540  QBezier left, right; /* bez poly splits */
541 
542  qreal len = qreal(0.0); /* arc length */
543  qreal chord; /* chord length */
544 
545  len = len + QLineF(QPointF(x1, y1),QPointF(x2, y2)).length();
546  len = len + QLineF(QPointF(x2, y2),QPointF(x3, y3)).length();
547  len = len + QLineF(QPointF(x3, y3),QPointF(x4, y4)).length();
548 
549  chord = QLineF(QPointF(x1, y1),QPointF(x4, y4)).length();
550 
551  if((len-chord) > error) {
552  split(&left, &right); /* split in two */
553  left.addIfClose(length, error); /* try left side */
554  right.addIfClose(length, error); /* try right side */
555  return;
556  }
557 
558  *length = *length + len;
559 
560  return;
561 }
double qreal
Definition: qglobal.h:1193
qreal length() const
Returns the length of the line.
Definition: qline.cpp:698
#define error(msg)
qreal x2
Definition: qbezier_p.h:116
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal length(qreal error=0.01) const
Definition: qbezier.cpp:529
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void addIfClose(qreal *length, qreal error) const
Definition: qbezier.cpp:538
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
void split(QBezier *firstHalf, QBezier *secondHalf) const
Definition: qbezier_p.h:224
qreal y1
Definition: qbezier_p.h:116
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
qreal y3
Definition: qbezier_p.h:116

◆ addToPolygon()

void QBezier::addToPolygon ( QPolygonF p,
qreal  bezier_flattening_threshold = 0.5 
) const

Definition at line 191 of file qbezier.cpp.

Referenced by toPolygon().

192 {
193  QBezier beziers[32];
194  beziers[0] = *this;
195  QBezier *b = beziers;
196 
197  while (b >= beziers) {
198  // check if we can pop the top bezier curve from the stack
199  qreal y4y1 = b->y4 - b->y1;
200  qreal x4x1 = b->x4 - b->x1;
201  qreal l = qAbs(x4x1) + qAbs(y4y1);
202  qreal d;
203  if (l > 1.) {
204  d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) )
205  + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) );
206  } else {
207  d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) +
208  qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);
209  l = 1.;
210  }
211  if (d < bezier_flattening_threshold*l || b == beziers + 31) {
212  // good enough, we pop it off and add the endpoint
213  polygon->append(QPointF(b->x4, b->y4));
214  --b;
215  } else {
216  // split, second half of the polygon goes lower into the stack
217  b->split(b+1, b);
218  ++b;
219  }
220  }
221 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
qreal x2
Definition: qbezier_p.h:116
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
QFactoryLoader * l
qreal x1
Definition: qbezier_p.h:116
void split(QBezier *firstHalf, QBezier *secondHalf) const
Definition: qbezier_p.h:224
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ bezierOnInterval()

QBezier QBezier::bezierOnInterval ( qreal  t0,
qreal  t1 
) const

Definition at line 687 of file qbezier.cpp.

Referenced by qt_curves_for_arc().

688 {
689  if (t0 == 0 && t1 == 1)
690  return *this;
691 
692  QBezier bezier = *this;
693 
694  QBezier result;
695  bezier.parameterSplitLeft(t0, &result);
696  qreal trueT = (t1-t0)/(1-t0);
697  bezier.parameterSplitLeft(trueT, &result);
698 
699  return result;
700 }
double qreal
Definition: qglobal.h:1193
void parameterSplitLeft(qreal t, QBezier *left)
Definition: qbezier_p.h:248

◆ bounds()

QRectF QBezier::bounds ( ) const

Definition at line 223 of file qbezier.cpp.

Referenced by QGL2PEXVertexArray::addPath(), QPathSegments::addPath(), QTriangulatingStroker::cubicTo(), QDashedStrokeProcessor::process(), qt_isect_curve_horizontal(), qt_isect_curve_vertical(), qt_painterpath_isect_curve(), and shift().

224 {
225  qreal xmin = x1;
226  qreal xmax = x1;
227  if (x2 < xmin)
228  xmin = x2;
229  else if (x2 > xmax)
230  xmax = x2;
231  if (x3 < xmin)
232  xmin = x3;
233  else if (x3 > xmax)
234  xmax = x3;
235  if (x4 < xmin)
236  xmin = x4;
237  else if (x4 > xmax)
238  xmax = x4;
239 
240  qreal ymin = y1;
241  qreal ymax = y1;
242  if (y2 < ymin)
243  ymin = y2;
244  else if (y2 > ymax)
245  ymax = y2;
246  if (y3 < ymin)
247  ymin = y3;
248  else if (y3 > ymax)
249  ymax = y3;
250  if (y4 < ymin)
251  ymin = y4;
252  else if (y4 > ymax)
253  ymax = y4;
254  return QRectF(xmin, ymin, xmax-xmin, ymax-ymin);
255 }
double qreal
Definition: qglobal.h:1193
qreal x2
Definition: qbezier_p.h:116
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
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 x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ coefficients()

void QBezier::coefficients ( qreal  t,
qreal a,
qreal b,
qreal c,
qreal d 
)
inlinestatic

Definition at line 152 of file qbezier_p.h.

Referenced by qt_find_ellipse_coords(), and tForY().

153 {
154  qreal m_t = 1. - t;
155  b = m_t * m_t;
156  c = t * t;
157  d = c * t;
158  a = b * m_t;
159  b *= 3. * t;
160  c *= 3. * m_t;
161 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ derivedAt()

QPointF QBezier::derivedAt ( qreal  t) const
inline

Definition at line 198 of file qbezier_p.h.

199 {
200  // p'(t) = 3 * (-(1-2t+t^2) * p0 + (1 - 4 * t + 3 * t^2) * p1 + (2 * t - 3 * t^2) * p2 + t^2 * p3)
201 
202  qreal m_t = 1. - t;
203 
204  qreal d = t * t;
205  qreal a = -m_t * m_t;
206  qreal b = 1 - 4 * t + 3 * d;
207  qreal c = 2 * t - 3 * d;
208 
209  return 3 * QPointF(a * x1 + b * x2 + c * x3 + d * x4,
210  a * y1 + b * y2 + c * y3 + d * y4);
211 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
qreal x2
Definition: qbezier_p.h:116
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 y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ endTangent()

QLineF QBezier::endTangent ( ) const
inline

Definition at line 142 of file qbezier_p.h.

143 {
144  QLineF tangent(pt4(), pt3());
145  if (tangent.isNull())
146  tangent = QLineF(pt4(), pt2());
147  if (tangent.isNull())
148  tangent = QLineF(pt4(), pt1());
149  return tangent;
150 }
QPointF pt4() const
Definition: qbezier_p.h:97
QPointF pt1() const
Definition: qbezier_p.h:94
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QPointF pt2() const
Definition: qbezier_p.h:95
QPointF pt3() const
Definition: qbezier_p.h:96

◆ fromPoints()

QBezier QBezier::fromPoints ( const QPointF p1,
const QPointF p2,
const QPointF p3,
const QPointF p4 
)
static
Warning
This function is not part of the public interface.

Definition at line 71 of file qbezier.cpp.

Referenced by QGL2PEXVertexArray::addPath(), QPathSegments::addPath(), bezierAtT(), QPainterPath::computeBoundingRect(), QPainterPath::contains(), QTriangulatingStroker::cubicTo(), cubicTo_clipped(), QOpenGLPaintEnginePrivate::curveToStencil(), QTriangulator< T >::initialize(), QPainterPath::length(), mapBy(), QSubpathFlatIterator::next(), nextBezier(), QPainterPath::percentAtLength(), QDashedStrokeProcessor::process(), qt_curves_for_arc(), qt_painterpath_check_crossing(), qt_stroke_side(), shift(), QOpenGLPaintEnginePrivate::strokePathFastPen(), and QPainterPath::toSubpathPolygons().

73 {
74  QBezier b;
75  b.x1 = p1.x();
76  b.y1 = p1.y();
77  b.x2 = p2.x();
78  b.y2 = p2.y();
79  b.x3 = p3.x();
80  b.y3 = p3.y();
81  b.x4 = p4.x();
82  b.y4 = p4.y();
83  return b;
84 }
qreal x2
Definition: qbezier_p.h:116
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ getSubRange()

QBezier QBezier::getSubRange ( qreal  t0,
qreal  t1 
) const

Definition at line 113 of file qbezier.cpp.

114 {
115  QBezier result;
116  QBezier temp;
117 
118  // cut at t1
119  if (qFuzzyIsNull(t1 - qreal(1.))) {
120  result = *this;
121  } else {
122  temp = *this;
123  temp.parameterSplitLeft(t1, &result);
124  }
125 
126  // cut at t0
127  if (!qFuzzyIsNull(t0))
128  result.parameterSplitLeft(t0 / t1, &temp);
129 
130  return result;
131 }
double qreal
Definition: qglobal.h:1193
void parameterSplitLeft(qreal t, QBezier *left)
Definition: qbezier_p.h:248
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043

◆ length()

qreal QBezier::length ( qreal  error = 0.01) const

Definition at line 529 of file qbezier.cpp.

Referenced by bezierAtT(), QPainterPath::length(), nextBezier(), QPainterPath::percentAtLength(), and tAtLength().

530 {
531  qreal length = qreal(0.0);
532 
533  addIfClose(&length, error);
534 
535  return length;
536 }
double qreal
Definition: qglobal.h:1193
#define error(msg)
qreal length(qreal error=0.01) const
Definition: qbezier.cpp:529
void addIfClose(qreal *length, qreal error) const
Definition: qbezier.cpp:538

◆ mapBy()

QBezier QBezier::mapBy ( const QTransform transform) const

Definition at line 108 of file qbezier.cpp.

109 {
110  return QBezier::fromPoints(transform.map(pt1()), transform.map(pt2()), transform.map(pt3()), transform.map(pt4()));
111 }
QPointF pt4() const
Definition: qbezier_p.h:97
QPointF pt1() const
Definition: qbezier_p.h:94
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPointF pt2() const
Definition: qbezier_p.h:95
QPointF pt3() const
Definition: qbezier_p.h:96

◆ midPoint()

QPointF QBezier::midPoint ( ) const
inline

Definition at line 119 of file qbezier_p.h.

120 {
121  return QPointF((x1 + x4 + 3*(x2 + x3))/8., (y1 + y4 + 3*(y2 + y3))/8.);
122 }
qreal x2
Definition: qbezier_p.h:116
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ midTangent()

QLineF QBezier::midTangent ( ) const
inline

Definition at line 124 of file qbezier_p.h.

125 {
126  QPointF mid = midPoint();
127  QLineF dir(QLineF(x1, y1, x2, y2).pointAt(0.5), QLineF(x3, y3, x4, y4).pointAt(0.5));
128  return QLineF(mid.x() - dir.dx(), mid.y() - dir.dy(),
129  mid.x() + dir.dx(), mid.y() + dir.dy());
130 }
qreal x2
Definition: qbezier_p.h:116
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF pointAt(qreal t) const
Definition: qbezier_p.h:163
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
QPointF midPoint() const
Definition: qbezier_p.h:119
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ normalVector()

QPointF QBezier::normalVector ( qreal  t) const
inline

Definition at line 188 of file qbezier_p.h.

Referenced by good_offset().

189 {
190  qreal m_t = 1. - t;
191  qreal a = m_t * m_t;
192  qreal b = t * m_t;
193  qreal c = t * t;
194 
195  return QPointF((y2-y1) * a + (y3-y2) * b + (y4-y3) * c, -(x2-x1) * a - (x3-x2) * b - (x4-x3) * c);
196 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
qreal x2
Definition: qbezier_p.h:116
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 y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ parameterSplitLeft()

void QBezier::parameterSplitLeft ( qreal  t,
QBezier left 
)
inline

Definition at line 248 of file qbezier_p.h.

Referenced by bezierOnInterval(), getSubRange(), and tAtLength().

249 {
250  left->x1 = x1;
251  left->y1 = y1;
252 
253  left->x2 = x1 + t * ( x2 - x1 );
254  left->y2 = y1 + t * ( y2 - y1 );
255 
256  left->x3 = x2 + t * ( x3 - x2 ); // temporary holding spot
257  left->y3 = y2 + t * ( y3 - y2 ); // temporary holding spot
258 
259  x3 = x3 + t * ( x4 - x3 );
260  y3 = y3 + t * ( y4 - y3 );
261 
262  x2 = left->x3 + t * ( x3 - left->x3);
263  y2 = left->y3 + t * ( y3 - left->y3);
264 
265  left->x3 = left->x2 + t * ( left->x3 - left->x2 );
266  left->y3 = left->y2 + t * ( left->y3 - left->y2 );
267 
268  left->x4 = x1 = left->x3 + t * (x2 - left->x3);
269  left->y4 = y1 = left->y3 + t * (y2 - left->y3);
270 }
qreal x2
Definition: qbezier_p.h:116
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ pointAt()

QPointF QBezier::pointAt ( qreal  t) const
inline

Definition at line 163 of file qbezier_p.h.

Referenced by QGL2PEXVertexArray::addPath(), QPathSegments::addPath(), QDeclarativePath::createPointCache(), QTriangulatingStroker::cubicTo(), good_offset(), QPainterPath::pointAtPercent(), QDashedStrokeProcessor::process(), and tForY().

164 {
165  // numerically more stable:
166  qreal x, y;
167 
168  qreal m_t = 1. - t;
169  {
170  qreal a = x1*m_t + x2*t;
171  qreal b = x2*m_t + x3*t;
172  qreal c = x3*m_t + x4*t;
173  a = a*m_t + b*t;
174  b = b*m_t + c*t;
175  x = a*m_t + b*t;
176  }
177  {
178  qreal a = y1*m_t + y2*t;
179  qreal b = y2*m_t + y3*t;
180  qreal c = y3*m_t + y4*t;
181  a = a*m_t + b*t;
182  b = b*m_t + c*t;
183  y = a*m_t + b*t;
184  }
185  return QPointF(x, y);
186 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
qreal x2
Definition: qbezier_p.h:116
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 y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ pt1()

QPointF QBezier::pt1 ( ) const
inline

Definition at line 94 of file qbezier_p.h.

Referenced by isLine(), mapBy(), qt_painterpath_isect_curve(), and qt_stroke_side().

94 { return QPointF(x1, y1); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116

◆ pt2()

QPointF QBezier::pt2 ( ) const
inline

Definition at line 95 of file qbezier_p.h.

Referenced by isLine(), mapBy(), qt_curves_for_arc(), and qt_stroke_side().

95 { return QPointF(x2, y2); }
qreal x2
Definition: qbezier_p.h:116
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal y2
Definition: qbezier_p.h:116

◆ pt3()

QPointF QBezier::pt3 ( ) const
inline

Definition at line 96 of file qbezier_p.h.

Referenced by isLine(), mapBy(), qt_curves_for_arc(), and qt_stroke_side().

96 { return QPointF(x3, y3); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x3
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ pt4()

QPointF QBezier::pt4 ( ) const
inline

Definition at line 97 of file qbezier_p.h.

Referenced by isLine(), mapBy(), qt_curves_for_arc(), qt_painterpath_isect_curve(), and qt_stroke_side().

97 { return QPointF(x4, y4); }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116

◆ secondDerivedAt()

QPointF QBezier::secondDerivedAt ( qreal  t) const
inline

Definition at line 213 of file qbezier_p.h.

214 {
215  qreal a = 2. - 2. * t;
216  qreal b = -4 + 6 * t;
217  qreal c = 2 - 6 * t;
218  qreal d = 2 * t;
219 
220  return 3 * QPointF(a * x1 + b * x2 + c * x3 + d * x4,
221  a * y1 + b * y2 + c * y3 + d * y4);
222 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
qreal x2
Definition: qbezier_p.h:116
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 y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ shifted()

int QBezier::shifted ( QBezier curveSegments,
int  maxSegmets,
qreal  offset,
float  threshold 
) const

Definition at line 433 of file qbezier.cpp.

Referenced by qt_stroke_side().

434 {
435  Q_ASSERT(curveSegments);
436  Q_ASSERT(maxSegments > 0);
437 
438  if (x1 == x2 && x1 == x3 && x1 == x4 &&
439  y1 == y2 && y1 == y3 && y1 == y4)
440  return 0;
441 
442  --maxSegments;
443  QBezier beziers[10];
444 redo:
445  beziers[0] = *this;
446  QBezier *b = beziers;
447  QBezier *o = curveSegments;
448 
449  while (b >= beziers) {
450  int stack_segments = b - beziers + 1;
451  if ((stack_segments == 10) || (o - curveSegments == maxSegments - stack_segments)) {
452  threshold *= qreal(1.5);
453  if (threshold > qreal(2.0))
454  goto give_up;
455  goto redo;
456  }
457  ShiftResult res = shift(b, o, offset, threshold);
458  if (res == Discard) {
459  --b;
460  } else if (res == Ok) {
461  ++o;
462  --b;
463  continue;
464  } else if (res == Circle && maxSegments - (o - curveSegments) >= 2) {
465  // add semi circle
466  if (addCircle(b, offset, o))
467  o += 2;
468  --b;
469  } else {
470  b->split(b+1, b);
471  ++b;
472  }
473  }
474 
475 give_up:
476  while (b >= beziers) {
477  ShiftResult res = shift(b, o, offset, threshold);
478 
479  // if res isn't Ok or Split then *o is undefined
480  if (res == Ok || res == Split)
481  ++o;
482 
483  --b;
484  }
485 
486  Q_ASSERT(o - curveSegments <= maxSegments);
487  return o - curveSegments;
488 }
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
Definition: qbezier.cpp:289
double qreal
Definition: qglobal.h:1193
ShiftResult
Definition: qbezier.cpp:258
qreal x2
Definition: qbezier_p.h:116
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
Definition: qbezier.cpp:259
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
void split(QBezier *firstHalf, QBezier *secondHalf) const
Definition: qbezier_p.h:224
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116
static bool addCircle(const QBezier *b, qreal offset, QBezier *o)
Definition: qbezier.cpp:373

◆ split()

void QBezier::split ( QBezier firstHalf,
QBezier secondHalf 
) const
inline

Definition at line 224 of file qbezier_p.h.

Referenced by addIfClose(), addToPolygon(), qt_isect_curve_horizontal(), qt_isect_curve_vertical(), qt_painterpath_isect_curve(), shifted(), and QOpenGLPaintEnginePrivate::strokePathFastPen().

225 {
226  Q_ASSERT(firstHalf);
227  Q_ASSERT(secondHalf);
228 
229  qreal c = (x2 + x3)*.5;
230  firstHalf->x2 = (x1 + x2)*.5;
231  secondHalf->x3 = (x3 + x4)*.5;
232  firstHalf->x1 = x1;
233  secondHalf->x4 = x4;
234  firstHalf->x3 = (firstHalf->x2 + c)*.5;
235  secondHalf->x2 = (secondHalf->x3 + c)*.5;
236  firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2)*.5;
237 
238  c = (y2 + y3)/2;
239  firstHalf->y2 = (y1 + y2)*.5;
240  secondHalf->y3 = (y3 + y4)*.5;
241  firstHalf->y1 = y1;
242  secondHalf->y4 = y4;
243  firstHalf->y3 = (firstHalf->y2 + c)*.5;
244  secondHalf->y2 = (secondHalf->y3 + c)*.5;
245  firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2)*.5;
246 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
qreal x2
Definition: qbezier_p.h:116
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ startTangent()

QLineF QBezier::startTangent ( ) const
inline

Definition at line 132 of file qbezier_p.h.

Referenced by qt_stroke_side().

133 {
134  QLineF tangent(pt1(), pt2());
135  if (tangent.isNull())
136  tangent = QLineF(pt1(), pt3());
137  if (tangent.isNull())
138  tangent = QLineF(pt1(), pt4());
139  return tangent;
140 }
QPointF pt4() const
Definition: qbezier_p.h:97
QPointF pt1() const
Definition: qbezier_p.h:94
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QPointF pt2() const
Definition: qbezier_p.h:95
QPointF pt3() const
Definition: qbezier_p.h:96

◆ stationaryYPoints()

int QBezier::stationaryYPoints ( qreal t0,
qreal t1 
) const

Definition at line 605 of file qbezier.cpp.

606 {
607  // y(t) = (1 - t)^3 * y1 + 3 * (1 - t)^2 * t * y2 + 3 * (1 - t) * t^2 * y3 + t^3 * y4
608  // y'(t) = 3 * (-(1-2t+t^2) * y1 + (1 - 4 * t + 3 * t^2) * y2 + (2 * t - 3 * t^2) * y3 + t^2 * y4)
609  // y'(t) = 3 * ((-y1 + 3 * y2 - 3 * y3 + y4)t^2 + (2 * y1 - 4 * y2 + 2 * y3)t + (-y1 + y2))
610 
611  const qreal a = -y1 + 3 * y2 - 3 * y3 + y4;
612  const qreal b = 2 * y1 - 4 * y2 + 2 * y3;
613  const qreal c = -y1 + y2;
614 
615  if (qFuzzyIsNull(a)) {
616  if (qFuzzyIsNull(b))
617  return 0;
618 
619  t0 = -c / b;
620  return t0 > 0 && t0 < 1;
621  }
622 
623  qreal reciprocal = b * b - 4 * a * c;
624 
625  if (qFuzzyIsNull(reciprocal)) {
626  t0 = -b / (2 * a);
627  return t0 > 0 && t0 < 1;
628  } else if (reciprocal > 0) {
629  qreal temp = qSqrt(reciprocal);
630 
631  t0 = (-b - temp)/(2*a);
632  t1 = (-b + temp)/(2*a);
633 
634  if (t1 < t0)
635  qSwap(t0, t1);
636 
637  int count = 0;
638  qreal t[2] = { 0, 1 };
639 
640  if (t0 > 0 && t0 < 1)
641  t[count++] = t0;
642  if (t1 > 0 && t1 < 1)
643  t[count++] = t1;
644 
645  t0 = t[0];
646  t1 = t[1];
647 
648  return count;
649  }
650 
651  return 0;
652 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
long ASN1_INTEGER_get ASN1_INTEGER * a
qreal y2
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
qreal y1
Definition: qbezier_p.h:116
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal y3
Definition: qbezier_p.h:116
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ tAtLength()

qreal QBezier::tAtLength ( qreal  len) const

Definition at line 654 of file qbezier.cpp.

Referenced by QPainterPath::percentAtLength().

655 {
656  qreal len = length();
657  qreal t = qreal(1.0);
658  const qreal error = qreal(0.01);
659  if (l > len || qFuzzyCompare(l, len))
660  return t;
661 
662  t *= qreal(0.5);
663  //int iters = 0;
664  //qDebug()<<"LEN is "<<l<<len;
665  qreal lastBigger = qreal(1.0);
666  while (1) {
667  //qDebug()<<"\tt is "<<t;
668  QBezier right = *this;
669  QBezier left;
670  right.parameterSplitLeft(t, &left);
671  qreal lLen = left.length();
672  if (qAbs(lLen - l) < error)
673  break;
674 
675  if (lLen < l) {
676  t += (lastBigger - t) * qreal(0.5);
677  } else {
678  lastBigger = t;
679  t -= t * qreal(0.5);
680  }
681  //++iters;
682  }
683  //qDebug()<<"number of iters is "<<iters;
684  return t;
685 }
double qreal
Definition: qglobal.h:1193
void parameterSplitLeft(qreal t, QBezier *left)
Definition: qbezier_p.h:248
#define error(msg)
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
qreal length(qreal error=0.01) const
Definition: qbezier.cpp:529
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QFactoryLoader * l
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ tForY()

qreal QBezier::tForY ( qreal  t0,
qreal  t1,
qreal  y 
) const

Definition at line 563 of file qbezier.cpp.

564 {
565  qreal py0 = pointAt(t0).y();
566  qreal py1 = pointAt(t1).y();
567 
568  if (py0 > py1) {
569  qSwap(py0, py1);
570  qSwap(t0, t1);
571  }
572 
573  Q_ASSERT(py0 <= py1);
574 
575  if (py0 >= y)
576  return t0;
577  else if (py1 <= y)
578  return t1;
579 
580  Q_ASSERT(py0 < y && y < py1);
581 
582  qreal lt = t0;
583  qreal dt;
584  do {
585  qreal t = qreal(0.5) * (t0 + t1);
586 
587  qreal a, b, c, d;
588  QBezier::coefficients(t, a, b, c, d);
589  qreal yt = a * y1 + b * y2 + c * y3 + d * y4;
590 
591  if (yt < y) {
592  t0 = t;
593  py0 = yt;
594  } else {
595  t1 = t;
596  py1 = yt;
597  }
598  dt = lt - t;
599  lt = t;
600  } while (qAbs(dt) > qreal(1e-7));
601 
602  return t0;
603 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
static void coefficients(qreal t, qreal &a, qreal &b, qreal &c, qreal &d)
Definition: qbezier_p.h:152
long ASN1_INTEGER_get ASN1_INTEGER * a
QPointF pointAt(qreal t) const
Definition: qbezier_p.h:163
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal y2
Definition: qbezier_p.h:116
qreal y4
Definition: qbezier_p.h:116
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ toPolygon()

QPolygonF QBezier::toPolygon ( qreal  bezier_flattening_threshold = 0.5) const
Warning
This function is not part of the public interface.

Definition at line 89 of file qbezier.cpp.

Referenced by cubicTo_clipped(), and QTriangulator< T >::initialize().

90 {
91  // flattening is done by splitting the bezier until we can replace the segment by a straight
92  // line. We split further until the control points are close enough to the line connecting the
93  // boundary points.
94  //
95  // the Distance of a point p from a line given by the points (a,b) is given by:
96  //
97  // d = abs( (bx - ax)(ay - py) - (by - ay)(ax - px) ) / line_length
98  //
99  // We can stop splitting if both control points are close enough to the line.
100  // To make the algorithm faster we use the manhattan length of the line.
101 
102  QPolygonF polygon;
103  polygon.append(QPointF(x1, y1));
104  addToPolygon(&polygon, bezier_flattening_threshold);
105  return polygon;
106 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void addToPolygon(QPolygonF *p, qreal bezier_flattening_threshold=0.5) const
Definition: qbezier.cpp:191
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116

Properties

◆ x1

qreal QBezier::x1

◆ x2

qreal QBezier::x2

◆ x3

qreal QBezier::x3

◆ x4

qreal QBezier::x4

◆ y1

qreal QBezier::y1

◆ y2

qreal QBezier::y2

◆ y3

qreal QBezier::y3

◆ y4

qreal QBezier::y4

The documentation for this class was generated from the following files: