Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8952d14

Browse files
authored
Merge pull request #26797 from oscargus/removedrawgouraudtriangle
Remove deprecated draw_gouraud_triangle
2 parents 5469134 + 819e173 commit 8952d14

File tree

9 files changed

+54
-141
lines changed

9 files changed

+54
-141
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
``draw_gouraud_triangle``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... is removed. Use `~.RendererBase.draw_gouraud_triangles` instead.
5+
6+
A ``draw_gouraud_triangle`` call in a custom `~matplotlib.artist.Artist` can readily be
7+
replaced as::
8+
9+
self.draw_gouraud_triangles(gc, points.reshape((1, 3, 2)),
10+
colors.reshape((1, 3, 4)), trans)
11+
12+
A `~.RendererBase.draw_gouraud_triangles` method can be implemented from an
13+
existing ``draw_gouraud_triangle`` method as::
14+
15+
transform = transform.frozen()
16+
for tri, col in zip(triangles_array, colors_array):
17+
self.draw_gouraud_triangle(gc, tri, col, transform)

lib/matplotlib/backend_bases.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -292,24 +292,6 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
292292
gc, master_transform, paths, [], offsets, offsetTrans, facecolors,
293293
edgecolors, linewidths, [], [antialiased], [None], 'screen')
294294

295-
@_api.deprecated("3.7", alternative="draw_gouraud_triangles")
296-
def draw_gouraud_triangle(self, gc, points, colors, transform):
297-
"""
298-
Draw a Gouraud-shaded triangle.
299-
300-
Parameters
301-
----------
302-
gc : `.GraphicsContextBase`
303-
The graphics context.
304-
points : (3, 2) array-like
305-
Array of (x, y) points for the triangle.
306-
colors : (3, 4) array-like
307-
RGBA colors for each point of the triangle.
308-
transform : `~matplotlib.transforms.Transform`
309-
An affine transform to apply to the points.
310-
"""
311-
raise NotImplementedError
312-
313295
def draw_gouraud_triangles(self, gc, triangles_array, colors_array,
314296
transform):
315297
"""

lib/matplotlib/backend_bases.pyi

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ class RendererBase:
7777
antialiased: bool,
7878
edgecolors: Sequence[ColorType] | ColorType | None,
7979
) -> None: ...
80-
def draw_gouraud_triangle(
81-
self,
82-
gc: GraphicsContextBase,
83-
points: ArrayLike,
84-
colors: ArrayLike,
85-
transform: Transform,
86-
) -> None: ...
8780
def draw_gouraud_triangles(
8881
self,
8982
gc: GraphicsContextBase,

lib/matplotlib/backends/backend_agg.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def __setstate__(self, state):
8484
self.__init__(state['width'], state['height'], state['dpi'])
8585

8686
def _update_methods(self):
87-
self.draw_gouraud_triangle = self._renderer.draw_gouraud_triangle
8887
self.draw_gouraud_triangles = self._renderer.draw_gouraud_triangles
8988
self.draw_image = self._renderer.draw_image
9089
self.draw_markers = self._renderer.draw_markers

lib/matplotlib/backends/backend_pdf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,10 +2132,6 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans,
21322132
lastx, lasty = x, y
21332133
output(Op.grestore)
21342134

2135-
def draw_gouraud_triangle(self, gc, points, colors, trans):
2136-
self.draw_gouraud_triangles(gc, points.reshape((1, 3, 2)),
2137-
colors.reshape((1, 3, 4)), trans)
2138-
21392135
def draw_gouraud_triangles(self, gc, points, colors, trans):
21402136
assert len(points) == len(colors)
21412137
if len(points) == 0:

lib/matplotlib/backends/backend_ps.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,6 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
691691
self._pswriter.write(f"{ox} {oy} {w} {h} rectfill\n")
692692
self._pswriter.write("grestore\n")
693693

694-
@_log_if_debug_on
695-
def draw_gouraud_triangle(self, gc, points, colors, trans):
696-
self.draw_gouraud_triangles(gc, points.reshape((1, 3, 2)),
697-
colors.reshape((1, 3, 4)), trans)
698-
699694
@_log_if_debug_on
700695
def draw_gouraud_triangles(self, gc, points, colors, trans):
701696
assert len(points) == len(colors)

lib/matplotlib/backends/backend_svg.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
770770

771771
self._path_collection_id += 1
772772

773-
def draw_gouraud_triangle(self, gc, points, colors, trans):
774-
# docstring inherited
775-
self._draw_gouraud_triangle(gc, points, colors, trans)
776-
777-
def _draw_gouraud_triangle(self, gc, points, colors, trans):
773+
def _draw_gouraud_triangle(self, transformed_points, colors):
778774
# This uses a method described here:
779775
#
780776
# http://www.svgopen.org/2005/papers/Converting3DFaceToSVG/index.html
@@ -786,43 +782,17 @@ def _draw_gouraud_triangle(self, gc, points, colors, trans):
786782
# opposite edge. Underlying these three gradients is a solid
787783
# triangle whose color is the average of all three points.
788784

789-
writer = self.writer
790-
if not self._has_gouraud:
791-
self._has_gouraud = True
792-
writer.start(
793-
'filter',
794-
id='colorAdd')
795-
writer.element(
796-
'feComposite',
797-
attrib={'in': 'SourceGraphic'},
798-
in2='BackgroundImage',
799-
operator='arithmetic',
800-
k2="1", k3="1")
801-
writer.end('filter')
802-
# feColorMatrix filter to correct opacity
803-
writer.start(
804-
'filter',
805-
id='colorMat')
806-
writer.element(
807-
'feColorMatrix',
808-
attrib={'type': 'matrix'},
809-
values='1 0 0 0 0 \n0 1 0 0 0 \n0 0 1 0 0' +
810-
' \n1 1 1 1 0 \n0 0 0 0 1 ')
811-
writer.end('filter')
812-
813785
avg_color = np.average(colors, axis=0)
814786
if avg_color[-1] == 0:
815787
# Skip fully-transparent triangles
816788
return
817789

818-
trans_and_flip = self._make_flip_transform(trans)
819-
tpoints = trans_and_flip.transform(points)
820-
790+
writer = self.writer
821791
writer.start('defs')
822792
for i in range(3):
823-
x1, y1 = tpoints[i]
824-
x2, y2 = tpoints[(i + 1) % 3]
825-
x3, y3 = tpoints[(i + 2) % 3]
793+
x1, y1 = transformed_points[i]
794+
x2, y2 = transformed_points[(i + 1) % 3]
795+
x3, y3 = transformed_points[(i + 2) % 3]
826796
rgba_color = colors[i]
827797

828798
if x2 == x3:
@@ -862,9 +832,9 @@ def _draw_gouraud_triangle(self, gc, points, colors, trans):
862832
writer.end('defs')
863833

864834
# triangle formation using "path"
865-
dpath = "M " + _short_float_fmt(x1)+',' + _short_float_fmt(y1)
866-
dpath += " L " + _short_float_fmt(x2) + ',' + _short_float_fmt(y2)
867-
dpath += " " + _short_float_fmt(x3) + ',' + _short_float_fmt(y3) + " Z"
835+
dpath = (f"M {_short_float_fmt(x1)},{_short_float_fmt(y1)}"
836+
f" L {_short_float_fmt(x2)},{_short_float_fmt(y2)}"
837+
f" {_short_float_fmt(x3)},{_short_float_fmt(y3)} Z")
868838

869839
writer.element(
870840
'path',
@@ -906,11 +876,36 @@ def _draw_gouraud_triangle(self, gc, points, colors, trans):
906876

907877
def draw_gouraud_triangles(self, gc, triangles_array, colors_array,
908878
transform):
909-
self.writer.start('g', **self._get_clip_attrs(gc))
879+
writer = self.writer
880+
writer.start('g', **self._get_clip_attrs(gc))
910881
transform = transform.frozen()
911-
for tri, col in zip(triangles_array, colors_array):
912-
self._draw_gouraud_triangle(gc, tri, col, transform)
913-
self.writer.end('g')
882+
trans_and_flip = self._make_flip_transform(transform)
883+
884+
if not self._has_gouraud:
885+
self._has_gouraud = True
886+
writer.start(
887+
'filter',
888+
id='colorAdd')
889+
writer.element(
890+
'feComposite',
891+
attrib={'in': 'SourceGraphic'},
892+
in2='BackgroundImage',
893+
operator='arithmetic',
894+
k2="1", k3="1")
895+
writer.end('filter')
896+
# feColorMatrix filter to correct opacity
897+
writer.start(
898+
'filter',
899+
id='colorMat')
900+
writer.element(
901+
'feColorMatrix',
902+
attrib={'type': 'matrix'},
903+
values='1 0 0 0 0 \n0 1 0 0 0 \n0 0 1 0 0 \n1 1 1 1 0 \n0 0 0 0 1 ')
904+
writer.end('filter')
905+
906+
for points, colors in zip(triangles_array, colors_array):
907+
self._draw_gouraud_triangle(trans_and_flip.transform(points), colors)
908+
writer.end('g')
914909

915910
def option_scale_image(self):
916911
# docstring inherited

src/_backend_agg.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,6 @@ class RendererAgg
190190
bool antialiased,
191191
ColorArray &edgecolors);
192192

193-
template <class PointArray, class ColorArray>
194-
void draw_gouraud_triangle(GCAgg &gc,
195-
PointArray &points,
196-
ColorArray &colors,
197-
agg::trans_affine &trans);
198-
199193
template <class PointArray, class ColorArray>
200194
void draw_gouraud_triangles(GCAgg &gc,
201195
PointArray &points,
@@ -1229,20 +1223,6 @@ inline void RendererAgg::_draw_gouraud_triangle(PointArray &points,
12291223
}
12301224
}
12311225

1232-
template <class PointArray, class ColorArray>
1233-
inline void RendererAgg::draw_gouraud_triangle(GCAgg &gc,
1234-
PointArray &points,
1235-
ColorArray &colors,
1236-
agg::trans_affine &trans)
1237-
{
1238-
theRasterizer.reset_clipping();
1239-
rendererBase.reset_clipping(true);
1240-
set_clipbox(gc.cliprect, theRasterizer);
1241-
bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans, gc.snap_mode);
1242-
1243-
_draw_gouraud_triangle(points, colors, trans, has_clippath);
1244-
}
1245-
12461226
template <class PointArray, class ColorArray>
12471227
inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc,
12481228
PointArray &points,

src/_backend_agg_wrapper.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -436,49 +436,6 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg
436436
Py_RETURN_NONE;
437437
}
438438

439-
static PyObject *
440-
PyRendererAgg_draw_gouraud_triangle(PyRendererAgg *self, PyObject *args)
441-
{
442-
GCAgg gc;
443-
numpy::array_view<const double, 2> points;
444-
numpy::array_view<const double, 2> colors;
445-
agg::trans_affine trans;
446-
447-
if (!PyArg_ParseTuple(args,
448-
"O&O&O&O&|O:draw_gouraud_triangle",
449-
&convert_gcagg,
450-
&gc,
451-
&points.converter,
452-
&points,
453-
&colors.converter,
454-
&colors,
455-
&convert_trans_affine,
456-
&trans)) {
457-
return NULL;
458-
}
459-
460-
if (points.dim(0) != 3 || points.dim(1) != 2) {
461-
PyErr_Format(PyExc_ValueError,
462-
"points must have shape (3, 2), "
463-
"got (%" NPY_INTP_FMT ", %" NPY_INTP_FMT ")",
464-
points.dim(0), points.dim(1));
465-
return NULL;
466-
}
467-
468-
if (colors.dim(0) != 3 || colors.dim(1) != 4) {
469-
PyErr_Format(PyExc_ValueError,
470-
"colors must have shape (3, 4), "
471-
"got (%" NPY_INTP_FMT ", %" NPY_INTP_FMT ")",
472-
colors.dim(0), colors.dim(1));
473-
return NULL;
474-
}
475-
476-
477-
CALL_CPP("draw_gouraud_triangle", (self->x->draw_gouraud_triangle(gc, points, colors, trans)));
478-
479-
Py_RETURN_NONE;
480-
}
481-
482439
static PyObject *
483440
PyRendererAgg_draw_gouraud_triangles(PyRendererAgg *self, PyObject *args)
484441
{
@@ -603,7 +560,6 @@ static PyTypeObject *PyRendererAgg_init_type()
603560
{"draw_image", (PyCFunction)PyRendererAgg_draw_image, METH_VARARGS, NULL},
604561
{"draw_path_collection", (PyCFunction)PyRendererAgg_draw_path_collection, METH_VARARGS, NULL},
605562
{"draw_quad_mesh", (PyCFunction)PyRendererAgg_draw_quad_mesh, METH_VARARGS, NULL},
606-
{"draw_gouraud_triangle", (PyCFunction)PyRendererAgg_draw_gouraud_triangle, METH_VARARGS, NULL},
607563
{"draw_gouraud_triangles", (PyCFunction)PyRendererAgg_draw_gouraud_triangles, METH_VARARGS, NULL},
608564

609565
{"clear", (PyCFunction)PyRendererAgg_clear, METH_NOARGS, NULL},

0 commit comments

Comments
 (0)