Skip to content

Commit 7a99055

Browse files
committed
Add a pybind11 type caster for e_snap_mode
1 parent ce39f3f commit 7a99055

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
@@ -295,15 +295,11 @@ Py_convert_path_to_polygons(mpl::PathIterator path, agg::trans_affine trans,
295295

296296
static py::tuple
297297
Py_cleanup_path(mpl::PathIterator path, agg::trans_affine trans, bool remove_nans,
298-
agg::rect_d clip_rect, py::object snap_mode_obj, double stroke_width,
298+
agg::rect_d clip_rect, e_snap_mode snap_mode, double stroke_width,
299299
std::optional<bool> simplify, bool return_curves, py::object sketch_obj)
300300
{
301-
e_snap_mode snap_mode;
302301
SketchParams sketch;
303302

304-
if (!convert_snap(snap_mode_obj.ptr(), &snap_mode)) {
305-
throw py::error_already_set();
306-
}
307303
if (!convert_sketch_params(sketch_obj.ptr(), &sketch)) {
308304
throw py::error_already_set();
309305
}

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 = src.cast<bool>() ? SNAP_TRUE : SNAP_FALSE;
100+
101+
return true;
102+
}
103+
};
104+
88105
/* Remove all this macro magic after dropping NumPy usage and just include `py_adaptors.h`. */
89106
#ifdef MPL_PY_ADAPTORS_H
90107
template <> struct type_caster<mpl::PathIterator> {

0 commit comments

Comments
 (0)