Warning, file /office/calligra/libs/flake/KoPathSegment.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2008-2009 Jan Hambrecht <jaham@gmx.net>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #ifndef KOPATHSEGMENT_H
0021 #define KOPATHSEGMENT_H
0022 
0023 #include "flake_export.h"
0024 #include <QList>
0025 #include <QPair>
0026 
0027 class KoPathPoint;
0028 class QTransform;
0029 class QPointF;
0030 class QRectF;
0031 
0032 /// A KoPathSegment consist of two neighboring KoPathPoints
0033 class FLAKE_EXPORT KoPathSegment
0034 {
0035 public:
0036     /**
0037     * Creates a new segment from the given path points
0038     * It takes ownership of the path points which do not have a
0039     * parent path shape set.
0040     */
0041     explicit KoPathSegment(KoPathPoint * first = 0, KoPathPoint * second = 0);
0042 
0043     /// Constructs segment by copying another segment
0044     KoPathSegment(const KoPathSegment &segment);
0045 
0046     /// Creates a new line segment
0047     KoPathSegment(const QPointF &p0, const QPointF &p1);
0048     /// Creates a new quadratic segment
0049     KoPathSegment(const QPointF &p0, const QPointF &p1, const QPointF &p2);
0050     /// Creates a new cubic segment
0051     KoPathSegment(const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3);
0052 
0053     /// Assigns segment
0054     KoPathSegment& operator=(const KoPathSegment &other);
0055 
0056     /// Destroys the path segment
0057     ~KoPathSegment();
0058 
0059     /// Returns the first point of the segment
0060     KoPathPoint *first() const;
0061 
0062     /// Sets the first segment point
0063     void setFirst(KoPathPoint *first);
0064 
0065     /// Returns the second point of the segment
0066     KoPathPoint *second() const;
0067 
0068     /// Sets the second segment point
0069     void setSecond(KoPathPoint *second);
0070 
0071     /// Returns if segment is valid, e.g. has two valid points
0072     bool isValid() const;
0073 
0074     /// Compare operator
0075     bool operator==(const KoPathSegment &other) const;
0076 
0077     /// Returns the degree of the segment: 1 = line, 2 = quadratic, 3 = cubic, -1 = invalid
0078     int degree() const;
0079 
0080     /// Returns list of intersections with the given path segment
0081     QVector<QPointF> intersections(const KoPathSegment &segment) const;
0082 
0083     /// Returns the convex hull polygon of the segment
0084     QVector<QPointF> convexHull() const;
0085 
0086     /// Splits segment at given position returning the two resulting segments
0087     QPair<KoPathSegment, KoPathSegment> splitAt(qreal t) const;
0088 
0089     /// Returns point at given t
0090     QPointF pointAt(qreal t) const;
0091 
0092     /// Returns the axis aligned tight bounding rect
0093     QRectF boundingRect() const;
0094 
0095     /// Returns the control point bounding rect
0096     QRectF controlPointRect() const;
0097 
0098     /// Returns transformed segment
0099     KoPathSegment mapped(const QTransform &matrix) const;
0100 
0101     /// Returns cubic bezier curve segment of this segment
0102     KoPathSegment toCubic() const;
0103 
0104     /**
0105      * Returns the length of the path segment
0106      * @param error the error tolerance
0107      */
0108     qreal length(qreal error = 0.005) const;
0109 
0110     /**
0111      * Returns segment length at given parameter
0112      *
0113      * Splits the segment at the given parameter t and calculates
0114      * the length of the first segment of the split.
0115      *
0116      * @param t curve parameter to get length at
0117      * @param error the error tolerance
0118      */
0119     qreal lengthAt(qreal t, qreal error = 0.005) const;
0120 
0121     /**
0122      * Returns the curve parameter at the given length of the segment
0123      *
0124      * If the specified length is negative it returns 0.0.
0125      * If the specified length is bigger that the actual length of the
0126      * segment it return 1.0.
0127      *
0128      * @param length the length to get the curve parameter for
0129      * @param tolerance the length error tolerance
0130      */
0131     qreal paramAtLength(qreal length, qreal tolerance = 0.001) const;
0132 
0133     /**
0134      * Checks if the segment is flat, i.e. the height smaller then the given tolerance
0135      * @param tolerance the flatness tolerance
0136      */
0137     bool isFlat(qreal tolerance = 0.01) const;
0138 
0139     /**
0140      * Returns the parameter for the curve point nearest to the given point
0141      * @param point the point to find nearest point to
0142      * @return the parameter of the curve point nearest to the given point
0143      */
0144     qreal nearestPoint(const QPointF &point) const;
0145 
0146     /// Returns ordered list of control points
0147     QVector<QPointF> controlPoints() const;
0148 
0149     /**
0150      * Interpolates quadric bezier curve.
0151      * @return the interpolated bezier segment
0152      */
0153     static KoPathSegment interpolate(const QPointF &p0, const QPointF &p1, const QPointF &p2, qreal t);
0154 
0155 private:
0156     class Private;
0157     Private * const d;
0158 };
0159 
0160 #endif // KOPATHSEGMENT_H