Skip to content

Make draw_gouraud_triangle optional and remove unused versions #23820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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):
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,6 @@ class RendererAgg
bool antialiased,
ColorArray &edgecolors);

template <class PointArray, class ColorArray>
void draw_gouraud_triangle(GCAgg &gc,
PointArray &points,
ColorArray &colors,
agg::trans_affine &trans);

template <class PointArray, class ColorArray>
void draw_gouraud_triangles(GCAgg &gc,
PointArray &points,
Expand Down Expand Up @@ -1223,20 +1217,6 @@ inline void RendererAgg::_draw_gouraud_triangle(PointArray &points,
}
}

template <class PointArray, class ColorArray>
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 <class PointArray, class ColorArray>
inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc,
PointArray &points,
Expand Down
42 changes: 0 additions & 42 deletions src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const double, 2> points;
numpy::array_view<const double, 2> 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)
{
Expand Down Expand Up @@ -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},
Expand Down