Blender V5.3
BPy_StrokeVertexIterator.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "../BPy_Convert.h"
14
15using namespace Freestyle;
16
18
19//------------------------INSTANCE METHODS ----------------------------------
20
22 /* Wrap. */
23 StrokeVertexIterator_doc,
24 "Class hierarchy: :class:`Iterator` > :class:`StrokeVertexIterator`\n"
25 "\n"
26 "Class defining an iterator designed to iterate over the\n"
27 ":class:`StrokeVertex` of a :class:`Stroke`. An instance of a\n"
28 "StrokeVertexIterator can be obtained from a Stroke by calling\n"
29 "iter(), stroke_vertices_begin() or stroke_vertices_begin(). It is iterating\n"
30 "over the same vertices as an :class:`Interface0DIterator`. The difference\n"
31 "resides in the object access: an Interface0DIterator only allows\n"
32 "access to an Interface0D while one might need to access the\n"
33 "specialized StrokeVertex type. In this case, one should use a\n"
34 "StrokeVertexIterator. To call functions of the UnaryFunction0D type,\n"
35 "a StrokeVertexIterator can be converted to an Interface0DIterator by\n"
36 "by calling Interface0DIterator(it).\n"
37 "\n"
38 ".. method:: __init__(*args)\n"
39 "\n"
40 " Accepted call signatures:\n"
41 "\n"
42 " - ``__init__()``\n"
43 " - ``__init__(brother)``\n"
44 "\n"
45 " Creates a :class:`StrokeVertexIterator` using either the\n"
46 " default constructor or the copy constructor.\n"
47 "\n"
48 " :param brother: A StrokeVertexIterator object.\n"
49 " :type brother: :class:`StrokeVertexIterator`\n");
51 PyObject *args,
52 PyObject *kwds)
53{
54 static const char *kwlist_1[] = {"brother", nullptr};
55 static const char *kwlist_2[] = {"stroke", nullptr};
56 PyObject *brother = nullptr, *stroke = nullptr;
57
58 if (PyArg_ParseTupleAndKeywords(args,
59 kwds,
60 "O!" /* `brother` */
61 ":__init__",
62 (char **)kwlist_1,
64 &brother))
65 {
67 *(((BPy_StrokeVertexIterator *)brother)->sv_it));
68 self->reversed = ((BPy_StrokeVertexIterator *)brother)->reversed;
69 self->at_start = ((BPy_StrokeVertexIterator *)brother)->at_start;
70 }
71
72 else if ((void)PyErr_Clear(),
73 PyArg_ParseTupleAndKeywords(args,
74 kwds,
75 "|" /* Optional arguments. */
76 "O!" /* `stroke` */
77 ":__init__",
78 (char **)kwlist_2,
80 &stroke))
81 {
82 if (!stroke) {
84 }
85 else {
87 ((BPy_Stroke *)stroke)->s->strokeVerticesBegin());
88 }
89 self->reversed = false;
90 self->at_start = true;
91 }
92 else {
93 PyErr_SetString(PyExc_TypeError, "argument 1 must be StrokeVertexIterator or Stroke");
94 return -1;
95 }
96 self->py_it.it = self->sv_it;
97 return 0;
98}
99
101{
102 Py_INCREF(self);
103 self->at_start = true;
104 return (PyObject *)self;
105}
106
108{
109 /* Because Freestyle iterators for which it.isEnd() holds true have no valid object
110 * (they point to the past-the-end element and can't be dereferenced), we have to check
111 * iterators for validity.
112 * Additionally, the at_start attribute is used to keep Freestyle iterator objects
113 * and Python for loops in sync. */
114
115 if (self->reversed) {
116 if (self->sv_it->isBegin()) {
117 PyErr_SetNone(PyExc_StopIteration);
118 return nullptr;
119 }
120 self->sv_it->decrement();
121 }
122 else {
123 /* If sv_it.isEnd() is true, the iterator can't be incremented. */
124 if (self->sv_it->isEnd()) {
125 PyErr_SetNone(PyExc_StopIteration);
126 return nullptr;
127 }
128 /* If at the start of the iterator, only return the object
129 * and don't increment, to keep for-loops in sync */
130 if (self->at_start) {
131 self->at_start = false;
132 }
133 /* If sv_it.atLast() is true, the iterator is currently pointing to the final valid element.
134 * Incrementing it further would lead to a state that the iterator can't be dereferenced. */
135 else if (self->sv_it->atLast()) {
136 PyErr_SetNone(PyExc_StopIteration);
137 return nullptr;
138 }
139 else {
140 self->sv_it->increment();
141 }
142 }
143 StrokeVertex *sv = self->sv_it->operator->();
145}
146
147/*----------------------StrokeVertexIterator methods ----------------------------*/
148
150 /* Wrap. */
151 StrokeVertexIterator_incremented_doc,
152 ".. method:: incremented()\n"
153 "\n"
154 " Returns a copy of an incremented StrokeVertexIterator.\n"
155 "\n"
156 " :return: A StrokeVertexIterator pointing the next StrokeVertex.\n"
157 " :rtype: :class:`StrokeVertexIterator`\n");
159{
160 if (self->sv_it->isEnd()) {
161 PyErr_SetString(PyExc_RuntimeError, "cannot increment any more");
162 return nullptr;
163 }
165 copy.increment();
167}
168
170 /* Wrap. */
171 StrokeVertexIterator_decremented_doc,
172 ".. method:: decremented()\n"
173 "\n"
174 " Returns a copy of a decremented StrokeVertexIterator.\n"
175 "\n"
176 " :return: A StrokeVertexIterator pointing the previous StrokeVertex.\n"
177 " :rtype: :class:`StrokeVertexIterator`\n");
179{
180 if (self->sv_it->isBegin()) {
181 PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more");
182 return nullptr;
183 }
185 copy.decrement();
187}
188
190 /* Wrap. */
191 StrokeVertexIterator_reversed_doc,
192 ".. method:: reversed()\n"
193 "\n"
194 " Returns a StrokeVertexIterator that traverses stroke vertices in the\n"
195 " reversed order.\n"
196 "\n"
197 " :return: A StrokeVertexIterator traversing stroke vertices backward.\n"
198 " :rtype: :class:`StrokeVertexIterator`\n");
203
204#ifdef __GNUC__
205# ifdef __clang__
206# pragma clang diagnostic push
207# pragma clang diagnostic ignored "-Wcast-function-type"
208# else
209# pragma GCC diagnostic push
210# pragma GCC diagnostic ignored "-Wcast-function-type"
211# endif
212#endif
213
214static PyMethodDef BPy_StrokeVertexIterator_methods[] = {
215 {"incremented",
217 METH_NOARGS,
218 StrokeVertexIterator_incremented_doc},
219 {"decremented",
221 METH_NOARGS,
222 StrokeVertexIterator_decremented_doc},
223 {"reversed",
225 METH_NOARGS,
226 StrokeVertexIterator_reversed_doc},
227 {nullptr, nullptr, 0, nullptr},
228};
229
230#ifdef __GNUC__
231# ifdef __clang__
232# pragma clang diagnostic pop
233# else
234# pragma GCC diagnostic pop
235# endif
236#endif
237
238/*----------------------StrokeVertexIterator get/setters ----------------------------*/
239
241 /* Wrap. */
242 StrokeVertexIterator_object_doc,
243 "The StrokeVertex object currently pointed to by this iterator.\n"
244 "\n"
245 ":type: :class:`StrokeVertex`\n");
247 void * /*closure*/)
248{
249 if (self->sv_it->isEnd()) {
250 PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
251 return nullptr;
252 }
253 StrokeVertex *sv = self->sv_it->operator->();
254 if (sv) {
256 }
257 Py_RETURN_NONE;
258}
259
261 /* Wrap. */
262 StrokeVertexIterator_t_doc,
263 "The curvilinear abscissa of the current point.\n"
264 "\n"
265 ":type: float\n");
266static PyObject *StrokeVertexIterator_t_get(BPy_StrokeVertexIterator *self, void * /*closure*/)
267{
268 return PyFloat_FromDouble(self->sv_it->t());
269}
270
272 /* Wrap. */
273 StrokeVertexIterator_u_doc,
274 "The point parameter at the current point in the stroke (0 <= u <= 1).\n"
275 "\n"
276 ":type: float\n");
277static PyObject *StrokeVertexIterator_u_get(BPy_StrokeVertexIterator *self, void * /*closure*/)
278{
279 return PyFloat_FromDouble(self->sv_it->u());
280}
281
283 /* Wrap. */
284 StrokeVertexIterator_at_last_doc,
285 "True if the iterator points to the last valid element.\n"
286 "For its counterpart (pointing to the first valid element), use it.is_begin.\n"
287 "\n"
288 ":type: bool\n");
290{
291 return PyBool_from_bool(self->sv_it->atLast());
292}
293
294#ifdef __GNUC__
295# ifdef __clang__
296# pragma clang diagnostic push
297# pragma clang diagnostic ignored "-Wcast-function-type"
298# else
299# pragma GCC diagnostic push
300# pragma GCC diagnostic ignored "-Wcast-function-type"
301# endif
302#endif
303
305 {"object",
307 (setter) nullptr,
308 StrokeVertexIterator_object_doc,
309 nullptr},
310 {"t",
312 (setter) nullptr,
313 StrokeVertexIterator_t_doc,
314 nullptr},
315 {"u",
317 (setter) nullptr,
318 StrokeVertexIterator_u_doc,
319 nullptr},
320 {"at_last",
322 (setter) nullptr,
323 StrokeVertexIterator_at_last_doc,
324 nullptr},
325 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
326};
327
328#ifdef __GNUC__
329# ifdef __clang__
330# pragma clang diagnostic pop
331# else
332# pragma GCC diagnostic pop
333# endif
334#endif
335
336/*-----------------------BPy_StrokeVertexIterator type definition ------------------------------*/
337
339 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
340 /*tp_name*/ "StrokeVertexIterator",
341 /*tp_basicsize*/ sizeof(BPy_StrokeVertexIterator),
342 /*tp_itemsize*/ 0,
343 /*tp_dealloc*/ nullptr,
344 /*tp_vectorcall_offset*/ 0,
345 /*tp_getattr*/ nullptr,
346 /*tp_setattr*/ nullptr,
347 /*tp_as_async*/ nullptr,
348 /*tp_repr*/ nullptr,
349 /*tp_as_number*/ nullptr,
350 /*tp_as_sequence*/ nullptr,
351 /*tp_as_mapping*/ nullptr,
352 /*tp_hash*/ nullptr,
353 /*tp_call*/ nullptr,
354 /*tp_str*/ nullptr,
355 /*tp_getattro*/ nullptr,
356 /*tp_setattro*/ nullptr,
357 /*tp_as_buffer*/ nullptr,
358 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
359 /*tp_doc*/ StrokeVertexIterator_doc,
360 /*tp_traverse*/ nullptr,
361 /*tp_clear*/ nullptr,
362 /*tp_richcompare*/ nullptr,
363 /*tp_weaklistoffset*/ 0,
364 /*tp_iter*/ (getiterfunc)StrokeVertexIterator_iter,
365 /*tp_iternext*/ (iternextfunc)StrokeVertexIterator_iternext,
367 /*tp_members*/ nullptr,
369 /*tp_base*/ &Iterator_Type,
370 /*tp_dict*/ nullptr,
371 /*tp_descr_get*/ nullptr,
372 /*tp_descr_set*/ nullptr,
373 /*tp_dictoffset*/ 0,
374 /*tp_init*/ (initproc)StrokeVertexIterator_init,
375 /*tp_alloc*/ nullptr,
376 /*tp_new*/ nullptr,
377};
378
PyObject * BPy_StrokeVertexIterator_from_StrokeVertexIterator(StrokeInternal::StrokeVertexIterator &sv_it, bool reversed)
PyObject * BPy_StrokeVertex_from_StrokeVertex(StrokeVertex &sv)
PyObject * PyBool_from_bool(bool b)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject Iterator_Type
static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *args, PyObject *kwds)
static PyObject * StrokeVertexIterator_at_last_get(BPy_StrokeVertexIterator *self)
static PyObject * StrokeVertexIterator_reversed(BPy_StrokeVertexIterator *self)
static PyObject * StrokeVertexIterator_t_get(BPy_StrokeVertexIterator *self, void *)
static PyObject * StrokeVertexIterator_decremented(BPy_StrokeVertexIterator *self)
static PyObject * StrokeVertexIterator_object_get(BPy_StrokeVertexIterator *self, void *)
static PyObject * StrokeVertexIterator_u_get(BPy_StrokeVertexIterator *self, void *)
PyTypeObject StrokeVertexIterator_Type
static PyObject * StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self)
static PyGetSetDef BPy_StrokeVertexIterator_getseters[]
static PyObject * StrokeVertexIterator_incremented(BPy_StrokeVertexIterator *self)
static PyMethodDef BPy_StrokeVertexIterator_methods[]
static PyObject * StrokeVertexIterator_iter(BPy_StrokeVertexIterator *self)
PyTypeObject Stroke_Type
float u() const
Definition Stroke.h:396
inherits from class Rep
Definition AppCanvas.cpp:20
PyObject_HEAD Freestyle::Iterator * it
Freestyle::StrokeInternal::StrokeVertexIterator * sv_it