QGIS API Documentation 3.99.0-Master (a8f284845db)
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
25class QgsNurbsCurve;
26
27#define SIP_NO_FILE
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
167 std::unique_ptr<QgsNurbsCurve> asNurbsCurve() const;
168
170 void clear();
171
173 bool isEmpty() const { return mData.isEmpty(); }
174
181 int findClosestAnchor( const QgsPoint &point, double tolerance ) const;
182
189 int findClosestHandle( const QgsPoint &point, double tolerance ) const;
190
197 int findClosestSegment( const QgsPoint &point, double tolerance ) const;
198
199 private:
200 QVector<QgsAnchorWithHandles> mData;
201 static const QgsAnchorWithHandles sInvalidAnchor;
202};
203
205
206#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