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

Skip to content

Commit 925d619

Browse files
committed
Add a pybind11 type caster for e_snap_mode
1 parent d32a372 commit 925d619

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

288288
static py::tuple
289289
Py_cleanup_path(mpl::PathIterator path, agg::trans_affine trans, bool remove_nans,
290-
agg::rect_d clip_rect, py::object snap_mode_obj, double stroke_width,
290+
agg::rect_d clip_rect, e_snap_mode snap_mode, double stroke_width,
291291
std::optional<bool> simplify, bool return_curves, py::object sketch_obj)
292292
{
293-
e_snap_mode snap_mode;
294293
SketchParams sketch;
295294

296-
if (!convert_snap(snap_mode_obj.ptr(), &snap_mode)) {
297-
throw py::error_already_set();
298-
}
299295
if (!convert_sketch_params(sketch_obj.ptr(), &sketch)) {
300296
throw py::error_already_set();
301297
}

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)