File indexing completed on 2024-06-23 04:48:43
0001 /* 0002 SPDX-FileCopyrightText: 2010 Till Theato <root@ttill.de> 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #pragma once 0007 0008 #include "../../../../bpoint.h" 0009 0010 #include <QList> 0011 #include <QString> 0012 0013 /** @class CubicBezierSpline 0014 @brief \@todo Describe class CubicBezierSpline 0015 @todo Describe class CubicBezierSpline 0016 */ 0017 class CubicBezierSpline 0018 { 0019 0020 public: 0021 using Point_t = BPoint; 0022 explicit CubicBezierSpline(); 0023 CubicBezierSpline(const CubicBezierSpline &spline); 0024 CubicBezierSpline &operator=(const CubicBezierSpline &spline); 0025 0026 /** @brief Loads the points from the string @param spline. 0027 * 0028 * x, y values have to be separated with a ';' 0029 * handles and points with a '#' 0030 * and the nodes with a '|' 0031 * So that you get: h1x;h1y#px;py#h2x;h2y|h1x;h1y#... */ 0032 void fromString(const QString &spline); 0033 /** @brief Returns the points stored in a string. 0034 * 0035 * x, y values have are separated with a ';' 0036 * handles and points with a '#' 0037 * and the nodes with a '|' 0038 * So that you get: h1x;h1y#px;py#h2x;h2y|h1x;h1y#... */ 0039 QString toString() const; 0040 0041 /** @brief Returns a list of the points defining the spline. */ 0042 QList<BPoint> points() const; 0043 0044 /** @brief Returns the number of points in the spline.*/ 0045 int count() const; 0046 0047 /** @brief Sets the point at index @param ix to @param point and returns its index (it might have changed during validation). */ 0048 int setPoint(int ix, const BPoint &point); 0049 /** @brief Adds @param point and returns its index. */ 0050 int addPoint(const BPoint &point); 0051 /** @brief Add a point based on a position @param point only 0052 This will try to compute relevant handles based on neihbouring points 0053 Return the index of the added point. 0054 */ 0055 int addPoint(const QPointF &point); 0056 /** @brief Removes the point at @param ix. */ 0057 void removePoint(int ix); 0058 0059 /** @brief Returns the point at @param ix. 0060 * @param ix Index of the point 0061 * @param normalisedWidth (default = 1) Will be multiplied will all x values to change the range from 0-1 into another one 0062 * @param normalisedHeight (default = 1) Will be multiplied will all y values to change the range from 0-1 into another one 0063 * @param invertHeight (default = false) true => y = 0 is at the very top 0064 */ 0065 BPoint getPoint(int ix, int normalisedWidth = 1, int normalisedHeight = 1, bool invertHeight = false); 0066 0067 /** @brief Returns the closest point to @param p, represented by its index and type (center or handle) 0068 */ 0069 std::pair<int, BPoint::PointType> closestPoint(const QPointF &p) const; 0070 0071 QList<BPoint> getPoints() const; 0072 0073 private: 0074 void validatePoints(); 0075 void keepSorted(); 0076 int indexOf(const BPoint &p); 0077 0078 QList<BPoint> m_points; 0079 };