Blender V5.0
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");
57static int CurvePoint_init(BPy_CurvePoint *self, PyObject *args, PyObject *kwds)
58{
59 static const char *kwlist_1[] = {"brother", nullptr};
60 static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t2d", nullptr};
61 static const char *kwlist_3[] = {"first_point", "second_point", "t2d", nullptr};
62 PyObject *obj1 = nullptr, *obj2 = nullptr;
63 float t2d;
64
65 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePoint_Type, &obj1)) {
66 if (!obj1) {
67 self->cp = new CurvePoint();
68 }
69 else {
70 self->cp = new CurvePoint(*(((BPy_CurvePoint *)obj1)->cp));
71 }
72 }
73 else if ((void)PyErr_Clear(),
74 PyArg_ParseTupleAndKeywords(args,
75 kwds,
76 "O!O!f",
77 (char **)kwlist_2,
79 &obj1,
81 &obj2,
82 &t2d))
83 {
84 self->cp = new CurvePoint(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv, t2d);
85 }
86 else if ((void)PyErr_Clear(),
87 PyArg_ParseTupleAndKeywords(args,
88 kwds,
89 "O!O!f",
90 (char **)kwlist_3,
92 &obj1,
94 &obj2,
95 &t2d))
96 {
97 CurvePoint *cp1 = ((BPy_CurvePoint *)obj1)->cp;
98 CurvePoint *cp2 = ((BPy_CurvePoint *)obj2)->cp;
99 if (!cp1 || cp1->A() == nullptr || cp1->B() == nullptr) {
100 PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object");
101 return -1;
102 }
103 if (!cp2 || cp2->A() == nullptr || cp2->B() == nullptr) {
104 PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid CurvePoint object");
105 return -1;
106 }
107 self->cp = new CurvePoint(cp1, cp2, t2d);
108 }
109 else {
110 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
111 return -1;
112 }
113 self->py_if0D.if0D = self->cp;
114 self->py_if0D.borrowed = false;
115 return 0;
116}
117
119
120/*----------------------CurvePoint get/setters ----------------------------*/
121
123 /* Wrap. */
124 CurvePoint_first_svertex_doc,
125 "The first SVertex upon which the CurvePoint is built.\n"
126 "\n"
127 ":type: :class:`SVertex`\n");
128static PyObject *CurvePoint_first_svertex_get(BPy_CurvePoint *self, void * /*closure*/)
129{
130 SVertex *A = self->cp->A();
131 if (A) {
133 }
134 Py_RETURN_NONE;
135}
136
137static int CurvePoint_first_svertex_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
138{
139 if (!BPy_SVertex_Check(value)) {
140 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
141 return -1;
142 }
143 self->cp->setA(((BPy_SVertex *)value)->sv);
144 return 0;
145}
146
148 /* Wrap. */
149 CurvePoint_second_svertex_doc,
150 "The second SVertex upon which the CurvePoint is built.\n"
151 "\n"
152 ":type: :class:`SVertex`\n");
153static PyObject *CurvePoint_second_svertex_get(BPy_CurvePoint *self, void * /*closure*/)
154{
155 SVertex *B = self->cp->B();
156 if (B) {
158 }
159 Py_RETURN_NONE;
160}
161
162static int CurvePoint_second_svertex_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
163{
164 if (!BPy_SVertex_Check(value)) {
165 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
166 return -1;
167 }
168 self->cp->setB(((BPy_SVertex *)value)->sv);
169 return 0;
170}
171
173 /* Wrap. */
174 CurvePoint_fedge_doc,
175 "Gets the FEdge for the two SVertices that given CurvePoints consists out of.\n"
176 "A shortcut for CurvePoint.first_svertex.get_fedge(CurvePoint.second_svertex).\n"
177 "\n"
178 ":type: :class:`FEdge`\n");
179static PyObject *CurvePoint_fedge_get(BPy_CurvePoint *self, void * /*closure*/)
180{
181 SVertex *A = self->cp->A();
182 Interface0D *B = (Interface0D *)self->cp->B();
183 // B can be nullptr under certain circumstances
184 if (B) {
185 return Any_BPy_Interface1D_from_Interface1D(*(A->getFEdge(*B)));
186 }
187 Py_RETURN_NONE;
188}
189
191 /* Wrap. */
192 CurvePoint_t2d_doc,
193 "The 2D interpolation parameter.\n"
194 "\n"
195 ":type: float\n");
196static PyObject *CurvePoint_t2d_get(BPy_CurvePoint *self, void * /*closure*/)
197{
198 return PyFloat_FromDouble(self->cp->t2d());
199}
200
201static int CurvePoint_t2d_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
202{
203 float scalar;
204 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
205 PyErr_SetString(PyExc_TypeError, "value must be a number");
206 return -1;
207 }
208 self->cp->setT2d(scalar);
209 return 0;
210}
211
212static PyGetSetDef BPy_CurvePoint_getseters[] = {
213 {"first_svertex",
216 CurvePoint_first_svertex_doc,
217 nullptr},
218 {"second_svertex",
221 CurvePoint_second_svertex_doc,
222 nullptr},
223 {"fedge", (getter)CurvePoint_fedge_get, nullptr, CurvePoint_fedge_doc, nullptr},
224 {"t2d", (getter)CurvePoint_t2d_get, (setter)CurvePoint_t2d_set, CurvePoint_t2d_doc, nullptr},
225 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
226};
227
228/*-----------------------BPy_CurvePoint type definition ------------------------------*/
229
230PyTypeObject CurvePoint_Type = {
231 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
232 /*tp_name*/ "CurvePoint",
233 /*tp_basicsize*/ sizeof(BPy_CurvePoint),
234 /*tp_itemsize*/ 0,
235 /*tp_dealloc*/ nullptr,
236 /*tp_vectorcall_offset*/ 0,
237 /*tp_getattr*/ nullptr,
238 /*tp_setattr*/ nullptr,
239 /*tp_as_async*/ nullptr,
240 /*tp_repr*/ nullptr,
241 /*tp_as_number*/ nullptr,
242 /*tp_as_sequence*/ nullptr,
243 /*tp_as_mapping*/ nullptr,
244 /*tp_hash*/ nullptr,
245 /*tp_call*/ nullptr,
246 /*tp_str*/ nullptr,
247 /*tp_getattro*/ nullptr,
248 /*tp_setattro*/ nullptr,
249 /*tp_as_buffer*/ nullptr,
250 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
251 /*tp_doc*/ CurvePoint_doc,
252 /*tp_traverse*/ nullptr,
253 /*tp_clear*/ nullptr,
254 /*tp_richcompare*/ nullptr,
255 /*tp_weaklistoffset*/ 0,
256 /*tp_iter*/ nullptr,
257 /*tp_iternext*/ nullptr,
258 /*tp_methods*/ nullptr,
259 /*tp_members*/ nullptr,
260 /*tp_getset*/ BPy_CurvePoint_getseters,
261 /*tp_base*/ &Interface0D_Type,
262 /*tp_dict*/ nullptr,
263 /*tp_descr_get*/ nullptr,
264 /*tp_descr_set*/ nullptr,
265 /*tp_dictoffset*/ 0,
266 /*tp_init*/ (initproc)CurvePoint_init,
267 /*tp_alloc*/ nullptr,
268 /*tp_new*/ nullptr,
269};
270
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