60 if (path->pointCount() == 0) {
66 bool isClosed = path->isClosedSubpath(0);
71 path->insertPoint(
new KoPathPoint(*firstPoint), end);
75 Q_FOREACH (
KoSubpath *subpath, subpaths) {
82 while (! subpaths.isEmpty()) {
97 for (
int i = 1; i < path->pointCount(); ++i) {
102 if (
qFuzzyCompare(diff.x() + 1, 1) && qFuzzyCompare(diff.y() + 1, 1)) {
106 p->removeControlPoint1();
120 for (
int i = 0; i < path.pointCount(); ++i) {
124 if (i != 0 && i != path.pointCount() - 1) {
127 if (!
p->isSmooth(prev, next)) {
142 for (
int i = 1; i < subpath->size(); ++i) {
146 subpath->insert(i,
p);
155 if (!
p1->activeControlPoint1() && !
p2->activeControlPoint2()) {
161 p1->activeControlPoint2() ?
p1->controlPoint2() :
p1->point(),
162 p2->activeControlPoint1() ?
p2->controlPoint1() :
p2->point(),
173 qDebug() <<
"reached MAX_RECURSIVE_DEPTH";
181 for (
unsigned short j = 1; j <= 3; ++j) {
182 for (
unsigned short i = 0; i <= 3 - j; ++i) {
183 curve[i] = (curve[i] + curve[i + 1]) / 2.0;
192 p1->setControlPoint2(
p[0]);
193 p2->setControlPoint1(curve[2]);
203 qreal ux = 3 * curve[1].x() - 2 * curve[0].x() - curve[3].x();
204 qreal uy = 3 * curve[1].y() - 2 * curve[0].y() - curve[3].y();
205 qreal vx = 3 * curve[2].x() - 2 * curve[3].x() - curve[0].x();
206 qreal vy = 3 * curve[2].x() - 2 * curve[3].x() - curve[0].x();
209 qreal dx = curve[0].x() - curve[3].y();
210 qreal dy = curve[0].y() - curve[3].y();
211 qreal dist2 = dx * dx + dy * dy;
212 qreal max2 = qMax(ux * ux, vx * vx) + qMax(uy * uy, vy * vy);
215 return max2 <= dist2;
221 Q_FOREACH (
KoSubpath *subpath, *subpaths) {
222 if (subpath->size() > 2) {
232 for (
int i = 0; i < subpath->size(); ++i) {
233 points.append((*subpath)[i]->point());
238 qDeleteAll(*subpath);
241 for (
int i = 0; i < simplified->
pointCount(); ++i) {
252 path->moveTo(subpaths.first()->first()->point());
257 for (
int si = 0; si < subpaths.size(); ++si) {
258 for (
int pi = 1; pi < subpaths[si]->size(); ++pi) {
260 path->lineTo(point->
point());
271 p = path->pointByIndex(index);
void karbonSimplifyPath(KoPathShape *path, qreal error)
KoPathShape * bezierFit(const QList< QPointF > &points, float error)
QList< KoPathPoint * > KoSubpath
a KoSubpath contains a path from a moveTo until a close or a new moveTo
QPair< int, int > KoPathPointIndex
A KoPathPoint represents a point in a path.
void setControlPoint1(const QPointF &point)
Set the control point 1.
void setControlPoint2(const QPointF &point)
Set the control point 2.
The position of a path point within a path shape.
int pointCount() const
Returns the number of points in the path.
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.
void clear()
Removes all subpaths and their points from the path.
static bool qFuzzyCompare(half p1, half p2)
KoSubpath subdivideAux(KoPathPoint *p1, KoPathPoint *p2)
QList< KoSubpath * > split(const KoPathShape &path)
const qreal SUBDIVISION_COEFF
void simplifySubpath(KoSubpath *subpath, qreal error)
void simplifySubpaths(QList< KoSubpath * > *subpaths, qreal error)
void subdivide(KoSubpath *subpath)
void mergeSubpaths(QList< KoSubpath * > subpaths, KoPathShape *path)
void removeDuplicates(KoPathShape *path)
const int MAX_RECURSIVE_DEPTH
bool isSufficientlyFlat(QPointF curve[4])