Blender V5.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
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__(*args)\n"
35 "\n"
36 " Accepted call signatures:\n"
37 "\n"
38 " - ``__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 " :param brother: A CurvePoint object.\n"
49 " :type brother: :class:`CurvePoint`\n"
50 " :param first_vertex: The first SVertex.\n"
51 " :type first_vertex: :class:`SVertex`\n"
52 " :param second_vertex: The second SVertex.\n"
53 " :type second_vertex: :class:`SVertex`\n"
54 " :param first_point: The first CurvePoint.\n"
55 " :type first_point: :class:`CurvePoint`\n"
56 " :param second_point: The second CurvePoint.\n"
57 " :type second_point: :class:`CurvePoint`\n"
58 " :param 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");
61static int CurvePoint_init(BPy_CurvePoint *self, PyObject *args, PyObject *kwds)
62{
63 static const char *kwlist_1[] = {"brother", nullptr};
64 static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t2d", nullptr};
65 static const char *kwlist_3[] = {"first_point", "second_point", "t2d", nullptr};
66 PyObject *obj1 = nullptr, *obj2 = nullptr;
67 float t2d;
68
69 if (PyArg_ParseTupleAndKeywords(args,
70 kwds,
71 "|" /* Optional arguments. */
72 "O!" /* `brother` */
73 ":__init__",
74 (char **)kwlist_1,
76 &obj1))
77 {
78 if (!obj1) {
79 self->cp = new CurvePoint();
80 }
81 else {
82 self->cp = new CurvePoint(*(((BPy_CurvePoint *)obj1)->cp));
83 }
84 }
85 else if ((void)PyErr_Clear(),
86 PyArg_ParseTupleAndKeywords(args,
87 kwds,
88 "O!" /* `first_vertex` */
89 "O!" /* `second_vertex` */
90 "f" /* `t2d` */
91 ":__init__",
92 (char **)kwlist_2,
94 &obj1,
96 &obj2,
97 &t2d))
98 {
99 self->cp = new CurvePoint(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv, t2d);
100 }
101 else if ((void)PyErr_Clear(),
102 PyArg_ParseTupleAndKeywords(args,
103 kwds,
104 "O!" /* `first_point` */
105 "O!" /* `second_point` */
106 "f" /* `t2d` */
107 ":__init__",
108 (char **)kwlist_3,
110 &obj1,
112 &obj2,
113 &t2d))
114 {
115 CurvePoint *cp1 = ((BPy_CurvePoint *)obj1)->cp;
116 CurvePoint *cp2 = ((BPy_CurvePoint *)obj2)->cp;
117 if (!cp1 || cp1->A() == nullptr || cp1->B() == nullptr) {
118 PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object");
119 return -1;
120 }
121 if (!cp2 || cp2->A() == nullptr || cp2->B() == nullptr) {
122 PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid CurvePoint object");
123 return -1;
124 }
125 self->cp = new CurvePoint(cp1, cp2, t2d);
126 }
127 else {
128 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
129 return -1;
130 }
131 self->py_if0D.if0D = self->cp;
132 self->py_if0D.borrowed = false;
133 return 0;
134}
135
137
138/*----------------------CurvePoint get/setters ----------------------------*/
139
141 /* Wrap. */
142 CurvePoint_first_svertex_doc,
143 "The first SVertex upon which the CurvePoint is built.\n"
144 "\n"
145 ":type: :class:`SVertex`\n");
146static PyObject *CurvePoint_first_svertex_get(BPy_CurvePoint *self, void * /*closure*/)
147{
148 SVertex *A = self->cp->A();
149 if (A) {
151 }
152 Py_RETURN_NONE;
153}
154
155static int CurvePoint_first_svertex_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
156{
157 if (!BPy_SVertex_Check(value)) {
158 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
159 return -1;
160 }
161 self->cp->setA(((BPy_SVertex *)value)->sv);
162 return 0;
163}
164
166 /* Wrap. */
167 CurvePoint_second_svertex_doc,
168 "The second SVertex upon which the CurvePoint is built.\n"
169 "\n"
170 ":type: :class:`SVertex`\n");
171static PyObject *CurvePoint_second_svertex_get(BPy_CurvePoint *self, void * /*closure*/)
172{
173 SVertex *B = self->cp->B();
174 if (B) {
176 }
177 Py_RETURN_NONE;
178}
179
180static int CurvePoint_second_svertex_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
181{
182 if (!BPy_SVertex_Check(value)) {
183 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
184 return -1;
185 }
186 self->cp->setB(((BPy_SVertex *)value)->sv);
187 return 0;
188}
189
191 /* Wrap. */
192 CurvePoint_fedge_doc,
193 "Gets the FEdge for the two SVertices that given CurvePoints consists out of.\n"
194 "A shortcut for CurvePoint.first_svertex.get_fedge(CurvePoint.second_svertex).\n"
195 "\n"
196 ":type: :class:`FEdge`\n");
197static PyObject *CurvePoint_fedge_get(BPy_CurvePoint *self, void * /*closure*/)
198{
199 SVertex *A = self->cp->A();
200 Interface0D *B = (Interface0D *)self->cp->B();
201 // B can be nullptr under certain circumstances
202 if (B) {
203 return Any_BPy_Interface1D_from_Interface1D(*(A->getFEdge(*B)));
204 }
205 Py_RETURN_NONE;
206}
207
209 /* Wrap. */
210 CurvePoint_t2d_doc,
211 "The 2D interpolation parameter.\n"
212 "\n"
213 ":type: float\n");
214static PyObject *CurvePoint_t2d_get(BPy_CurvePoint *self, void * /*closure*/)
215{
216 return PyFloat_FromDouble(self->cp->t2d());
217}
218
219static int CurvePoint_t2d_set(BPy_CurvePoint *self, PyObject *value, void * /*closure*/)
220{
221 float scalar;
222 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
223 PyErr_SetString(PyExc_TypeError, "value must be a number");
224 return -1;
225 }
226 self->cp->setT2d(scalar);
227 return 0;
228}
229
230static PyGetSetDef BPy_CurvePoint_getseters[] = {
231 {"first_svertex",
234 CurvePoint_first_svertex_doc,
235 nullptr},
236 {"second_svertex",
239 CurvePoint_second_svertex_doc,
240 nullptr},
241 {"fedge", (getter)CurvePoint_fedge_get, nullptr, CurvePoint_fedge_doc, nullptr},
242 {"t2d", (getter)CurvePoint_t2d_get, (setter)CurvePoint_t2d_set, CurvePoint_t2d_doc, nullptr},
243 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
244};
245
246/*-----------------------BPy_CurvePoint type definition ------------------------------*/
247
248PyTypeObject CurvePoint_Type = {
249 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
250 /*tp_name*/ "CurvePoint",
251 /*tp_basicsize*/ sizeof(BPy_CurvePoint),
252 /*tp_itemsize*/ 0,
253 /*tp_dealloc*/ nullptr,
254 /*tp_vectorcall_offset*/ 0,
255 /*tp_getattr*/ nullptr,
256 /*tp_setattr*/ nullptr,
257 /*tp_as_async*/ nullptr,
258 /*tp_repr*/ nullptr,
259 /*tp_as_number*/ nullptr,
260 /*tp_as_sequence*/ nullptr,
261 /*tp_as_mapping*/ nullptr,
262 /*tp_hash*/ nullptr,
263 /*tp_call*/ nullptr,
264 /*tp_str*/ nullptr,
265 /*tp_getattro*/ nullptr,
266 /*tp_setattro*/ nullptr,
267 /*tp_as_buffer*/ nullptr,
268 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
269 /*tp_doc*/ CurvePoint_doc,
270 /*tp_traverse*/ nullptr,
271 /*tp_clear*/ nullptr,
272 /*tp_richcompare*/ nullptr,
273 /*tp_weaklistoffset*/ 0,
274 /*tp_iter*/ nullptr,
275 /*tp_iternext*/ nullptr,
276 /*tp_methods*/ nullptr,
277 /*tp_members*/ nullptr,
278 /*tp_getset*/ BPy_CurvePoint_getseters,
279 /*tp_base*/ &Interface0D_Type,
280 /*tp_dict*/ nullptr,
281 /*tp_descr_get*/ nullptr,
282 /*tp_descr_set*/ nullptr,
283 /*tp_dictoffset*/ 0,
284 /*tp_init*/ (initproc)CurvePoint_init,
285 /*tp_alloc*/ nullptr,
286 /*tp_new*/ nullptr,
287};
288
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 *)
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 *)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject Interface0D_Type
PyTypeObject SVertex_Type
#define BPy_SVertex_Check(v)
Definition BPy_SVertex.h:19
#define A
void setB(SVertex *iB)
Definition Curve.h:267
void setT2d(float t)
Definition Curve.h:273
float t2d() const
Definition Curve.h:247
void setA(SVertex *iA)
Definition Curve.h:261
SVertex * A()
Definition Curve.h:235
SVertex * B()
Definition Curve.h:241
#define B
inherits from class Rep
Definition AppCanvas.cpp:20
BPy_Interface0D py_if0D
Freestyle::CurvePoint * cp
PyObject_HEAD Freestyle::Interface0D * if0D