88#define PY_SSIZE_T_CLEAN
99#include "Python.h"
1010#include "numpy/ndarrayobject.h"
11- #include "libqhull/qhull_a .h"
11+ #include "libqhull_r/qhull_ra .h"
1212#include <stdio.h>
1313
1414
@@ -32,11 +32,11 @@ static const char* qhull_error_msg[6] = {
3232/* Return the indices of the 3 vertices that comprise the specified facet (i.e.
3333 * triangle). */
3434static void
35- get_facet_vertices (const facetT * facet , int indices [3 ])
35+ get_facet_vertices (qhT * qh , const facetT * facet , int indices [3 ])
3636{
3737 vertexT * vertex , * * vertexp ;
3838 FOREACHvertex_ (facet -> vertices )
39- * indices ++ = qh_pointid (vertex -> point );
39+ * indices ++ = qh_pointid (qh , vertex -> point );
4040}
4141
4242/* Return the indices of the 3 triangles that are neighbors of the specified
@@ -88,6 +88,8 @@ static PyObject*
8888delaunay_impl (int npoints , const double * x , const double * y ,
8989 int hide_qhull_errors )
9090{
91+ qhT qh_qh ; /* qh variable type and name must be like */
92+ qhT * qh = & qh_qh ; /* this for Qhull macros to work correctly. */
9193 coordT * points = NULL ;
9294 facetT * facet ;
9395 int i , ntri , max_facet_id ;
@@ -148,7 +150,8 @@ delaunay_impl(int npoints, const double* x, const double* y,
148150 }
149151
150152 /* Perform Delaunay triangulation. */
151- exitcode = qh_new_qhull (ndim , npoints , points , False ,
153+ qh_zero (qh , error_file );
154+ exitcode = qh_new_qhull (qh , ndim , npoints , points , False ,
152155 "qhull d Qt Qbb Qc Qz" , NULL , error_file );
153156 if (exitcode != qh_ERRnone ) {
154157 PyErr_Format (PyExc_RuntimeError ,
@@ -159,7 +162,7 @@ delaunay_impl(int npoints, const double* x, const double* y,
159162 }
160163
161164 /* Split facets so that they only have 3 points each. */
162- qh_triangulate ();
165+ qh_triangulate (qh );
163166
164167 /* Determine ntri and max_facet_id.
165168 Note that libqhull uses macros to iterate through collections. */
@@ -169,7 +172,7 @@ delaunay_impl(int npoints, const double* x, const double* y,
169172 ++ ntri ;
170173 }
171174
172- max_facet_id = qh facet_id - 1 ;
175+ max_facet_id = qh -> facet_id - 1 ;
173176
174177 /* Create array to map facet id to triangle index. */
175178 tri_indices = (int * )malloc ((max_facet_id + 1 )* sizeof (int ));
@@ -204,7 +207,7 @@ delaunay_impl(int npoints, const double* x, const double* y,
204207 FORALLfacets {
205208 if (!facet -> upperdelaunay ) {
206209 tri_indices [facet -> id ] = i ++ ;
207- get_facet_vertices (facet , indices );
210+ get_facet_vertices (qh , facet , indices );
208211 * triangles_ptr ++ = (facet -> toporient ? indices [0 ] : indices [2 ]);
209212 * triangles_ptr ++ = indices [1 ];
210213 * triangles_ptr ++ = (facet -> toporient ? indices [2 ] : indices [0 ]);
@@ -224,8 +227,8 @@ delaunay_impl(int npoints, const double* x, const double* y,
224227 }
225228
226229 /* Clean up. */
227- qh_freeqhull (!qh_ALL );
228- qh_memfreeshort (& curlong , & totlong );
230+ qh_freeqhull (qh , !qh_ALL );
231+ qh_memfreeshort (qh , & curlong , & totlong );
229232 if (curlong || totlong )
230233 PyErr_WarnEx (PyExc_RuntimeWarning ,
231234 "Qhull could not free all allocated memory" , 1 );
@@ -243,8 +246,8 @@ delaunay_impl(int npoints, const double* x, const double* y,
243246 /* Clean up. */
244247 Py_XDECREF (triangles );
245248 Py_XDECREF (neighbors );
246- qh_freeqhull (!qh_ALL );
247- qh_memfreeshort (& curlong , & totlong );
249+ qh_freeqhull (qh , !qh_ALL );
250+ qh_memfreeshort (qh , & curlong , & totlong );
248251 /* Don't bother checking curlong and totlong as raising error anyway. */
249252 if (hide_qhull_errors )
250253 fclose (error_file );
0 commit comments