8000 Simplify in draw_path as needed (even for vector output, as does mpl). · matplotlib/mplcairo@6a59936 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a59936

Browse files
committed
Simplify in draw_path as needed (even for vector output, as does mpl).
1 parent 870c7a9 commit 6a59936

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

README.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,6 @@ Possible optimizations
542542
======================
543543

544544
- Cache eviction policy and persistent cache for ``draw_path_collection``.
545-
- Path simplification (although cairo appears to use vertex reduction and
546-
Douglas-Peucker internally?).
547545
- Use QtOpenGLWidget and the cairo-gl backend.
548546

549547
What about the already existing cairo (gtk/qt/wx/tk/...cairo) backends?

src/_mplcairo.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,17 @@ void GraphicsContextRenderer::draw_path(
964964
path_loaded = true;
965965
}
966966
};
967-
if (auto const& sketch = get_additional_state().sketch) {
968-
path =
969-
path.attr("cleaned")(
970-
"transform"_a=transform, "curves"_a=true, "sketch"_a=sketch);
967+
auto const& hatch_path =
968+
py::cast(this).attr("get_hatch_path")().cast<std::optional<py::object>>();
969+
auto const& simplify =
970+
path.attr("should_simplify").cast<bool>() && !fc && !hatch_path;
971+
auto const& sketch = get_additional_state().sketch;
972+
if (simplify || sketch) {
973+
// TODO: cairo internally uses vertex reduction and Douglas-Peucker, but it
974+
// is unclear whether it also applies to vector output? See mplcairo#37.
975+
path = path.attr("cleaned")(
976+
"transform"_a=transform, "simplify"_a=simplify, "curves"_a=true,
977+
"sketch"_a=sketch);
971978
mtx = cairo_matrix_t{1, 0, 0, -1, 0, get_additional_state().height};
972979
}
973980
if (fc) {
@@ -978,9 +985,7 @@ void GraphicsContextRenderer::draw_path(
978985
cairo_fill_preserve(cr_);
979986
cairo_restore(cr_);
980987
}
981-
if (auto const& hatch_path =
982-
py::cast(this).attr("get_hatch_path")()
983-
.cast<std::optional<py::object>>()) {
988+
if (hatch_path) {
984989
cairo_save(cr_);
985990
auto const& dpi = int(get_additional_state().dpi); // Truncating is good enough.
986991
auto const& hatch_surface =

0 commit comments

Comments
 (0)
0