Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd0e236

Browse files
committed
Add a pybind11 type caster for SketchParams
1 parent7a99055 commitcd0e236

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

‎src/_path_wrapper.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include"_path.h"
1313

14+
#include"_backend_agg_basic_types.h"
1415
#include"py_adaptors.h"
1516
#include"py_converters.h"
1617
#include"py_converters_11.h"
@@ -296,14 +297,8 @@ Py_convert_path_to_polygons(mpl::PathIterator path, agg::trans_affine trans,
296297
static py::tuple
297298
Py_cleanup_path(mpl::PathIterator path, agg::trans_affine trans,bool remove_nans,
298299
agg::rect_d clip_rect, e_snap_mode snap_mode,double stroke_width,
299-
std::optional<bool> simplify,bool return_curves,py::object sketch_obj)
300+
std::optional<bool> simplify,bool return_curves,SketchParams sketch)
300301
{
301-
SketchParams sketch;
302-
303-
if (!convert_sketch_params(sketch_obj.ptr(), &sketch)) {
304-
throwpy::error_already_set();
305-
}
306-
307302
if (!simplify.has_value()) {
308303
simplify = path.should_simplify();
309304
}
@@ -361,18 +356,13 @@ postfix : bool
361356
static py::object
362357
Py_convert_to_string(mpl::PathIterator path, agg::trans_affine trans,
363358
agg::rect_d cliprect, std::optional<bool> simplify,
364-
py::object sketch_obj,int precision,
359+
SketchParams sketch,int precision,
365360
std::array<std::string,5> codes_obj,bool postfix)
366361
{
367-
SketchParams sketch;
368362
char *codes[5];
369363
std::string buffer;
370364
bool status;
371365

372-
if (!convert_sketch_params(sketch_obj.ptr(), &sketch)) {
373-
throwpy::error_already_set();
374-
}
375-
376366
for(auto i =0; i <5; ++i) {
377367
codes[i] =const_cast<char *>(codes_obj[i].c_str());
378368
}

‎src/py_converters_11.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ namespace PYBIND11_NAMESPACE { namespace detail {
127127
}
128128
};
129129
#endif
130+
131+
/* Remove all this macro magic after dropping NumPy usage and just include `_backend_agg_basic_types.h`.*/
132+
#ifdef MPL_BACKEND_AGG_BASIC_TYPES_H
133+
template<>structtype_caster<SketchParams> {
134+
public:
135+
PYBIND11_TYPE_CASTER(SketchParams, const_name("SketchParams"));
136+
137+
boolload(handle src,bool) {
138+
if (src.is_none()) {
139+
value.scale =0.0;
140+
returntrue;
141+
}
142+
143+
auto params = src.cast<std::tuple<double,double,double>>();
144+
std::tie(value.scale, value.length, value.randomness) = params;
145+
146+
returntrue;
147+
}
148+
};
149+
#endif
130150
}}// namespace PYBIND11_NAMESPACE::detail
131151

132152
#endif/* MPL_PY_CONVERTERS_11_H*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp