QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 ), leftHandle( point ), rightHandle( point ) {}
54
56 QgsAnchorWithHandles( const QgsPoint &point, const QgsPoint &left, const QgsPoint &right )
57 : anchor( point ), leftHandle( left ), rightHandle( right ) {}
58};
59
73class GUI_EXPORT QgsBezierData
74{
75 public:
77 QgsBezierData() = default;
78
80 static constexpr int INTERPOLATION_POINTS = 32;
81
87 void addAnchor( const QgsPoint &point );
88
95 void moveAnchor( int index, const QgsPoint &point );
96
102 void moveHandle( int index, const QgsPoint &point );
103
109 void insertAnchor( int segmentIndex, const QgsPoint &point );
110
115 void deleteAnchor( int index );
116
121 void retractHandle( int index );
122
129 void extendHandle( int index, const QgsPoint &point );
130
132 int anchorCount() const { return mData.count(); }
133
135 int handleCount() const { return mData.count() * 2; }
136
138 QgsPoint anchor( int index ) const;
139
141 QgsPoint handle( int index ) const;
142
144 QVector<QgsPoint> anchors() const;
145
147 QVector<QgsPoint> handles() const;
148
154 const QgsAnchorWithHandles &anchorWithHandles( int index ) const;
155
160 QgsPointSequence interpolateLine() const;
161
168 std::unique_ptr<QgsNurbsCurve> asNurbsCurve( int degree = 3 ) const;
169
182 static QgsBezierData fromPolyBezierControlPoints( const QVector<QgsPoint> &controlPoints, int degree = 3 );
183
195 static QgsBezierData fromPolyBezierControlPoints( const QVector<QgsPointXY> &controlPoints, int degree = 3 );
196
205 static void calculateSymmetricHandles( QVector<QgsPoint> &controlPoints, int anchorIndex, const QgsPoint &mousePosition );
206
216 static void calculateSymmetricHandles( const QgsPoint &anchor, const QgsPoint &mousePosition, QgsPoint *handleFollow, QgsPoint *handleOpposite );
217
227 void calculateSymmetricHandles( int anchorIndex, const QgsPoint &mousePosition );
228
230 void clear();
231
233 bool isEmpty() const { return mData.isEmpty(); }
234
241 int findClosestAnchor( const QgsPoint &point, double tolerance ) const;
242
249 int findClosestHandle( const QgsPoint &point, double tolerance ) const;
250
257 int findClosestSegment( const QgsPoint &point, double tolerance ) const;
258
259 private:
260 QVector<QgsAnchorWithHandles> mData;
261 static const QgsAnchorWithHandles sInvalidAnchor;
262};
263
265
266#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