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