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

Skip to content

Commit f589b28

Browse files
committed
Add a pybind11 type caster for e_snap_mode
1 parent 80aaf64 commit f589b28

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/_path_wrapper.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,11 @@ Py_convert_path_to_polygons(mpl::PathIterator path, agg::trans_affine trans,
301301

302302
static py::tuple
303303
Py_cleanup_path(mpl::PathIterator path, agg::trans_affine trans, bool remove_nans,
304-
agg::rect_d clip_rect, py::object snap_mode_obj, double stroke_width,
304+
agg::rect_d clip_rect, e_snap_mode snap_mode, double stroke_width,
305305
std::optional<bool> simplify, bool return_curves, py::object sketch_obj)
306306
{
307-
e_snap_mode snap_mode;
308307
SketchParams sketch;
309308

310-
if (!convert_snap(snap_mode_obj.ptr(), &snap_mode)) {
311-
throw py::error_already_set();
312-
}
313309
if (!convert_sketch_params(sketch_obj.ptr(), &sketch)) {
314310
throw py::error_already_set();
315311
}

src/py_converters_11.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace py = pybind11;
1010

1111
#include "agg_basics.h"
1212
#include "agg_trans_affine.h"
13+
#include "path_converters.h"
1314

1415
void convert_trans_affine(const py::object& transform, agg::trans_affine& affine);
1516

@@ -85,6 +86,22 @@ namespace PYBIND11_NAMESPACE { namespace detail {
8586
}
8687
};
8788

89+
template <> struct type_caster<e_snap_mode> {
90+
public:
91+
PYBIND11_TYPE_CASTER(e_snap_mode, const_name("e_snap_mode"));
92+
93+
bool load(handle src, bool) {
94+
if (src.is_none()) {
95+
value = SNAP_AUTO;
96+
return true;
97+
}
98+
99+
value = py::cast<bool>(src) ? SNAP_TRUE : SNAP_FALSE;
100+
101+
return true;
102+
}
103+
};
104+
88105
/* Remove all this macro magic after dropping NumPy usage and just import `py_adaptors.h`. */
89106
#ifdef MPL_PY_ADAPTORS_H
90107
template <> struct type_caster<mpl::PathIterator> {

0 commit comments

Comments
 (0)