diff options
Diffstat (limited to 'src/webenginequick/api/qquickwebengineaction_p.h')
0 files changed, 0 insertions, 0 deletions
![]() |
index : qt/qtwebengine.git | |
| Qt WebEngine |
| summaryrefslogtreecommitdiffstats |
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtriangulator_p.h"
#include <QtGui/qevent.h>
#include <QtGui/qpainter.h>
#include <QtGui/qpainterpath.h>
#include <QtGui/private/qbezier_p.h>
#include <QtGui/private/qdatabuffer_p.h>
#include <QtCore/qbitarray.h>
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qqueue.h>
#include <QtCore/qglobal.h>
#include <QtCore/qpoint.h>
#include <QtCore/qalgorithms.h>
#include <private/qopenglcontext_p.h>
#include <private/qopenglextensions_p.h>
#include <private/qrbtree_p.h>
#include <math.h>
QT_BEGIN_NAMESPACE
//#define Q_TRIANGULATOR_DEBUG
#define Q_FIXED_POINT_SCALE 32
template<typename T>
struct QVertexSet
{
inline QVertexSet() { }
inline QVertexSet(const QVertexSet<T> &other) : vertices(other.vertices), indices(other.indices) { }
QVertexSet<T> &operator = (const QVertexSet<T> &other) {vertices = other.vertices; indices = other.indices; return *this;}
// The vertices of a triangle are given by: (x[i[n]], y[i[n]]), (x[j[n]], y[j[n]]), (x[k[n]], y[k[n]]), n = 0, 1, ...
QVector<qreal> vertices; // [x[0], y[0], x[1], y[1], x[2], ...]
QVector<T> indices; // [i[0], j[0], k[0], i[1], j[1], k[1], i[2], ...]
};
//============================================================================//
// QFraction //
//============================================================================//
// Fraction must be in the range [0, 1)
struct QFraction
{
// Comparison operators must not be called on invalid fractions.
inline bool operator < (const QFraction &other) const;
inline bool operator == (const QFraction &other) const;
inline bool operator != (const QFraction &other) const {return !(*this == other);}
inline bool operator > (const QFraction &other) const {return other < *this;}
inline bool operator >= (const QFraction &other) const {return !(*this < other);}
inline bool operator <= (const QFraction &other) const {return !(*this > other);}
inline bool isValid() const {return denominator != 0;}
// numerator and denominator must not have common denominators.
quint64 numerator, denominator;
};
static inline quint64 gcd(quint64 x, quint64 y)
{
while (y != 0) {
quint64 z = y;
y = x % y;
x = z;
}
return x;
}
static inline int compare(quint64 a, quint64 b)
{
return (a > b) - (a < b);
}
// Compare a/b with c/d.
// Return negative if less, 0 if equal, positive if greater.
// a < b, c < d
static int qCompareFractions(quint64 a, quint64 b, quint64 c, quint64 d)
{
const quint64 LIMIT = Q_UINT64_C(0x100000000);
for (;;) {
// If the products 'ad' and 'bc' fit into 64 bits, they can be directly compared.
if (b < LIMIT && d < LIMIT)
return compare(a * d, b * c);
if (a == 0 || c == 0)
return compare(a, c);
// a/b < c/d <=> d/c < b/a
quint64 b_div_a = b / a;
quint64 d_div_c = d / c;
if (b_div_a != d_div_c)
return compare(d_div_c, b_div_a);
// floor(d/c) == floor(b/a)
// frac(d/c) < frac(b/a) ?
// frac(x/y) = (x%y)/y
d -= d_div_c * c; //d %= c;
b -= b_div_a * a; //b %= a;
qSwap(a, d);
qSwap(b, c);
}
}
// Fraction must be in the range [0, 1)
// Assume input is valid.
static QFraction qFraction(quint64 n, quint64 d) {
QFraction result;
if (n == 0) {
result.numerator = 0;
result.denominator = 1;
} else {
quint64 g = gcd(n, d);
result.numerator = n / g;
result.denominator = d / g;
}
return result;
}
inline bool QFraction::operator < (const QFraction &other) const
{
return qCompareFractions(numerator, denominator, other.numerator, other.denominator) < 0;
}
inline bool QFraction::operator == (const QFraction &other) const
{
return numerator == other.numerator && denominator == other.denominator;
}
//============================================================================//
// QPodPoint //
//============================================================================//
struct QPodPoint
{
inline bool operator < (const QPodPoint &other) const
{
if (y != other.y)
return y < other.y;
return x < other.x;
}
inline bool operator > (const QPodPoint &other) const {return other < *this;}
inline bool operator <= (const QPodPoint &other) const {return !(*this > other);}
inline bool operator >= (const QPodPoint &other) const {return !(*this < other);}
inline bool operator == (const QPodPoint &other) const {return x == other.x && y == other.y;}
inline bool operator != (const QPodPoint &other) const {return x != other.x || y != other.y;}
inline QPodPoint &operator += (const QPodPoint &other) {x += other.x; y += other.y; return *this;}
inline QPodPoint &operator -= (const QPodPoint &other) {x -= other.x; y -= other.y; return *this;}
inline QPodPoint operator + (const QPodPoint &other) const {QPodPoint result = {x + other.x, y + other.y}; return result;}
inline QPodPoint operator - (const QPodPoint &other) const {QPodPoint result = {x - other.x, y - other.y}; return result;}
int x;
int y;
};
static inline qint64 qCross(const QPodPoint &u, const QPodPoint &v)
{
return qint64(u.x) * qint64(v.y) - qint64(u.y) * qint64(v.x);
}
#ifdef Q_TRIANGULATOR_DEBUG
static inline qint64 qDot(const QPodPoint &u, const QPodPoint &v)
{
return qint64(u.x) * qint64(v.x) + qint64(u.y) * qint64(v.y);
}
#endif
// Return positive value if 'p' is to the right of the line 'v1'->'v2', negative if left of the
// line and zero if exactly on the line.
// The returned value is the z-component of the qCross product between 'v2-v1' and 'p-v1',
// which is twice the signed area of the triangle 'p'->'v1'->'v2' (positive for CW order).
static inline qint64 qPointDistanceFromLine(const QPodPoint &p, const QPodPoint &v1, const QPodPoint &v2)
{
return qCross(v2 - v1, p - v1);
}
static inline bool qPointIsLeftOfLine(const QPodPoint &p, const QPodPoint &v1, const QPodPoint &v2)
{
return QT_PREPEND_NAMESPACE(qPointDistanceFromLine)(p, v1, v2) < 0;
}
//============================================================================//
// QIntersectionPoint //
//============================================================================//
struct QIntersectionPoint
{
inline bool isValid() const {return xOffset.isValid() && yOffset.isValid();}
QPodPoint round() const;
inline bool isAccurate() const {return xOffset.numerator == 0 && yOffset.numerator == 0;}
bool operator < (const QIntersectionPoint &other) const;
bool operator == (const QIntersectionPoint &other) const;
inline bool operator != (const QIntersectionPoint &other) const {return !(*this == other);}
inline bool operator > (const QIntersectionPoint &other) const {return other < *this;}
inline bool operator >= (const QIntersectionPoint &other) const {return !(*this < other);}
inline bool operator <= (const QIntersectionPoint &other) const {return !(*this > other);}
bool isOnLine(const QPodPoint &u, const QPodPoint &v) const;
QPodPoint upperLeft;
QFraction xOffset;
QFraction yOffset;
};
static inline QIntersectionPoint qIntersectionPoint(const QPodPoint &point)
{
// upperLeft = point, xOffset = 0/1, yOffset = 0/1.
QIntersectionPoint p = {{point.x, point.y}, {0, 1}, {0, 1}};
return p;
}
static QIntersectionPoint qIntersectionPoint(const QPodPoint &u1, const QPodPoint &u2, const QPodPoint &v1, const QPodPoint &v2)
{
QIntersectionPoint result = {{0, 0}, {0, 0}, {0, 0}};
QPodPoint u = u2 - u1;
QPodPoint v = v2 - v1;
qint64 d1 = qCross(u, v1 - u1);
qint64 d2 = qCross(u, v2 - u1);
qint64 det = d2 - d1;
qint64 d3 = qCross(v, u1 - v1);
qint64 d4 = d3 - det; //qCross(v, u2 - v1);
// Check that the math is correct.
Q_ASSERT(d4 == qCross(v, u2 - v1));
// The intersection point can be expressed as:
// v1 - v * d1/det
// v2 - v * d2/det
// u1 + u * d3/det
// u2 + u * d4/det
// I'm only interested in lines that are crossing, so ignore parallel lines even if they overlap.
if (det == 0)
return result;
if (det < 0) {
det = -det;
d1 = -d1;
d2 = -d2;
d3 = -d3;
d4 = -d4;
}
// I'm only interested in lines intersecting at their interior, not at their end points.
// The lines intersect at their interior if and only if 'd1 < 0', 'd2 > 0', 'd3 < 0' and 'd4 > 0'.
if (d1 >= 0 || d2 <= 0 || d3 <= 0 || d4 >= 0)
return result;
// Calculate the intersection point as follows: