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