static PyObject *M_Geometry_BoxPack2D( PyObject * self, PyObject * boxlist ) { boxPack *boxarray = NULL; float tot_width, tot_height; int len; int error; if(!PyList_Check(boxlist)) { PyErr_SetString( PyExc_TypeError, "expected a sequence of boxes [[x,y,w,h], ... ]" ); return NULL; } len = PyList_Size( boxlist ); if (!len) return Py_BuildValue( "ff", 0.0, 0.0); error = boxPack_FromPyObject(boxlist, &boxarray); if (error!=0) return NULL; /* Non Python function */ boxPack2D(boxarray, len, &tot_width, &tot_height); boxPack_ToPyObject(boxlist, &boxarray); return Py_BuildValue( "ff", tot_width, tot_height); }
static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlist) { float tot_width = 0.0f, tot_height = 0.0f; Py_ssize_t len; PyObject *ret; if (!PyList_Check(boxlist)) { PyErr_SetString(PyExc_TypeError, "expected a list of boxes [[x, y, w, h], ... ]"); return NULL; } len = PyList_GET_SIZE(boxlist); if (len) { BoxPack *boxarray = NULL; if (boxPack_FromPyObject(boxlist, &boxarray) == -1) { return NULL; /* exception set */ } /* Non Python function */ BLI_box_pack_2D(boxarray, len, &tot_width, &tot_height); boxPack_ToPyObject(boxlist, &boxarray); } ret = PyTuple_New(2); PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(tot_width)); PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(tot_width)); return ret; }