Skip to content

Commit 37206c2

Browse files
QuLogicanntzer
andcommitted
Clean up some pybind11 Agg type casters
Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
1 parent 1818c7b commit 37206c2

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/_backend_agg_basic_types.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ namespace PYBIND11_NAMESPACE { namespace detail {
152152
{"round", agg::round_join},
153153
{"bevel", agg::bevel_join},
154154
};
155-
value = agg::miter_join_revert;
156155
value = enum_values.at(src.cast<std::string>());
157156
return true;
158157
}
@@ -167,13 +166,12 @@ namespace PYBIND11_NAMESPACE { namespace detail {
167166
return true;
168167
}
169168

170-
auto clippath_tuple = src.cast<py::tuple>();
171-
172-
auto path = clippath_tuple[0];
173-
if (!path.is_none()) {
174-
value.path = path.cast<mpl::PathIterator>();
169+
auto [path, trans] =
170+
src.cast<std::pair<std::optional<mpl::PathIterator>, agg::trans_affine>>();
171+
if (path) {
172+
value.path = *path;
175173
}
176-
value.trans = clippath_tuple[1].cast<agg::trans_affine>();
174+
value.trans = trans;
177175

178176
return true;
179177
}
@@ -184,15 +182,14 @@ namespace PYBIND11_NAMESPACE { namespace detail {
184182
PYBIND11_TYPE_CASTER(Dashes, const_name("Dashes"));
185183

186184
bool load(handle src, bool) {
187-
auto dash_tuple = src.cast<py::tuple>();
188-
auto dash_offset = dash_tuple[0].cast<double>();
189-
auto dashes_seq_or_none = dash_tuple[1];
185+
auto [dash_offset, dashes_seq_or_none] =
186+
src.cast<std::pair<double, std::optional<py::sequence>>>();
190187

191-
if (dashes_seq_or_none.is_none()) {
188+
if (!dashes_seq_or_none) {
192189
return true;
193190
}
194191

195-
auto dashes_seq = dashes_seq_or_none.cast<py::sequence>();
192+
auto dashes_seq = *dashes_seq_or_none;
196193

197194
auto nentries = dashes_seq.size();
198195
// If the dashpattern has odd length, iterate through it twice (in

0 commit comments

Comments
 (0)