@@ -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 \n 0 1 0 0 0 \n 0 0 1 0 0' +
810- ' \n 1 1 1 1 0 \n 0 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 \n 0 1 0 0 0 \n 0 0 1 0 0 \n 1 1 1 1 0 \n 0 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
0 commit comments