From 28784521c9795ff7f222583a5b332015aff5bcc5 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 7 Sep 2022 18:50:41 +0200 Subject: [PATCH] Make draw_gouraud_triangle optional and remove unused versions --- lib/matplotlib/backend_bases.py | 12 +++++++- lib/matplotlib/backends/backend_agg.py | 1 - lib/matplotlib/backends/backend_pdf.py | 4 --- lib/matplotlib/backends/backend_ps.py | 5 --- lib/matplotlib/collections.py | 2 +- src/_backend_agg.h | 20 ------------ src/_backend_agg_wrapper.cpp | 42 -------------------------- 7 files changed, 12 insertions(+), 74 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index bb17950b03f7..c932ea18e387 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -158,7 +158,7 @@ class RendererBase: * `draw_path` * `draw_image` - * `draw_gouraud_triangle` + * `draw_gouraud_triangle` or `draw_gouraud_triangles` The following methods *should* be implemented in the backend for optimization reasons: @@ -300,6 +300,11 @@ def draw_gouraud_triangle(self, gc, points, colors, transform): RGBA colors for each point of the triangle. transform : `matplotlib.transforms.Transform` An affine transform to apply to the points. + + .. note:: + It is enough to implement one of `draw_gouraud_triangle` and + `draw_gouraud_triangles`. Any `Artist` must call + `draw_gouraud_triangles`. """ raise NotImplementedError @@ -316,6 +321,11 @@ def draw_gouraud_triangles(self, gc, triangles_array, colors_array, Array of *N* RGBA colors for each point of the triangles. transform : `matplotlib.transforms.Transform` An affine transform to apply to the points. + + .. note:: + It is enough to implement one of `draw_gouraud_triangle` and + `draw_gouraud_triangles`. Any `Artist` must call + `draw_gouraud_triangles`. """ transform = transform.frozen() for tri, col in zip(triangles_array, colors_array): diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index 0d8a127dba8c..adaf2e797e3f 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -101,7 +101,6 @@ def __setstate__(self, state): self.__init__(state['width'], state['height'], state['dpi']) def _update_methods(self): - self.draw_gouraud_triangle = self._renderer.draw_gouraud_triangle self.draw_gouraud_triangles = self._renderer.draw_gouraud_triangles self.draw_image = self._renderer.draw_image self.draw_markers = self._renderer.draw_markers diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index a3ea5dac6e43..f6fffc6b524f 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -2153,10 +2153,6 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, lastx, lasty = x, y output(Op.grestore) - def draw_gouraud_triangle(self, gc, points, colors, trans): - self.draw_gouraud_triangles(gc, points.reshape((1, 3, 2)), - colors.reshape((1, 3, 4)), trans) - def draw_gouraud_triangles(self, gc, points, colors, trans): assert len(points) == len(colors) if len(points) == 0: diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index f209e811f18b..b3d347fcbeea 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -710,11 +710,6 @@ def draw_mathtext(self, gc, x, y, s, prop, angle): self._pswriter.write(f"{ox} {oy} {w} {h} rectfill\n") self._pswriter.write("grestore\n") - @_log_if_debug_on - def draw_gouraud_triangle(self, gc, points, colors, trans): - self.draw_gouraud_triangles(gc, points.reshape((1, 3, 2)), - colors.reshape((1, 3, 4)), trans) - @_log_if_debug_on def draw_gouraud_triangles(self, gc, points, colors, trans): assert len(points) == len(colors) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index cef043e79ddb..8aba85a67e0a 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -2097,7 +2097,7 @@ def _convert_mesh_to_triangles(self, coordinates): """ Convert a given mesh into a sequence of triangles, each point with its own color. The result can be used to construct a call to - `~.RendererBase.draw_gouraud_triangle`. + `~.RendererBase.draw_gouraud_triangles`. """ if isinstance(coordinates, np.ma.MaskedArray): p = coordinates.data diff --git a/src/_backend_agg.h b/src/_backend_agg.h index 8f175b18f0bf..11dd48bc5fae 100644 --- a/src/_backend_agg.h +++ b/src/_backend_agg.h @@ -190,12 +190,6 @@ class RendererAgg bool antialiased, ColorArray &edgecolors); - template - void draw_gouraud_triangle(GCAgg &gc, - PointArray &points, - ColorArray &colors, - agg::trans_affine &trans); - template void draw_gouraud_triangles(GCAgg &gc, PointArray &points, @@ -1223,20 +1217,6 @@ inline void RendererAgg::_draw_gouraud_triangle(PointArray &points, } } -template -inline void RendererAgg::draw_gouraud_triangle(GCAgg &gc, - PointArray &points, - ColorArray &colors, - agg::trans_affine &trans) -{ - theRasterizer.reset_clipping(); - rendererBase.reset_clipping(true); - set_clipbox(gc.cliprect, theRasterizer); - bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans, gc.snap_mode); - - _draw_gouraud_triangle(points, colors, trans, has_clippath); -} - template inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc, PointArray &points, diff --git a/src/_backend_agg_wrapper.cpp b/src/_backend_agg_wrapper.cpp index 9d0c3dbc759a..99caad967fc0 100644 --- a/src/_backend_agg_wrapper.cpp +++ b/src/_backend_agg_wrapper.cpp @@ -421,47 +421,6 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg Py_RETURN_NONE; } -static PyObject * -PyRendererAgg_draw_gouraud_triangle(PyRendererAgg *self, PyObject *args) -{ - GCAgg gc; - numpy::array_view points; - numpy::array_view colors; - agg::trans_affine trans; - - if (!PyArg_ParseTuple(args, - "O&O&O&O&|O:draw_gouraud_triangle", - &convert_gcagg, - &gc, - &points.converter, - &points, - &colors.converter, - &colors, - &convert_trans_affine, - &trans)) { - return NULL; - } - - if (points.dim(0) != 3 || points.dim(1) != 2) { - PyErr_Format(PyExc_ValueError, - "points must be a 3x2 array, got %" NPY_INTP_FMT "x%" NPY_INTP_FMT, - points.dim(0), points.dim(1)); - return NULL; - } - - if (colors.dim(0) != 3 || colors.dim(1) != 4) { - PyErr_Format(PyExc_ValueError, - "colors must be a 3x4 array, got %" NPY_INTP_FMT "x%" NPY_INTP_FMT, - colors.dim(0), colors.dim(1)); - return NULL; - } - - - CALL_CPP("draw_gouraud_triangle", (self->x->draw_gouraud_triangle(gc, points, colors, trans))); - - Py_RETURN_NONE; -} - static PyObject * PyRendererAgg_draw_gouraud_triangles(PyRendererAgg *self, PyObject *args) { @@ -594,7 +553,6 @@ static PyTypeObject *PyRendererAgg_init_type() {"draw_image", (PyCFunction)PyRendererAgg_draw_image, METH_VARARGS, NULL}, {"draw_path_collection", (PyCFunction)PyRendererAgg_draw_path_collection, METH_VARARGS, NULL}, {"draw_quad_mesh", (PyCFunction)PyRendererAgg_draw_quad_mesh, METH_VARARGS, NULL}, - {"draw_gouraud_triangle", (PyCFunction)PyRendererAgg_draw_gouraud_triangle, METH_VARARGS, NULL}, {"draw_gouraud_triangles", (PyCFunction)PyRendererAgg_draw_gouraud_triangles, METH_VARARGS, NULL}, {"clear", (PyCFunction)PyRendererAgg_clear, METH_NOARGS, NULL},