1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
7
** This file is part of the QtGui module of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
10
** Licensees holding valid Qt Commercial licenses may use this file in
11
** accordance with the Qt Commercial License Agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Nokia.
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
** In addition, as a special exception, Nokia gives you certain
24
** additional rights. These rights are described in the Nokia Qt LGPL
25
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file. Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
127
127
qreal dy = bez.y2 - bez.y1;
129
129
qreal normalized = qSqrt(dx * dx + dy * dy);
130
if (qFuzzyCompare(normalized + 1, 1))
130
if (qFuzzyIsNull(normalized))
133
133
qreal d = qAbs(dx * (bez.y3 - bez.y2) - dy * (bez.x3 - bez.x2));
135
135
qreal t = qSqrt(4. / 3. * normalized * flatness / d);
136
if (t > 1 || qFuzzyCompare(t, (qreal)1.))
136
if (t > 1 || qFuzzyIsNull(t - (qreal)1.))
138
138
bez.parameterSplitLeft(t, &left);
139
139
p->append(bez.pt1());
144
144
static inline int quadraticRoots(qreal a, qreal b, qreal c,
145
145
qreal *x1, qreal *x2)
147
if (qFuzzyCompare(a + 1, 1)) {
148
if (qFuzzyCompare(b + 1, 1))
147
if (qFuzzyIsNull(a)) {
150
150
*x1 = *x2 = (-c / b);
153
153
const qreal det = b * b - 4 * a * c;
154
if (qFuzzyCompare(det + 1, 1)) {
154
if (qFuzzyIsNull(det)) {
155
155
*x1 = *x2 = -b / (2 * a);
159
if (qFuzzyCompare(b + 1, 1)) {
159
if (qFuzzyIsNull(b)) {
160
160
*x2 = qSqrt(-c / a);
243
243
qreal b = 6 * (ay * cx - ax * cy);
244
244
qreal c = 2 * (by * cx - bx * cy);
246
if ((qFuzzyCompare(a + 1, 1) && qFuzzyCompare(b + 1, 1)) ||
246
if ((qFuzzyIsNull(a) && qFuzzyIsNull(b)) ||
247
247
(b * b - 4 * a *c) < 0) {
248
248
QBezier bez(*this);
249
249
flattenBezierWithoutInflections(bez, polygon);
447
447
qreal r = 1.0 + prev_normal.x() * next_normal.x()
448
448
+ prev_normal.y() * next_normal.y();
450
if (qFuzzyCompare(r + 1, 1)) {
450
if (qFuzzyIsNull(r)) {
451
451
points_shifted[i] = points[i] + offset * prev_normal;
453
453
qreal k = offset / r;
478
478
normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2);
479
479
qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y());
480
if (qFuzzyCompare(dist + 1, 1))
480
if (qFuzzyIsNull(dist))
482
482
normals[0] /= dist;
483
483
normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4);
484
484
dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y());
485
if (qFuzzyCompare(dist + 1, 1))
485
if (qFuzzyIsNull(dist))
487
487
normals[2] /= dist;
673
673
#ifdef QDEBUG_BEZIER
674
674
static QDebug operator<<(QDebug dbg, const QBezier &bz)
676
dbg <<"["<<bz.x1<<", "<<bz.y1<<"], "
677
<<"["<<bz.x2<<", "<<bz.y2<<"], "
678
<<"["<<bz.x3<<", "<<bz.y3<<"], "
679
<<"["<<bz.x4<<", "<<bz.y4<<"]";
676
dbg << '[' << bz.x1<< ", " << bz.y1 << "], "
677
<< '[' << bz.x2 <<", " << bz.y2 << "], "
678
<< '[' << bz.x3 <<", " << bz.y3 << "], "
679
<< '[' << bz.x4 <<", " << bz.y4 << ']';