Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/bmesh/bmesh_py_types_select.c
| Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, int keynum) | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self, | static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self, | ||||
| Py_ssize_t start, | Py_ssize_t start, | ||||
| Py_ssize_t stop) | Py_ssize_t stop) | ||||
| { | { | ||||
| int count = 0; | int count = 0; | ||||
| bool ok; | |||||
| PyObject *list; | PyObject *list; | ||||
| BMEditSelection *ese; | BMEditSelection *ese; | ||||
| BPY_BM_CHECK_OBJ(self); | BPY_BM_CHECK_OBJ(self); | ||||
| list = PyList_New(0); | list = PyList_New(0); | ||||
| ese = self->bm->selected.first; | /* First loop up-until the start. */ | ||||
| for (ese = self->bm->selected.first; ese; ese = ese->next) { | |||||
| ok = (ese != NULL); | |||||
| if (UNLIKELY(ok == false)) { | |||||
| return list; | |||||
| } | |||||
| /* first loop up-until the start */ | |||||
| for (ok = true; ok; ok = ((ese = ese->next) != NULL)) { | |||||
| if (count == start) { | if (count == start) { | ||||
| break; | break; | ||||
| } | } | ||||
| count++; | count++; | ||||
| } | } | ||||
| /* add items until stop */ | /* Add items until stop. */ | ||||
| do { | for (; ese; ese = ese->next) { | ||||
| PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head)); | PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head)); | ||||
| count++; | count++; | ||||
| if (count == stop) { | if (count == stop) { | ||||
| break; | break; | ||||
| } | } | ||||
| } while ((ese = ese->next)); | } | ||||
| return list; | return list; | ||||
| } | } | ||||
| static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *key) | static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *key) | ||||
| { | { | ||||
| /* don't need error check here */ | /* don't need error check here */ | ||||
| if (PyIndex_Check(key)) { | if (PyIndex_Check(key)) { | ||||
| Show All 28 Lines | if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (start < 0 || stop < 0) { | if (start < 0 || stop < 0) { | ||||
| /* only get the length for negative values */ | /* only get the length for negative values */ | ||||
| const Py_ssize_t len = bpy_bmeditselseq_length(self); | const Py_ssize_t len = bpy_bmeditselseq_length(self); | ||||
| if (start < 0) { | if (start < 0) { | ||||
| start += len; | start += len; | ||||
| CLAMP_MIN(start, 0); | |||||
| } | } | ||||
| if (stop < 0) { | if (stop < 0) { | ||||
| stop += len; | stop += len; | ||||
| CLAMP_MIN(stop, 0); | |||||
| } | } | ||||
| } | } | ||||
| if (stop - start <= 0) { | if (stop - start <= 0) { | ||||
| return PyList_New(0); | return PyList_New(0); | ||||
| } | } | ||||
| return bpy_bmeditselseq_subscript_slice(self, start, stop); | return bpy_bmeditselseq_subscript_slice(self, start, stop); | ||||
| ▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines | |||||