@@ -81,188 +81,259 @@ Construct a linestring from a single 2d line segment.
81
81
virtual bool equals( const QgsCurve &other ) const;
82
82
83
83
84
+
84
85
SIP_PYOBJECT pointN( int i ) const;
85
86
%Docstring
86
- Returns the specified point from inside the line string .
87
+ Returns the point at the specified index. An IndexError will be raised if no point with the specified index exists .
87
88
88
- :param i: index of point, starting at 0 for the first point
89
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
90
+ corresponds to the last point in the line.
89
91
%End
90
92
%MethodCode
91
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
93
+ const int count = sipCpp->numPoints();
94
+ if ( a0 < -count || a0 >= count )
92
95
{
93
96
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
94
97
sipIsErr = 1;
95
98
}
96
99
else
97
100
{
98
- std::unique_ptr< QgsPoint > p = qgis::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
101
+ std::unique_ptr< QgsPoint > p;
102
+ if ( a0 >= 0 )
103
+ p = qgis::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
104
+ else // negative index, count backwards from end
105
+ p = qgis::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
99
106
sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
100
107
}
101
108
%End
102
109
110
+
103
111
virtual double xAt( int index ) const;
104
112
113
+ %Docstring
114
+ Returns the x-coordinate of the specified node in the line string.
115
+
116
+ An IndexError will be raised if no point with the specified index exists.
117
+
118
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
119
+ corresponds to the last point in the line.
120
+ %End
105
121
%MethodCode
106
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
122
+ const int count = sipCpp->numPoints();
123
+ if ( a0 < -count || a0 >= count )
107
124
{
108
125
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
109
126
sipIsErr = 1;
110
127
}
111
128
else
112
129
{
113
- return PyFloat_FromDouble( sipCpp->xAt( a0 ) );
130
+ if ( a0 >= 0 )
131
+ return PyFloat_FromDouble( sipCpp->xAt( a0 ) );
132
+ else
133
+ return PyFloat_FromDouble( sipCpp->xAt( count + a0 ) );
114
134
}
115
135
%End
116
136
137
+
117
138
virtual double yAt( int index ) const;
118
139
140
+ %Docstring
141
+ Returns the y-coordinate of the specified node in the line string.
142
+
143
+ An IndexError will be raised if no point with the specified index exists.
144
+
145
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
146
+ corresponds to the last point in the line.
147
+ %End
119
148
%MethodCode
120
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
149
+ const int count = sipCpp->numPoints();
150
+ if ( a0 < -count || a0 >= count )
121
151
{
122
152
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
123
153
sipIsErr = 1;
124
154
}
125
155
else
126
156
{
127
- return PyFloat_FromDouble( sipCpp->yAt( a0 ) );
157
+ if ( a0 >= 0 )
158
+ return PyFloat_FromDouble( sipCpp->yAt( a0 ) );
159
+ else
160
+ return PyFloat_FromDouble( sipCpp->yAt( count + a0 ) );
128
161
}
129
162
%End
130
163
131
164
132
165
133
166
134
167
168
+
135
169
double zAt( int index ) const;
136
170
%Docstring
137
171
Returns the z-coordinate of the specified node in the line string.
138
172
139
- :param index: index of node, where the first node in the line is 0
173
+ An IndexError will be raised if no point with the specified index exists.
140
174
141
- :return: z-coordinate of node, or ``nan`` if index is out of bounds or the line
142
- does not have a z dimension
175
+ If the LineString does not have a z-dimension then ``nan`` will be returned.
143
176
144
- .. seealso:: :py:func:`setZAt`
177
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
178
+ corresponds to the last point in the line.
145
179
%End
146
180
%MethodCode
147
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
181
+ const int count = sipCpp->numPoints();
182
+ if ( a0 < -count || a0 >= count )
148
183
{
149
184
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
150
185
sipIsErr = 1;
151
186
}
152
187
else
153
188
{
154
- return PyFloat_FromDouble( sipCpp->zAt( a0 ) );
189
+ if ( a0 >= 0 )
190
+ return PyFloat_FromDouble( sipCpp->zAt( a0 ) );
191
+ else
192
+ return PyFloat_FromDouble( sipCpp->zAt( count + a0 ) );
155
193
}
156
194
%End
157
195
196
+
158
197
double mAt( int index ) const;
159
198
%Docstring
160
- Returns the m value of the specified node in the line string.
199
+ Returns the m-coordinate of the specified node in the line string.
161
200
162
- :param index: index of node, where the first node in the line is 0
201
+ An IndexError will be raised if no point with the specified index exists.
163
202
164
- :return: m value of node, or ``nan`` if index is out of bounds or the line
165
- does not have m values
203
+ If the LineString does not have a m-dimension then ``nan`` will be returned.
166
204
167
- .. seealso:: :py:func:`setMAt`
205
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
206
+ corresponds to the last point in the line.
168
207
%End
169
208
%MethodCode
170
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
209
+ const int count = sipCpp->numPoints();
210
+ if ( a0 < -count || a0 >= count )
171
211
{
172
212
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
173
213
sipIsErr = 1;
174
214
}
175
215
else
176
216
{
177
- return PyFloat_FromDouble( sipCpp->mAt( a0 ) );
217
+ if ( a0 >= 0 )
218
+ return PyFloat_FromDouble( sipCpp->mAt( a0 ) );
219
+ else
220
+ return PyFloat_FromDouble( sipCpp->mAt( count + a0 ) );
178
221
}
179
222
%End
180
223
224
+
181
225
void setXAt( int index, double x );
182
226
%Docstring
183
227
Sets the x-coordinate of the specified node in the line string.
228
+ The corresponding node must already exist in line string.
229
+
230
+ An IndexError will be raised if no point with the specified index exists.
184
231
185
- :param index: index of node, where the first node in the line is 0. Corresponding
186
- node must already exist in line string.
187
- :param x: x-coordinate of node
232
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
233
+ corresponds to the last point in the line.
188
234
189
235
.. seealso:: :py:func:`xAt`
190
236
%End
191
237
%MethodCode
192
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
238
+ const int count = sipCpp->numPoints();
239
+ if ( a0 < -count || a0 >= count )
193
240
{
194
241
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
195
242
sipIsErr = 1;
196
243
}
197
244
else
198
245
{
199
- sipCpp->setXAt( a0, a1 );
246
+ if ( a0 >= 0 )
247
+ sipCpp->setXAt( a0, a1 );
248
+ else
249
+ sipCpp->setXAt( count + a0, a1 );
200
250
}
201
251
%End
202
252
253
+
203
254
void setYAt( int index, double y );
204
255
%Docstring
205
256
Sets the y-coordinate of the specified node in the line string.
257
+ The corresponding node must already exist in line string.
206
258
207
- :param index: index of node, where the first node in the line is 0. Corresponding
208
- node must already exist in line string.
209
- :param y: y-coordinate of node
259
+ An IndexError will be raised if no point with the specified index exists.
260
+
261
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
262
+ corresponds to the last point in the line.
210
263
211
264
.. seealso:: :py:func:`yAt`
212
265
%End
213
266
%MethodCode
214
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
267
+ const int count = sipCpp->numPoints();
268
+ if ( a0 < -count || a0 >= count )
215
269
{
216
270
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
217
271
sipIsErr = 1;
218
272
}
219
273
else
220
274
{
221
- sipCpp->setYAt( a0, a1 );
275
+ if ( a0 >= 0 )
276
+ sipCpp->setYAt( a0, a1 );
277
+ else
278
+ sipCpp->setYAt( count + a0, a1 );
222
279
}
223
280
%End
224
281
282
+
225
283
void setZAt( int index, double z );
226
284
%Docstring
227
285
Sets the z-coordinate of the specified node in the line string.
286
+ The corresponding node must already exist in line string and the line string must have z-dimension.
228
287
229
- :param index: index of node, where the first node in the line is 0. Corresponding
230
- node must already exist in line string, and the line string must have z-dimension.
231
- :param z: z-coordinate of node
288
+ An IndexError will be raised if no point with the specified index exists.
289
+
290
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
291
+ corresponds to the last point in the line.
232
292
233
293
.. seealso:: :py:func:`zAt`
234
294
%End
235
295
%MethodCode
236
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
296
+ const int count = sipCpp->numPoints();
297
+ if ( a0 < -count || a0 >= count )
237
298
{
238
299
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
239
300
sipIsErr = 1;
240
301
}
241
302
else
242
303
{
243
- sipCpp->setZAt( a0, a1 );
304
+ if ( a0 >= 0 )
305
+ sipCpp->setZAt( a0, a1 );
306
+ else
307
+ sipCpp->setZAt( count + a0, a1 );
244
308
}
245
309
%End
246
310
311
+
247
312
void setMAt( int index, double m );
248
313
%Docstring
249
- Sets the m value of the specified node in the line string.
314
+ Sets the m-coordinate of the specified node in the line string.
315
+ The corresponding node must already exist in line string and the line string must have m-dimension.
316
+
317
+ An IndexError will be raised if no point with the specified index exists.
250
318
251
- :param index: index of node, where the first node in the line is 0. Corresponding
252
- node must already exist in line string, and the line string must have m values.
253
- :param m: m value of node
319
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
320
+ corresponds to the last point in the line.
254
321
255
322
.. seealso:: :py:func:`mAt`
256
323
%End
257
324
%MethodCode
258
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
325
+ const int count = sipCpp->numPoints();
326
+ if ( a0 < -count || a0 >= count )
259
327
{
260
328
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
261
329
sipIsErr = 1;
262
330
}
263
331
else
264
332
{
265
- sipCpp->setMAt( a0, a1 );
333
+ if ( a0 >= 0 )
334
+ sipCpp->setMAt( a0, a1 );
335
+ else
336
+ sipCpp->setMAt( count + a0, a1 );
266
337
}
267
338
%End
268
339
@@ -439,37 +510,51 @@ of the curve.
439
510
440
511
SIP_PYOBJECT __getitem__( int index );
441
512
%Docstring
442
- Returns the point at the specified ``index``. An IndexError will be raised if no point with the specified ``index`` exists.
513
+ Returns the point at the specified ``index``. An IndexError will be raised if no point with the specified ``index`` exists.
443
514
444
- .. versionadded:: 3.6
515
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
516
+ corresponds to the last point in the line.
517
+
518
+ .. versionadded:: 3.6
445
519
%End
446
520
%MethodCode
447
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
448
- {
449
- PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
450
- sipIsErr = 1;
451
- }
521
+ const int count = sipCpp->numPoints();
522
+ if ( a0 < -count || a0 >= count )
523
+ {
524
+ PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
525
+ sipIsErr = 1;
526
+ }
527
+ else
528
+ {
529
+ std::unique_ptr< QgsPoint > p;
530
+ if ( a0 >= 0 )
531
+ p = qgis::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
452
532
else
453
- {
454
- std::unique_ptr< QgsPoint > p = qgis::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
455
- sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
456
- }
533
+ p = qgis::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
534
+ sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
535
+ }
457
536
%End
458
537
459
538
void __setitem__( int index, const QgsPoint &point );
460
539
%Docstring
461
- Sets the point at the specified ``index``. A point at the ``index`` must already exist or an IndexError will be raised.
540
+ Sets the point at the specified ``index``. A point at the ``index`` must already exist or an IndexError will be raised.
541
+
542
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
543
+ corresponds to the last point in the line.
462
544
463
- .. versionadded:: 3.6
545
+ .. versionadded:: 3.6
464
546
%End
465
547
%MethodCode
466
- if ( a0 < 0 || a0 >= sipCpp->numPoints() )
548
+ const int count = sipCpp->numPoints();
549
+ if ( a0 < -count || a0 >= count )
467
550
{
468
551
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
469
552
sipIsErr = 1;
470
553
}
471
554
else
472
555
{
556
+ if ( a0 < 0 )
557
+ a0 = count + a0;
473
558
sipCpp->setXAt( a0, a1->x() );
474
559
sipCpp->setYAt( a0, a1->y() );
475
560
if ( sipCpp->isMeasure() )
@@ -479,15 +564,22 @@ of the curve.
479
564
}
480
565
%End
481
566
567
+
482
568
void __delitem__( int index );
483
569
%Docstring
484
- Deletes the vertex at the specified ``index``. A point at the ``index`` must already exist or an IndexError will be raised.
570
+ Deletes the vertex at the specified ``index``. A point at the ``index`` must already exist or an IndexError will be raised.
571
+
572
+ Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1
573
+ corresponds to the last point in the line.
485
574
486
- .. versionadded:: 3.6
575
+ .. versionadded:: 3.6
487
576
%End
488
577
%MethodCode
489
- if ( a0 >= 0 && a0 < sipCpp->numPoints() )
578
+ const int count = sipCpp->numPoints();
579
+ if ( a0 >= 0 && a0 < count )
490
580
sipCpp->deleteVertex( QgsVertexId( -1, -1, a0 ) );
581
+ else if ( a0 < 0 && a0 >= -count )
582
+ sipCpp->deleteVertex( QgsVertexId( -1, -1, count + a0 ) );
491
583
else
492
584
{
493
585
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
0 commit comments