@@ -94,54 +94,97 @@ class CORE_EXPORT QgsLineString: public QgsCurve
94
94
95
95
bool equals ( const QgsCurve &other ) const override ;
96
96
97
+ #ifndef SIP_RUN
98
+
97
99
/* *
98
100
* Returns the specified point from inside the line string.
99
101
* \param i index of point, starting at 0 for the first point
100
102
*/
101
- #ifndef SIP_RUN
102
103
QgsPoint pointN ( int i ) const ;
103
104
#else
105
+
106
+ /* *
107
+ * Returns the point at the specified index. An IndexError will be raised if no point with the specified index exists.
108
+ *
109
+ * 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
110
+ * corresponds to the last point in the line.
111
+ */
104
112
SIP_PYOBJECT pointN ( int i ) const ;
105
113
% MethodCode
106
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
114
+ const int count = sipCpp->numPoints ();
115
+ if ( a0 < -count || a0 >= count )
107
116
{
108
117
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
109
118
sipIsErr = 1 ;
110
119
}
111
120
else
112
121
{
113
- std::unique_ptr< QgsPoint > p = qgis::make_unique< QgsPoint >( sipCpp->pointN ( a0 ) );
122
+ std::unique_ptr< QgsPoint > p;
123
+ if ( a0 >= 0 )
124
+ p = qgis::make_unique< QgsPoint >( sipCpp->pointN ( a0 ) );
125
+ else // negative index, count backwards from end
126
+ p = qgis::make_unique< QgsPoint >( sipCpp->pointN ( count + a0 ) );
114
127
sipRes = sipConvertFromType ( p.release (), sipType_QgsPoint, Py_None );
115
128
}
116
129
% End
117
130
#endif
118
131
132
+ #ifndef SIP_RUN
133
+ double xAt ( int index ) const override ;
134
+ #else
135
+
136
+ /* *
137
+ * Returns the x-coordinate of the specified node in the line string.
138
+ *
139
+ * An IndexError will be raised if no point with the specified index exists.
140
+ *
141
+ * 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
142
+ * corresponds to the last point in the line.
143
+ */
119
144
double xAt ( int index ) const override ;
120
- #ifdef SIP_RUN
121
145
% MethodCode
122
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
146
+ const int count = sipCpp->numPoints ();
147
+ if ( a0 < -count || a0 >= count )
123
148
{
124
149
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
125
150
sipIsErr = 1 ;
126
151
}
127
152
else
128
153
{
129
- return PyFloat_FromDouble ( sipCpp->xAt ( a0 ) );
154
+ if ( a0 >= 0 )
155
+ return PyFloat_FromDouble ( sipCpp->xAt ( a0 ) );
156
+ else
157
+ return PyFloat_FromDouble ( sipCpp->xAt ( count + a0 ) );
130
158
}
131
159
% End
132
160
#endif
133
161
162
+ #ifndef SIP_RUN
163
+ double yAt ( int index ) const override ;
164
+ #else
165
+
166
+ /* *
167
+ * Returns the y-coordinate of the specified node in the line string.
168
+ *
169
+ * An IndexError will be raised if no point with the specified index exists.
170
+ *
171
+ * 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
172
+ * corresponds to the last point in the line.
173
+ */
134
174
double yAt ( int index ) const override ;
135
- #ifdef SIP_RUN
136
175
% MethodCode
137
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
176
+ const int count = sipCpp->numPoints ();
177
+ if ( a0 < -count || a0 >= count )
138
178
{
139
179
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
140
180
sipIsErr = 1 ;
141
181
}
142
182
else
143
183
{
144
- return PyFloat_FromDouble ( sipCpp->yAt ( a0 ) );
184
+ if ( a0 >= 0 )
185
+ return PyFloat_FromDouble ( sipCpp->yAt ( a0 ) );
186
+ else
187
+ return PyFloat_FromDouble ( sipCpp->yAt ( count + a0 ) );
145
188
}
146
189
% End
147
190
#endif
@@ -200,6 +243,8 @@ class CORE_EXPORT QgsLineString: public QgsCurve
200
243
return mM .constData ();
201
244
}
202
245
246
+ #ifndef SIP_RUN
247
+
203
248
/* *
204
249
* Returns the z-coordinate of the specified node in the line string.
205
250
* \param index index of node, where the first node in the line is 0
@@ -214,20 +259,38 @@ class CORE_EXPORT QgsLineString: public QgsCurve
214
259
else
215
260
return std::numeric_limits<double >::quiet_NaN ();
216
261
}
217
- #ifdef SIP_RUN
262
+ #else
263
+
264
+ /* *
265
+ * Returns the z-coordinate of the specified node in the line string.
266
+ *
267
+ * An IndexError will be raised if no point with the specified index exists.
268
+ *
269
+ * If the LineString does not have a z-dimension then ``nan`` will be returned.
270
+ *
271
+ * 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
272
+ * corresponds to the last point in the line.
273
+ */
274
+ double zAt ( int index ) const ;
218
275
% MethodCode
219
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
276
+ const int count = sipCpp->numPoints ();
277
+ if ( a0 < -count || a0 >= count )
220
278
{
221
279
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
222
280
sipIsErr = 1 ;
223
281
}
224
282
else
225
283
{
226
- return PyFloat_FromDouble ( sipCpp->zAt ( a0 ) );
284
+ if ( a0 >= 0 )
285
+ return PyFloat_FromDouble ( sipCpp->zAt ( a0 ) );
286
+ else
287
+ return PyFloat_FromDouble ( sipCpp->zAt ( count + a0 ) );
227
288
}
228
289
% End
229
290
#endif
230
291
292
+ #ifndef SIP_RUN
293
+
231
294
/* *
232
295
* Returns the m value of the specified node in the line string.
233
296
* \param index index of node, where the first node in the line is 0
@@ -242,20 +305,38 @@ class CORE_EXPORT QgsLineString: public QgsCurve
242
305
else
243
306
return std::numeric_limits<double >::quiet_NaN ();
244
307
}
245
- #ifdef SIP_RUN
308
+ #else
309
+
310
+ /* *
311
+ * Returns the m-coordinate of the specified node in the line string.
312
+ *
313
+ * An IndexError will be raised if no point with the specified index exists.
314
+ *
315
+ * If the LineString does not have a m-dimension then ``nan`` will be returned.
316
+ *
317
+ * 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
318
+ * corresponds to the last point in the line.
319
+ */
320
+ double mAt ( int index ) const ;
246
321
% MethodCode
247
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
322
+ const int count = sipCpp->numPoints ();
323
+ if ( a0 < -count || a0 >= count )
248
324
{
249
325
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
250
326
sipIsErr = 1 ;
251
327
}
252
328
else
253
329
{
254
- return PyFloat_FromDouble ( sipCpp->mAt ( a0 ) );
330
+ if ( a0 >= 0 )
331
+ return PyFloat_FromDouble ( sipCpp->mAt ( a0 ) );
332
+ else
333
+ return PyFloat_FromDouble ( sipCpp->mAt ( count + a0 ) );
255
334
}
256
335
% End
257
336
#endif
258
337
338
+ #ifndef SIP_RUN
339
+
259
340
/* *
260
341
* Sets the x-coordinate of the specified node in the line string.
261
342
* \param index index of node, where the first node in the line is 0. Corresponding
@@ -264,20 +345,39 @@ class CORE_EXPORT QgsLineString: public QgsCurve
264
345
* \see xAt()
265
346
*/
266
347
void setXAt ( int index, double x );
267
- #ifdef SIP_RUN
348
+ #else
349
+
350
+ /* *
351
+ * Sets the x-coordinate of the specified node in the line string.
352
+ * The corresponding node must already exist in line string.
353
+ *
354
+ * An IndexError will be raised if no point with the specified index exists.
355
+ *
356
+ * 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
357
+ * corresponds to the last point in the line.
358
+ *
359
+ * \see xAt()
360
+ */
361
+ void setXAt ( int index, double x );
268
362
% MethodCode
269
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
363
+ const int count = sipCpp->numPoints ();
364
+ if ( a0 < -count || a0 >= count )
270
365
{
271
366
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
272
367
sipIsErr = 1 ;
273
368
}
274
369
else
275
370
{
276
- sipCpp->setXAt ( a0, a1 );
371
+ if ( a0 >= 0 )
372
+ sipCpp->setXAt ( a0, a1 );
373
+ else
374
+ sipCpp->setXAt ( count + a0, a1 );
277
375
}
278
376
% End
279
377
#endif
280
378
379
+ #ifndef SIP_RUN
380
+
281
381
/* *
282
382
* Sets the y-coordinate of the specified node in the line string.
283
383
* \param index index of node, where the first node in the line is 0. Corresponding
@@ -286,20 +386,39 @@ class CORE_EXPORT QgsLineString: public QgsCurve
286
386
* \see yAt()
287
387
*/
288
388
void setYAt ( int index, double y );
289
- #ifdef SIP_RUN
389
+ #else
390
+
391
+ /* *
392
+ * Sets the y-coordinate of the specified node in the line string.
393
+ * The corresponding node must already exist in line string.
394
+ *
395
+ * An IndexError will be raised if no point with the specified index exists.
396
+ *
397
+ * 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
398
+ * corresponds to the last point in the line.
399
+ *
400
+ * \see yAt()
401
+ */
402
+ void setYAt ( int index, double y );
290
403
% MethodCode
291
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
404
+ const int count = sipCpp->numPoints ();
405
+ if ( a0 < -count || a0 >= count )
292
406
{
293
407
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
294
408
sipIsErr = 1 ;
295
409
}
296
410
else
297
411
{
298
- sipCpp->setYAt ( a0, a1 );
412
+ if ( a0 >= 0 )
413
+ sipCpp->setYAt ( a0, a1 );
414
+ else
415
+ sipCpp->setYAt ( count + a0, a1 );
299
416
}
300
417
% End
301
418
#endif
302
419
420
+ #ifndef SIP_RUN
421
+
303
422
/* *
304
423
* Sets the z-coordinate of the specified node in the line string.
305
424
* \param index index of node, where the first node in the line is 0. Corresponding
@@ -312,20 +431,39 @@ class CORE_EXPORT QgsLineString: public QgsCurve
312
431
if ( index >= 0 && index < mZ .size () )
313
432
mZ [ index ] = z;
314
433
}
315
- #ifdef SIP_RUN
434
+ #else
435
+
436
+ /* *
437
+ * Sets the z-coordinate of the specified node in the line string.
438
+ * The corresponding node must already exist in line string and the line string must have z-dimension.
439
+ *
440
+ * An IndexError will be raised if no point with the specified index exists.
441
+ *
442
+ * 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
443
+ * corresponds to the last point in the line.
444
+ *
445
+ * \see zAt()
446
+ */
447
+ void setZAt ( int index, double z );
316
448
% MethodCode
317
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
449
+ const int count = sipCpp->numPoints ();
450
+ if ( a0 < -count || a0 >= count )
318
451
{
319
452
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
320
453
sipIsErr = 1 ;
321
454
}
322
455
else
323
456
{
324
- sipCpp->setZAt ( a0, a1 );
457
+ if ( a0 >= 0 )
458
+ sipCpp->setZAt ( a0, a1 );
459
+ else
460
+ sipCpp->setZAt ( count + a0, a1 );
325
461
}
326
462
% End
327
463
#endif
328
464
465
+ #ifndef SIP_RUN
466
+
329
467
/* *
330
468
* Sets the m value of the specified node in the line string.
331
469
* \param index index of node, where the first node in the line is 0. Corresponding
@@ -338,16 +476,33 @@ class CORE_EXPORT QgsLineString: public QgsCurve
338
476
if ( index >= 0 && index < mM .size () )
339
477
mM [ index ] = m;
340
478
}
341
- #ifdef SIP_RUN
479
+ #else
480
+
481
+ /* *
482
+ * Sets the m-coordinate of the specified node in the line string.
483
+ * The corresponding node must already exist in line string and the line string must have m-dimension.
484
+ *
485
+ * An IndexError will be raised if no point with the specified index exists.
486
+ *
487
+ * 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
488
+ * corresponds to the last point in the line.
489
+ *
490
+ * \see mAt()
491
+ */
492
+ void setMAt ( int index, double m );
342
493
% MethodCode
343
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
494
+ const int count = sipCpp->numPoints ();
495
+ if ( a0 < -count || a0 >= count )
344
496
{
345
497
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
346
498
sipIsErr = 1 ;
347
499
}
348
500
else
349
501
{
350
- sipCpp->setMAt ( a0, a1 );
502
+ if ( a0 >= 0 )
503
+ sipCpp->setMAt ( a0, a1 );
504
+ else
505
+ sipCpp->setMAt ( count + a0, a1 );
351
506
}
352
507
% End
353
508
#endif
@@ -484,39 +639,53 @@ class CORE_EXPORT QgsLineString: public QgsCurve
484
639
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
485
640
% End
486
641
642
+ /* *
643
+ * Returns the point at the specified ``index``. An IndexError will be raised if no point with the specified ``index`` exists.
644
+ *
645
+ * 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
646
+ * corresponds to the last point in the line.
647
+ *
648
+ * \since QGIS 3.6
649
+ */
487
650
SIP_PYOBJECT __getitem__ ( int index );
488
- % Docstring
489
- Returns the point at the specified ``index``. An IndexError will be raised if no point with the specified ``index`` exists.
490
-
491
- .. versionadded:: 3.6
492
- % End
493
651
% MethodCode
494
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
495
- {
496
- PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
497
- sipIsErr = 1 ;
498
- }
652
+ const int count = sipCpp->numPoints ();
653
+ if ( a0 < -count || a0 >= count )
654
+ {
655
+ PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
656
+ sipIsErr = 1 ;
657
+ }
658
+ else
659
+ {
660
+ std::unique_ptr< QgsPoint > p;
661
+ if ( a0 >= 0 )
662
+ p = qgis::make_unique< QgsPoint >( sipCpp->pointN ( a0 ) );
499
663
else
500
- {
501
- std::unique_ptr< QgsPoint > p = qgis::make_unique< QgsPoint >( sipCpp->pointN ( a0 ) );
502
- sipRes = sipConvertFromType ( p.release (), sipType_QgsPoint, Py_None );
503
- }
664
+ p = qgis::make_unique< QgsPoint >( sipCpp->pointN ( count + a0 ) );
665
+ sipRes = sipConvertFromType ( p.release (), sipType_QgsPoint, Py_None );
666
+ }
504
667
% End
505
668
669
+ /* *
670
+ * Sets the point at the specified ``index``. A point at the ``index`` must already exist or an IndexError will be raised.
671
+ *
672
+ * 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
673
+ * corresponds to the last point in the line.
674
+ *
675
+ * \since QGIS 3.6
676
+ */
506
677
void __setitem__ ( int index, const QgsPoint &point );
507
- % Docstring
508
- Sets the point at the specified ``index``. A point at the ``index`` must already exist or an IndexError will be raised.
509
-
510
- .. versionadded:: 3.6
511
- % End
512
678
% MethodCode
513
- if ( a0 < 0 || a0 >= sipCpp->numPoints () )
679
+ const int count = sipCpp->numPoints ();
680
+ if ( a0 < -count || a0 >= count )
514
681
{
515
682
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
516
683
sipIsErr = 1 ;
517
684
}
518
685
else
519
686
{
687
+ if ( a0 < 0 )
688
+ a0 = count + a0;
520
689
sipCpp->setXAt ( a0, a1->x () );
521
690
sipCpp->setYAt ( a0, a1->y () );
522
691
if ( sipCpp->isMeasure () )
@@ -526,15 +695,22 @@ class CORE_EXPORT QgsLineString: public QgsCurve
526
695
}
527
696
% End
528
697
529
- void __delitem__ ( int index );
530
- % Docstring
531
- Deletes the vertex at the specified ``index``. A point at the ``index`` must already exist or an IndexError will be raised.
532
698
533
- .. versionadded:: 3.6
534
- % End
699
+ /* *
700
+ * Deletes the vertex at the specified ``index``. A point at the ``index`` must already exist or an IndexError will be raised.
701
+ *
702
+ * 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
703
+ * corresponds to the last point in the line.
704
+ *
705
+ * \since QGIS 3.6
706
+ */
707
+ void __delitem__ ( int index );
535
708
% MethodCode
536
- if ( a0 >= 0 && a0 < sipCpp->numPoints () )
709
+ const int count = sipCpp->numPoints ();
710
+ if ( a0 >= 0 && a0 < count )
537
711
sipCpp->deleteVertex ( QgsVertexId( -1 , -1 , a0 ) );
712
+ else if ( a0 < 0 && a0 >= -count )
713
+ sipCpp->deleteVertex ( QgsVertexId( -1 , -1 , count + a0 ) );
538
714
else
539
715
{
540
716
PyErr_SetString ( PyExc_IndexError, QByteArray::number ( a0 ) );
0 commit comments