@@ -565,7 +565,7 @@ PyObject *_update_path_extents(PyObject *self, PyObject *_args)
565565 if (!input_minpos || PyArray_DIM (input_minpos, 0 ) != 2 )
566566 {
567567 PyErr_SetString (PyExc_TypeError,
568- " Argument 4 to update_path_extents must be a length-2 numpy array." );
568+ " Argument 4 to update_path_extents must be a length-2 numpy array." );
569569 Py_XDECREF (input_minpos);
570570 return NULL ;
571571 }
@@ -1291,19 +1291,35 @@ clip_to_rect(Path& path,
12911291// _path_module::clip_path_to_rect(const Py::Tuple &args)
12921292PyObject *_clip_path_to_rect (PyObject *self, PyObject *_args)
12931293{
1294+ PyObject *_path, *_bbox, *_inside;
1295+ if (!PyArg_ParseTuple (_args, " OOO" , &_path, &_bbox, &_inside)) {
1296+ return NULL ;
1297+ }
1298+ PathIterator path (Py::Object (_path, false ));
1299+ bool inside = PyObject_IsTrue (_inside) != 0 ;
1300+
1301+ double x0, y0, x1, y1;
1302+ if (!py_convert_bbox (_bbox, x0, y0, x1, y1))
1303+ {
1304+ PyErr_SetString (PyExc_TypeError,
1305+ " Argument 2 to clip_to_rect must be a Bbox object." );
1306+ return NULL ;
1307+ }
1308+
1309+ /*
12941310 const Py::Tuple args(_args);
12951311 args.verify_length(3);
12961312
12971313 PathIterator path(args[0]);
12981314 Py::Object bbox_obj = args[1];
12991315 bool inside = Py::Boolean(args[2]);
1300-
1316+
13011317 double x0, y0, x1, y1;
13021318 if (!py_convert_bbox(bbox_obj.ptr(), x0, y0, x1, y1))
13031319 {
13041320 throw Py::TypeError("Argument 2 to clip_to_rect must be a Bbox object.");
13051321 }
1306-
1322+ */
13071323 std::vector<Polygon> results;
13081324 typedef agg::conv_curve<PathIterator> curve_t ;
13091325 curve_t curve (path);
@@ -1315,19 +1331,25 @@ PyObject *_clip_path_to_rect(PyObject *self, PyObject *_args)
13151331 PyObject* py_results = PyList_New (results.size ());
13161332 if (!py_results)
13171333 {
1318- throw Py::RuntimeError (" Error creating results list" );
1334+ PyErr_SetString (PyExc_RuntimeError, " Error creating results list" );
1335+ return NULL ;
1336+ // throw Py::RuntimeError("Error creating results list");
13191337 }
1320-
1338+ /*
13211339 try
13221340 {
1341+ */
13231342 for (std::vector<Polygon>::const_iterator p = results.begin (); p != results.end (); ++p)
13241343 {
13251344 size_t size = p->size ();
13261345 dims[0 ] = (npy_intp)size + 1 ;
13271346 PyArrayObject* pyarray = (PyArrayObject*)PyArray_SimpleNew (2 , dims, PyArray_DOUBLE);
13281347 if (pyarray == NULL )
13291348 {
1330- throw Py::MemoryError (" Could not allocate result array" );
1349+ PyErr_SetString (PyExc_MemoryError, " Could not allocate result array" );
1350+ Py_DECREF (py_results);
1351+ return NULL ;
1352+ // throw Py::MemoryError("Could not allocate result array");
13311353 }
13321354
13331355 double *data = (double *) PyArray_DATA (pyarray);
@@ -1342,16 +1364,20 @@ PyObject *_clip_path_to_rect(PyObject *self, PyObject *_args)
13421364
13431365 if (PyList_SetItem (py_results, p - results.begin (), (PyObject *)pyarray) == -1 )
13441366 {
1345- throw Py::RuntimeError (" Error creating results list" );
1367+ PyErr_SetString (PyExc_RuntimeError, " Error creating results list" );
1368+ Py_DECREF (py_results);
1369+ return NULL ;
1370+ // throw Py::RuntimeError("Error creating results list");
13461371 }
13471372 }
1373+ /*
13481374 }
13491375 catch (...)
13501376 {
13511377 Py_XDECREF(py_results);
13521378 throw;
13531379 }
1354-
1380+ */
13551381 // return Py::Object(py_results, true);
13561382 return py_results;
13571383}
0 commit comments