@@ -19,7 +19,6 @@ extern const char qh_version[];
19
19
20
20
#include " libqhull_r/qhull_ra.h"
21
21
#include < cstdio>
22
- #include < sstream>
23
22
#include < vector>
24
23
25
24
#ifndef MPL_DEVNULL
@@ -135,7 +134,7 @@ class QhullInfo {
135
134
/* Delaunay implementation method.
136
135
* If hide_qhull_errors is true then qhull error messages are discarded;
137
136
* if it is false then they are written to stderr. */
138
- py::tuple
137
+ static py::tuple
139
138
delaunay_impl (py::ssize_t npoints, const double * x, const double * y,
140
139
bool hide_qhull_errors)
141
140
{
@@ -189,12 +188,12 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y,
189
188
exitcode = qh_new_qhull (qh, ndim, (int )npoints, points.data (), False,
190
189
(char *)" qhull d Qt Qbb Qc Qz" , NULL , error_file);
191
190
if (exitcode != qh_ERRnone) {
192
- std::ostringstream oss;
193
- oss << " Error in qhull Delaunay triangulation calculation: " <<
194
- qhull_error_msg[exitcode] << " ( exitcode= " << exitcode << " ) " ;
191
+ std::string msg =
192
+ py::str ( " Error in qhull Delaunay triangulation calculation: {} (exitcode={}) " )
193
+ . format ( qhull_error_msg[exitcode], exitcode). cast <std::string>() ;
195
194
if (hide_qhull_errors)
196
- oss << " ; use python verbose option (-v) to see original qhull error." ;
197
- throw std::runtime_error (oss. str () );
195
+ msg += " ; use python verbose option (-v) to see original qhull error." ;
196
+ throw std::runtime_error (msg );
198
197
}
199
198
200
199
/* Split facets so that they only have 3 points each. */
@@ -253,7 +252,7 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y,
253
252
}
254
253
255
254
/* Process Python arguments and call Delaunay implementation method. */
256
- py::tuple
255
+ static py::tuple
257
256
delaunay (const CoordArray& x, const CoordArray& y)
258
257
{
259
258
if (x.ndim () != 1 || y.ndim () != 1 )
@@ -272,17 +271,10 @@ delaunay(const CoordArray& x, const CoordArray& y)
272
271
return delaunay_impl (npoints, x.data (), y.data (), Py_VerboseFlag == 0 );
273
272
}
274
273
275
- /* Return qhull version string for assistance in debugging. */
276
- std::string
277
- version ()
278
- {
279
- return std::string (qh_version);
280
- }
281
-
282
274
PYBIND11_MODULE (_qhull, m) {
283
275
m.doc () = " Computing Delaunay triangulations.\n " ;
284
276
285
- m.def (" delaunay" , &delaunay,
277
+ m.def (" delaunay" , &delaunay, py::arg ( " x " ), py::arg ( " y " ),
286
278
" delaunay(x, y, /)\n "
287
279
" --\n\n "
288
280
" Compute a Delaunay triangulation.\n "
@@ -298,7 +290,7 @@ PYBIND11_MODULE(_qhull, m) {
298
290
" triangles, neighbors : int arrays, shape (ntri, 3)\n "
299
291
" Indices of triangle vertices and indices of triangle neighbors.\n " );
300
292
301
- m.def (" version" , &version ,
293
+ m.def (" version" , []() { return qh_version; } ,
302
294
" version()\n --\n\n "
303
295
" Return the qhull version string." );
304
296
}
0 commit comments