|
7 | 7 | */ |
8 | 8 | #define PY_SSIZE_T_CLEAN |
9 | 9 | #include "Python.h" |
10 | | -#include "numpy/ndarrayobject.h" |
| 10 | +#include "numpy_cpp.h" |
11 | 11 | #ifdef _MSC_VER |
12 | 12 | /* The Qhull header does not declare this as extern "C", but only MSVC seems to |
13 | 13 | * do name mangling on global variables. We thus need to declare this before |
@@ -63,7 +63,7 @@ get_facet_neighbours(const facetT* facet, const int* tri_indices, |
63 | 63 | /* Return true if the specified points arrays contain at least 3 unique points, |
64 | 64 | * or false otherwise. */ |
65 | 65 | static bool |
66 | | -at_least_3_unique_points(int npoints, const double* x, const double* y) |
| 66 | +at_least_3_unique_points(npy_intp npoints, const double* x, const double* y) |
67 | 67 | { |
68 | 68 | int i; |
69 | 69 | const int unique1 = 0; /* First unique point has index 0. */ |
@@ -98,7 +98,7 @@ at_least_3_unique_points(int npoints, const double* x, const double* y) |
98 | 98 | * If hide_qhull_errors is true then qhull error messages are discarded; |
99 | 99 | * if it is false then they are written to stderr. */ |
100 | 100 | static PyObject* |
101 | | -delaunay_impl(int npoints, const double* x, const double* y, |
| 101 | +delaunay_impl(npy_intp npoints, const double* x, const double* y, |
102 | 102 | bool hide_qhull_errors) |
103 | 103 | { |
104 | 104 | qhT qh_qh; /* qh variable type and name must be like */ |
@@ -281,58 +281,44 @@ delaunay_impl(int npoints, const double* x, const double* y, |
281 | 281 | static PyObject* |
282 | 282 | delaunay(PyObject *self, PyObject *args) |
283 | 283 | { |
284 | | - PyObject* xarg; |
285 | | - PyObject* yarg; |
286 | | - PyArrayObject* xarray; |
287 | | - PyArrayObject* yarray; |
| 284 | + numpy::array_view<double, 1> xarray; |
| 285 | + numpy::array_view<double, 1> yarray; |
288 | 286 | PyObject* ret; |
289 | | - int npoints; |
| 287 | + npy_intp npoints; |
290 | 288 | const double* x; |
291 | 289 | const double* y; |
292 | 290 |
|
293 | | - if (!PyArg_ParseTuple(args, "OO", &xarg, &yarg)) { |
294 | | - PyErr_SetString(PyExc_ValueError, "expecting x and y arrays"); |
| 291 | + if (!PyArg_ParseTuple(args, "O&O&", |
| 292 | + &xarray.converter_contiguous, &xarray, |
| 293 | + &yarray.converter_contiguous, &yarray)) { |
295 | 294 | return NULL; |
296 | 295 | } |
297 | 296 |
|
298 | | - xarray = (PyArrayObject*)PyArray_ContiguousFromObject(xarg, NPY_DOUBLE, |
299 | | - 1, 1); |
300 | | - yarray = (PyArrayObject*)PyArray_ContiguousFromObject(yarg, NPY_DOUBLE, |
301 | | - 1, 1); |
302 | | - if (xarray == 0 || yarray == 0 || |
303 | | - PyArray_DIM(xarray,0) != PyArray_DIM(yarray, 0)) { |
304 | | - Py_XDECREF(xarray); |
305 | | - Py_XDECREF(yarray); |
| 297 | + npoints = xarray.dim(0); |
| 298 | + if (npoints != yarray.dim(0)) { |
306 | 299 | PyErr_SetString(PyExc_ValueError, |
307 | 300 | "x and y must be 1D arrays of the same length"); |
308 | 301 | return NULL; |
309 | 302 | } |
310 | 303 |
|
311 | | - npoints = PyArray_DIM(xarray, 0); |
312 | | - |
313 | 304 | if (npoints < 3) { |
314 | | - Py_XDECREF(xarray); |
315 | | - Py_XDECREF(yarray); |
316 | 305 | PyErr_SetString(PyExc_ValueError, |
317 | 306 | "x and y arrays must have a length of at least 3"); |
318 | 307 | return NULL; |
319 | 308 | } |
320 | 309 |
|
321 | | - x = (const double*)PyArray_DATA(xarray); |
322 | | - y = (const double*)PyArray_DATA(yarray); |
| 310 | + x = xarray.data(); |
| 311 | + y = yarray.data(); |
323 | 312 |
|
324 | 313 | if (!at_least_3_unique_points(npoints, x, y)) { |
325 | | - Py_XDECREF(xarray); |
326 | | - Py_XDECREF(yarray); |
327 | 314 | PyErr_SetString(PyExc_ValueError, |
328 | 315 | "x and y arrays must consist of at least 3 unique points"); |
329 | 316 | return NULL; |
330 | 317 | } |
331 | 318 |
|
332 | | - ret = delaunay_impl(npoints, x, y, Py_VerboseFlag == 0); |
| 319 | + CALL_CPP("qhull.delaunay", |
| 320 | + (ret = delaunay_impl(npoints, x, y, Py_VerboseFlag == 0))); |
333 | 321 |
|
334 | | - Py_XDECREF(xarray); |
335 | | - Py_XDECREF(yarray); |
336 | 322 | return ret; |
337 | 323 | } |
338 | 324 |
|
|
0 commit comments