Blender V4.3
BPy_CurvePointIterator.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
10
11#include "../BPy_Convert.h"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18using namespace Freestyle;
19
21
22//------------------------INSTANCE METHODS ----------------------------------
23
25 /* Wrap. */
26 CurvePointIterator_doc,
27 "Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n"
28 "\n"
29 "Class representing an iterator on a curve. Allows an iterating\n"
30 "outside initial vertices. A CurvePoint is instantiated and returned\n"
31 "through the .object attribute.\n"
32 "\n"
33 ".. method:: __init__()\n"
34 " __init__(brother)\n"
35 " __init__(step=0.0)\n"
36 "\n"
37 " Builds a CurvePointIterator object using either the default constructor,\n"
38 " copy constructor, or the overloaded constructor.\n"
39 "\n"
40 " :arg brother: A CurvePointIterator object.\n"
41 " :type brother: :class:`CurvePointIterator`\n"
42 " :arg step: A resampling resolution with which the curve is resampled.\n"
43 " If zero, no resampling is done (i.e., the iterator iterates over\n"
44 " initial vertices).\n"
45 " :type step: float");
46
47static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args, PyObject *kwds)
48{
49 static const char *kwlist_1[] = {"brother", nullptr};
50 static const char *kwlist_2[] = {"step", nullptr};
51 PyObject *brother = nullptr;
52 float step;
53
54 if (PyArg_ParseTupleAndKeywords(
55 args, kwds, "|O!", (char **)kwlist_1, &CurvePointIterator_Type, &brother))
56 {
57 if (!brother) {
59 }
60 else {
62 *(((BPy_CurvePointIterator *)brother)->cp_it));
63 }
64 }
65 else if ((void)PyErr_Clear(),
66 PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &step))
67 {
68 self->cp_it = new CurveInternal::CurvePointIterator(step);
69 }
70 else {
71 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
72 return -1;
73 }
74 self->py_it.it = self->cp_it;
75 return 0;
76}
77
78/*----------------------CurvePointIterator get/setters ----------------------------*/
79
81 /* Wrap. */
82 CurvePointIterator_object_doc,
83 "The CurvePoint object currently pointed by this iterator.\n"
84 "\n"
85 ":type: :class:`CurvePoint`");
86
87static PyObject *CurvePointIterator_object_get(BPy_CurvePointIterator *self, void * /*closure*/)
88{
89 if (self->cp_it->isEnd()) {
90 PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
91 return nullptr;
92 }
93 return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*());
94}
95
97 /* Wrap. */
98 CurvePointIterator_t_doc,
99 "The curvilinear abscissa of the current point.\n"
100 "\n"
101 ":type: float");
102
103static PyObject *CurvePointIterator_t_get(BPy_CurvePointIterator *self, void * /*closure*/)
104{
105 return PyFloat_FromDouble(self->cp_it->t());
106}
107
109 /* Wrap. */
110 CurvePointIterator_u_doc,
111 "The point parameter at the current point in the stroke (0 <= u <= 1).\n"
112 "\n"
113 ":type: float");
114
115static PyObject *CurvePointIterator_u_get(BPy_CurvePointIterator *self, void * /*closure*/)
116{
117 return PyFloat_FromDouble(self->cp_it->u());
118}
119
120static PyGetSetDef BPy_CurvePointIterator_getseters[] = {
121 {"object",
123 (setter) nullptr,
124 CurvePointIterator_object_doc,
125 nullptr},
126 {"t", (getter)CurvePointIterator_t_get, (setter) nullptr, CurvePointIterator_t_doc, nullptr},
127 {"u", (getter)CurvePointIterator_u_get, (setter) nullptr, CurvePointIterator_u_doc, nullptr},
128 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
129};
130
131/*-----------------------BPy_CurvePointIterator type definition ------------------------------*/
132
134 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
135 /*tp_name*/ "CurvePointIterator",
136 /*tp_basicsize*/ sizeof(BPy_CurvePointIterator),
137 /*tp_itemsize*/ 0,
138 /*tp_dealloc*/ nullptr,
139 /*tp_vectorcall_offset*/ 0,
140 /*tp_getattr*/ nullptr,
141 /*tp_setattr*/ nullptr,
142 /*tp_as_async*/ nullptr,
143 /*tp_repr*/ nullptr,
144 /*tp_as_number*/ nullptr,
145 /*tp_as_sequence*/ nullptr,
146 /*tp_as_mapping*/ nullptr,
147 /*tp_hash*/ nullptr,
148 /*tp_call*/ nullptr,
149 /*tp_str*/ nullptr,
150 /*tp_getattro*/ nullptr,
151 /*tp_setattro*/ nullptr,
152 /*tp_as_buffer*/ nullptr,
153 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
154 /*tp_doc*/ CurvePointIterator_doc,
155 /*tp_traverse*/ nullptr,
156 /*tp_clear*/ nullptr,
157 /*tp_richcompare*/ nullptr,
158 /*tp_weaklistoffset*/ 0,
159 /*tp_iter*/ nullptr,
160 /*tp_iternext*/ nullptr,
161 /*tp_methods*/ nullptr,
162 /*tp_members*/ nullptr,
164 /*tp_base*/ &Iterator_Type,
165 /*tp_dict*/ nullptr,
166 /*tp_descr_get*/ nullptr,
167 /*tp_descr_set*/ nullptr,
168 /*tp_dictoffset*/ 0,
169 /*tp_init*/ (initproc)CurvePointIterator_init,
170 /*tp_alloc*/ nullptr,
171 /*tp_new*/ nullptr,
172};
173
175
176#ifdef __cplusplus
177}
178#endif
PyObject * BPy_CurvePoint_from_CurvePoint(CurvePoint &cp)
static PyObject * CurvePointIterator_object_get(BPy_CurvePointIterator *self, void *)
static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(CurvePointIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n" "\n" "Class representing an iterator on a curve. Allows an iterating\n" "outside initial vertices. A CurvePoint is instantiated and returned\n" "through the .object attribute.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" " __init__(step=0.0)\n" "\n" " Builds a CurvePointIterator object using either the default constructor,\n" " copy constructor, or the overloaded constructor.\n" "\n" " :arg brother: A CurvePointIterator object.\n" " :type brother: :class:`CurvePointIterator`\n" " :arg step: A resampling resolution with which the curve is resampled.\n" " If zero, no resampling is done (i.e., the iterator iterates over\n" " initial vertices).\n" " :type step: float")
static PyGetSetDef BPy_CurvePointIterator_getseters[]
static PyObject * CurvePointIterator_t_get(BPy_CurvePointIterator *self, void *)
PyTypeObject CurvePointIterator_Type
static PyObject * CurvePointIterator_u_get(BPy_CurvePointIterator *self, void *)
PyTypeObject Iterator_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20