Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7da3539

Browse files
committed
Address review comments
1 parent 293dffc commit 7da3539

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/_qhull_wrapper.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extern const char qh_version[];
1919

2020
#include "libqhull_r/qhull_ra.h"
2121
#include <cstdio>
22-
#include <sstream>
2322
#include <vector>
2423

2524
#ifndef MPL_DEVNULL
@@ -135,7 +134,7 @@ class QhullInfo {
135134
/* Delaunay implementation method.
136135
* If hide_qhull_errors is true then qhull error messages are discarded;
137136
* if it is false then they are written to stderr. */
138-
py::tuple
137+
static py::tuple
139138
delaunay_impl(py::ssize_t npoints, const double* x, const double* y,
140139
bool hide_qhull_errors)
141140
{
@@ -189,12 +188,12 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y,
189188
exitcode = qh_new_qhull(qh, ndim, (int)npoints, points.data(), False,
190189
(char*)"qhull d Qt Qbb Qc Qz", NULL, error_file);
191190
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>();
195194
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);
198197
}
199198

200199
/* 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,
253252
}
254253

255254
/* Process Python arguments and call Delaunay implementation method. */
256-
py::tuple
255+
static py::tuple
257256
delaunay(const CoordArray& x, const CoordArray& y)
258257
{
259258
if (x.ndim() != 1 || y.ndim() != 1)
@@ -272,17 +271,10 @@ delaunay(const CoordArray& x, const CoordArray& y)
272271
return delaunay_impl(npoints, x.data(), y.data(), Py_VerboseFlag == 0);
273272
}
274273

275-
/* Return qhull version string for assistance in debugging. */
276-
std::string
277-
version()
278-
{
279-
return std::string(qh_version);
280-
}
281-
282274
PYBIND11_MODULE(_qhull, m) {
283275
m.doc() = "Computing Delaunay triangulations.\n";
284276

285-
m.def("delaunay", &delaunay,
277+
m.def("delaunay", &delaunay, py::arg("x"), py::arg("y"),
286278
"delaunay(x, y, /)\n"
287279
"--\n\n"
288280
"Compute a Delaunay triangulation.\n"
@@ -298,7 +290,7 @@ PYBIND11_MODULE(_qhull, m) {
298290
"triangles, neighbors : int arrays, shape (ntri, 3)\n"
299291
" Indices of triangle vertices and indices of triangle neighbors.\n");
300292

301-
m.def("version", &version,
293+
m.def("version", []() { return qh_version; },
302294
"version()\n--\n\n"
303295
"Return the qhull version string.");
304296
}

0 commit comments

Comments
 (0)