QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
qgsbezierdata.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsbezierdata.h - Data structure for Poly-Bézier curve digitizing
3 ---------------------
4 begin : December 2025
5 copyright : (C) 2025 by Loïc Bartoletti
6 Adapted from BezierEditing plugin work by Takayuki Mizutani
7 email : loic dot bartoletti at oslandia dot com
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGSBEZIERDATA_H
18#define QGSBEZIERDATA_H
19
20#include <memory>
21
22#include "qgis_gui.h"
23#include "qgspoint.h"
24
25#define SIP_NO_FILE
26
27class QgsNurbsCurve;
28
30
42struct GUI_EXPORT QgsAnchorWithHandles
43{
44 QgsPoint anchor;
45 QgsPoint leftHandle;
46 QgsPoint rightHandle;
47
49 QgsAnchorWithHandles() = default;
50
52 explicit QgsAnchorWithHandles( const QgsPoint &point )
53 : anchor( point )
54 , leftHandle( point )
55 , rightHandle( point )
56 {}
57
59 QgsAnchorWithHandles( const QgsPoint &point, const QgsPoint &left, const QgsPoint &right )
60 : anchor( point )
61 , leftHandle( left )
62 , rightHandle( right )
63 {}
64};
65
79class GUI_EXPORT QgsBezierData
80{
81 public:
83 QgsBezierData() = default;
84
86 static constexpr int INTERPOLATION_POINTS = 32;
87
93 void addAnchor( const QgsPoint &point );
94
101 void moveAnchor( int index, const QgsPoint &point );
102
108 void moveHandle( int index, const QgsPoint &point );
109
115 void insertAnchor( int segmentIndex, const QgsPoint &point );
116
121 void deleteAnchor( int index );
122
127 void retractHandle( int index );
128
135 void extendHandle( int index, const QgsPoint &point );
136
138 int anchorCount() const { return mData.count(); }
139
141 int handleCount() const { return mData.count() * 2; }
142
144 QgsPoint anchor( int index ) const;
145
147 QgsPoint handle( int index ) const;
148
150 QVector<QgsPoint> anchors() const;
151
153 QVector<QgsPoint> handles() const;
154
160 const QgsAnchorWithHandles &anchorWithHandles( int index ) const;
161
166 QgsPointSequence interpolateLine() const;
167
174 std::unique_ptr<QgsNurbsCurve> asNurbsCurve( int degree = 3 ) const;
175
188 static QgsBezierData fromPolyBezierControlPoints( const QVector<QgsPoint> &controlPoints, int degree = 3 );
189
201 static QgsBezierData fromPolyBezierControlPoints( const QVector<QgsPointXY> &controlPoints, int degree = 3 );
202
211 static void calculateSymmetricHandles( QVector<QgsPoint> &controlPoints, int anchorIndex, const QgsPoint &mousePosition );
212
222 static void calculateSymmetricHandles( const QgsPoint &anchor, const QgsPoint &mousePosition, QgsPoint *handleFollow, QgsPoint *handleOpposite );
223
233 void calculateSymmetricHandles( int anchorIndex, const QgsPoint &mousePosition );
234
236 void clear();
237
239 bool isEmpty() const { return mData.isEmpty(); }
240
247 int findClosestAnchor( const QgsPoint &point, double tolerance ) const;
248
255 int findClosestHandle( const QgsPoint &point, double tolerance ) const;
256
263 int findClosestSegment( const QgsPoint &point, double tolerance ) const;
264
265 private:
266 QVector<QgsAnchorWithHandles> mData;
267 static const QgsAnchorWithHandles sInvalidAnchor;
268};
269
271
272#endif // QGSBEZIERDATA_H
Represents a NURBS (Non-Uniform Rational B-Spline) curve geometry in 2D/3D.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
QVector< QgsPoint > QgsPointSequence