QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
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
29
31
43struct GUI_EXPORT QgsAnchorWithHandles
44{
45 QgsPoint anchor;
46 QgsPoint leftHandle;
47 QgsPoint rightHandle;
48
50 QgsAnchorWithHandles() = default;
51
53 explicit QgsAnchorWithHandles( const QgsPoint &point )
54 : anchor( point ), leftHandle( point ), rightHandle( point ) {}
55
57 QgsAnchorWithHandles( const QgsPoint &point, const QgsPoint &left, const QgsPoint &right )
58 : anchor( point ), leftHandle( left ), rightHandle( right ) {}
59};
60
74class GUI_EXPORT QgsBezierData
75{
76 public:
78 QgsBezierData() = default;
79
81 static constexpr int INTERPOLATION_POINTS = 32;
82
88 void addAnchor( const QgsPoint &point );
89
96 void moveAnchor( int index, const QgsPoint &point );
97
103 void moveHandle( int index, const QgsPoint &point );
104
110 void insertAnchor( int segmentIndex, const QgsPoint &point );
111
116 void deleteAnchor( int index );
117
122 void retractHandle( int index );
123
130 void extendHandle( int index, const QgsPoint &point );
131
133 int anchorCount() const { return mData.count(); }
134
136 int handleCount() const { return mData.count() * 2; }
137
139 QgsPoint anchor( int index ) const;
140
142 QgsPoint handle( int index ) const;
143
145 QVector<QgsPoint> anchors() const;
146
148 QVector<QgsPoint> handles() const;
149
155 const QgsAnchorWithHandles &anchorWithHandles( int index ) const;
156
161 QgsPointSequence interpolateLine() const;
162
168 std::unique_ptr<QgsNurbsCurve> asNurbsCurve() const;
169
171 void clear();
172
174 bool isEmpty() const { return mData.isEmpty(); }
175
182 int findClosestAnchor( const QgsPoint &point, double tolerance ) const;
183
190 int findClosestHandle( const QgsPoint &point, double tolerance ) const;
191
198 int findClosestSegment( const QgsPoint &point, double tolerance ) const;
199
200 private:
201 QVector<QgsAnchorWithHandles> mData;
202 static const QgsAnchorWithHandles sInvalidAnchor;
203};
204
206
207#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