Blender V4.3
BPy_CurvePoint.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
9#include "BPy_CurvePoint.h"
10
11#include "../BPy_Convert.h"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18using namespace Freestyle;
19
21
22/*----------------------CurvePoint methods----------------------------*/
23
25 /* Wrap. */
26 CurvePoint_doc,
27 "Class hierarchy: :class:`Interface0D` > :class:`CurvePoint`\n"
28 "\n"
29 "Class to represent a point of a curve. A CurvePoint can be any point\n"
30 "of a 1D curve (it doesn't have to be a vertex of the curve). Any\n"
31 ":class:`Interface1D` is built upon ViewEdges, themselves built upon\n"
32 "FEdges. Therefore, a curve is basically a polyline made of a list of\n"
33 ":class:`SVertex` objects. Thus, a CurvePoint is built by linearly\n"
34 "interpolating two :class:`SVertex` instances. CurvePoint can be used\n"
35 "as virtual points while querying 0D information along a curve at a\n"
36 "given resolution.\n"
37 "\n"
38 ".. method:: __init__()\n"
39 " __init__(brother)\n"
40 " __init__(first_vertex, second_vertex, t2d)\n"
41 " __init__(first_point, second_point, t2d)\n"
42 "\n"
43 " Builds a CurvePoint using the default constructor, copy constructor,\n"
44 " or one of the overloaded constructors. The over loaded constructors\n"
45 " can either take two :class:`SVertex` or two :class:`CurvePoint`\n"
46 " objects and an interpolation parameter\n"
47 "\n"
48 " :arg brother: A CurvePoint object.\n"
49 " :type brother: :class:`CurvePoint`\n"
50 " :arg first_vertex: The first SVertex.\n"
51 " :type first_vertex: :class:`SVertex`\n"
52 " :arg second_vertex: The second SVertex.\n"
53 " :type second_vertex: :class:`SVertex`\n"
54 " :arg first_point: The first CurvePoint.\n"
55 " :type first_point: :class:`CurvePoint`\n"
56 " :arg second_point: The second CurvePoint.\n"
57 " :type second_point: :class:`CurvePoint`\n"
58 " :arg t2d: A 2D interpolation parameter used to linearly interpolate\n"
59 " first_vertex and second_vertex or first_point and second_point.\n"
60 " :type t2d: float\n");
61
62static int CurvePoint_init(BPy_CurvePoint *self, PyObject *args, PyObject *kwds)
63{
64 static const char *kwlist_1[] = {"brother", nullptr};
65 static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t2d", nullptr};
66 static const char *kwlist_3[] = {"first_point", "second_point", "t2d", nullptr};
67 PyObject *obj1 = nullptr, *obj2 = nullptr;
68 float t2d;
69
70 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePoint_Type, &obj1)) {
71 if (!obj1) {
72 self->cp = new CurvePoint();
73 }
74 else {
75 self->cp = new CurvePoint(*(((BPy_CurvePoint *)obj1)->cp));
76 }
77 }
78 else if ((void)PyErr_Clear(),
79 PyArg_ParseTupleAndKeywords(args,
80 kwds,
81 "O!O!f",
82 (char **)kwlist_2,
84 &obj1,
86 &obj2,
87 &t2d))
88 {
89 self->cp = new CurvePoint(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv, t2d);
90 }
91 else if ((void)PyErr_Clear(),
92 PyArg_ParseTupleAndKeywords(args,
93 kwds,
94 "O!O!f",
95 (char **)kwlist_3,
97 &obj1,
99 &obj2,
100 &t2d))
101 {
102 CurvePoint *cp1 = ((BPy_CurvePoint *)obj1)->cp;
103 CurvePoint *cp2 = ((BPy_CurvePoint *)obj2)->cp;
104 if (!cp1 || cp1->A() == nullptr || cp1->B() == nullptr) {
105 PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object");
106 return -1;
107 }
108 if (!cp2 || cp2->A() == nullptr || cp2->B() == nullptr) {
109 PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid CurvePoint object");
110 return -1;
111 }
112 self->cp = new CurvePoint(cp1, cp2, t2d);
113 }
114 else {
115 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
116 return -1;
117 }
118 self->py_if0D.if0D = self->cp;
119 self->py_if0D.borrowed = false;
120 return 0;
121}
122
124
125/*----------------------CurvePoint get/setters ----------------------------*/
126
128 /* Wrap. */
129 CurvePoint_first_svertex_doc,
130 "The first SVertex upon which the CurvePoint is built.\n"
131 "\n"
132 ":type: :class:`SVertex`");
133
134static PyObject *CurvePoint_first_svertex_get(BPy_CurvePoint *self, void * /*closure*/)
135{
136 SVertex *A = self->cp->A();
137 if (A) {
138 return BPy_SVertex_from_SVertex(*A);
139 }
140 Py_RETURN_NONE;
141}
142
143static int CurvePoint_first_svertex_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
144{
145 if (!BPy_SVertex_Check(value)) {
146 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
147 return -1;
148 }
149 self->cp->setA(((BPy_SVertex *)value)->sv);
150 return 0;
151}
152
154 /* Wrap. */
155 CurvePoint_second_svertex_doc,
156 "The second SVertex upon which the CurvePoint is built.\n"
157 "\n"
158 ":type: :class:`SVertex`");
159
160static PyObject *CurvePoint_second_svertex_get(BPy_CurvePoint *self, void * /*closure*/)
161{
162 SVertex *B = self->cp->B();
163 if (B) {
165 }
166 Py_RETURN_NONE;
167}
168
169static int CurvePoint_second_svertex_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
170{
171 if (!BPy_SVertex_Check(value)) {
172 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
173 return -1;
174 }
175 self->cp->setB(((BPy_SVertex *)value)->sv);
176 return 0;
177}
178
180 /* Wrap. */
181 CurvePoint_fedge_doc,
182 "Gets the FEdge for the two SVertices that given CurvePoints consists out of.\n"
183 "A shortcut for CurvePoint.first_svertex.get_fedge(CurvePoint.second_svertex).\n"
184 "\n"
185 ":type: :class:`FEdge`");
186
187static PyObject *CurvePoint_fedge_get(BPy_CurvePoint *self, void * /*closure*/)
188{
189 SVertex *A = self->cp->A();
190 Interface0D *B = (Interface0D *)self->cp->B();
191 // B can be nullptr under certain circumstances
192 if (B) {
193 return Any_BPy_Interface1D_from_Interface1D(*(A->getFEdge(*B)));
194 }
195 Py_RETURN_NONE;
196}
197
199 /* Wrap. */
200 CurvePoint_t2d_doc,
201 "The 2D interpolation parameter.\n"
202 "\n"
203 ":type: float");
204
205static PyObject *CurvePoint_t2d_get(BPy_CurvePoint *self, void * /*closure*/)
206{
207 return PyFloat_FromDouble(self->cp->t2d());
208}
209
210static int CurvePoint_t2d_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
211{
212 float scalar;
213 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
214 PyErr_SetString(PyExc_TypeError, "value must be a number");
215 return -1;
216 }
217 self->cp->setT2d(scalar);
218 return 0;
219}
220
221static PyGetSetDef BPy_CurvePoint_getseters[] = {
222 {"first_svertex",
225 CurvePoint_first_svertex_doc,
226 nullptr},
227 {"second_svertex",
230 CurvePoint_second_svertex_doc,
231 nullptr},
232 {"fedge", (getter)CurvePoint_fedge_get, nullptr, CurvePoint_fedge_doc, nullptr},
233 {"t2d", (getter)CurvePoint_t2d_get, (setter)CurvePoint_t2d_set, CurvePoint_t2d_doc, nullptr},
234 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
235};
236
237/*-----------------------BPy_CurvePoint type definition ------------------------------*/
238
239PyTypeObject CurvePoint_Type = {
240 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
241 /*tp_name*/ "CurvePoint",
242 /*tp_basicsize*/ sizeof(BPy_CurvePoint),
243 /*tp_itemsize*/ 0,
244 /*tp_dealloc*/ nullptr,
245 /*tp_vectorcall_offset*/ 0,
246 /*tp_getattr*/ nullptr,
247 /*tp_setattr*/ nullptr,
248 /*tp_as_async*/ nullptr,
249 /*tp_repr*/ nullptr,
250 /*tp_as_number*/ nullptr,
251 /*tp_as_sequence*/ nullptr,
252 /*tp_as_mapping*/ nullptr,
253 /*tp_hash*/ nullptr,
254 /*tp_call*/ nullptr,
255 /*tp_str*/ nullptr,
256 /*tp_getattro*/ nullptr,
257 /*tp_setattro*/ nullptr,
258 /*tp_as_buffer*/ nullptr,
259 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
260 /*tp_doc*/ CurvePoint_doc,
261 /*tp_traverse*/ nullptr,
262 /*tp_clear*/ nullptr,
263 /*tp_richcompare*/ nullptr,
264 /*tp_weaklistoffset*/ 0,
265 /*tp_iter*/ nullptr,
266 /*tp_iternext*/ nullptr,
267 /*tp_methods*/ nullptr,
268 /*tp_members*/ nullptr,
269 /*tp_getset*/ BPy_CurvePoint_getseters,
270 /*tp_base*/ &Interface0D_Type,
271 /*tp_dict*/ nullptr,
272 /*tp_descr_get*/ nullptr,
273 /*tp_descr_set*/ nullptr,
274 /*tp_dictoffset*/ 0,
275 /*tp_init*/ (initproc)CurvePoint_init,
276 /*tp_alloc*/ nullptr,
277 /*tp_new*/ nullptr,
278};
279
281
282#ifdef __cplusplus
283}
284#endif
PyObject * Any_BPy_Interface1D_from_Interface1D(Interface1D &if1D)
PyObject * BPy_SVertex_from_SVertex(SVertex &sv)
static int CurvePoint_init(BPy_CurvePoint *self, PyObject *args, PyObject *kwds)
PyTypeObject CurvePoint_Type
static PyObject * CurvePoint_first_svertex_get(BPy_CurvePoint *self, void *)
static PyObject * CurvePoint_t2d_get(BPy_CurvePoint *self, void *)
PyDoc_STRVAR(CurvePoint_doc, "Class hierarchy: :class:`Interface0D` > :class:`CurvePoint`\n" "\n" "Class to represent a point of a curve. A CurvePoint can be any point\n" "of a 1D curve (it doesn't have to be a vertex of the curve). Any\n" ":class:`Interface1D` is built upon ViewEdges, themselves built upon\n" "FEdges. Therefore, a curve is basically a polyline made of a list of\n" ":class:`SVertex` objects. Thus, a CurvePoint is built by linearly\n" "interpolating two :class:`SVertex` instances. CurvePoint can be used\n" "as virtual points while querying 0D information along a curve at a\n" "given resolution.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" " __init__(first_vertex, second_vertex, t2d)\n" " __init__(first_point, second_point, t2d)\n" "\n" " Builds a CurvePoint using the default constructor, copy constructor,\n" " or one of the overloaded constructors. The over loaded constructors\n" " can either take two :class:`SVertex` or two :class:`CurvePoint`\n" " objects and an interpolation parameter\n" "\n" " :arg brother: A CurvePoint object.\n" " :type brother: :class:`CurvePoint`\n" " :arg first_vertex: The first SVertex.\n" " :type first_vertex: :class:`SVertex`\n" " :arg second_vertex: The second SVertex.\n" " :type second_vertex: :class:`SVertex`\n" " :arg first_point: The first CurvePoint.\n" " :type first_point: :class:`CurvePoint`\n" " :arg second_point: The second CurvePoint.\n" " :type second_point: :class:`CurvePoint`\n" " :arg t2d: A 2D interpolation parameter used to linearly interpolate\n" " first_vertex and second_vertex or first_point and second_point.\n" " :type t2d: float\n")
static int CurvePoint_second_svertex_set(BPy_CurvePoint *self, PyObject *value, void *)
static PyObject * CurvePoint_fedge_get(BPy_CurvePoint *self, void *)
static int CurvePoint_first_svertex_set(BPy_CurvePoint *self, PyObject *value, void *)
static PyGetSetDef BPy_CurvePoint_getseters[]
static PyObject * CurvePoint_second_svertex_get(BPy_CurvePoint *self, void *)
static int CurvePoint_t2d_set(BPy_CurvePoint *self, PyObject *value, void *)
PyTypeObject Interface0D_Type
PyTypeObject SVertex_Type
#define BPy_SVertex_Check(v)
Definition BPy_SVertex.h:23
PyObject * self
SVertex * A()
Definition Curve.h:237
SVertex * B()
Definition Curve.h:243
#define B
inherits from class Rep
Definition AppCanvas.cpp:20