55from array import array
66from math import sqrt
77
8- from .shapes import ColoredGeometry
8+ from .shapes import SizedGeometry
99from .util import line_points , intersect_poly_rect
1010
1111
12- class WideLines (ColoredGeometry ):
12+ class WideLines (SizedGeometry ):
1313 """Render multiple colored line segments with variable width.
1414
1515 Geometry should produce x0, y0, x1, y1, width arrays.
1616 """
1717
18- def __init__ (self , geometry , colors , * , round = True , surface = None , clip = None ):
19- super ().__init__ (geometry , colors , surface = surface , clip = clip )
18+ def __init__ (self , geometry , colors , sizes , * , round = True , surface = None , clip = None ):
19+ super ().__init__ (geometry , colors , sizes , surface = surface , clip = clip )
2020 self .round = round
2121
2222 def draw_raster (self , raster ):
@@ -27,8 +27,7 @@ def draw_raster(self, raster):
2727 h = raster .h
2828 vertices = array ("h" , bytearray (16 ))
2929 should_round = self .round
30- for geometry , color in self :
31- lw = geometry [4 ]
30+ for geometry , color , lw in self :
3231 if intersect_poly_rect (geometry [:4 ], 4 , x - lw , y - lw , w + 2 * lw , h + 2 * lw ):
3332 x0 = geometry [0 ]
3433 y0 = geometry [1 ]
@@ -50,19 +49,17 @@ def _get_bounds(self):
5049 min_x = 0x7FFF
5150 max_y = - 0x7FFF
5251 min_y = 0x7FFF
53- for geometry in self .geometry :
54- max_x = max (max_x , geometry [0 ] + geometry [ 4 ] , geometry [2 ] + geometry [ 4 ] )
55- min_x = min (min_x , geometry [0 ] - geometry [ 4 ] , geometry [2 ] - geometry [ 4 ] )
56- max_y = max (max_y , geometry [1 ] + geometry [ 4 ] , geometry [3 ] + geometry [ 4 ] )
57- min_y = min (min_y , geometry [1 ] - geometry [ 4 ] , geometry [3 ] - geometry [ 4 ] )
52+ for geometry , w in zip ( self .geometry , self . sizes ) :
53+ max_x = max (max_x , geometry [0 ] + w , geometry [2 ] + w )
54+ min_x = min (min_x , geometry [0 ] - w , geometry [2 ] - w )
55+ max_y = max (max_y , geometry [1 ] + w , geometry [3 ] + w )
56+ min_y = min (min_y , geometry [1 ] - w , geometry [3 ] - w )
5857
5958 return (min_x , min_y , max_x - min_x , max_y - min_y )
6059
6160
62- class WidePolyLines (ColoredGeometry ):
61+ class WidePolyLines (SizedGeometry ):
6362 """Render multiple colored polylines with variable width.
64-
65- Geometry should produce array of [x0, y0, x1, y1, ...] and width.
6663 """
6764
6865 def draw_raster (self , raster ):
@@ -72,9 +69,7 @@ def draw_raster(self, raster):
7269 w = raster .w
7370 h = raster .h
7471 vertices = array ("h" , bytearray (16 ))
75- for geometry , color in self :
76- lw = geometry [- 1 ]
77- lines = geometry [:- 1 ]
72+ for lines , color , lw in self :
7873 if intersect_poly_rect (lines , len (lines ), x - lw , y - lw , w + 2 * lw , h + 2 * lw ):
7974 for i in range (0 , len (lines ) - 2 , 2 ):
8075 x0 = lines [i ]
@@ -99,9 +94,7 @@ def _get_bounds(self):
9994 min_x = 0x7FFF
10095 max_y = - 0x7FFF
10196 min_y = 0x7FFF
102- for geometry in self .geometry :
103- w = geometry [- 1 ]
104- lines = geometry [:- 1 ]
97+ for lines , w in zip (self .geometry , self .sizes ):
10598 for i in range (0 , len (lines ), 2 ):
10699 max_x = max (max_x , lines [i ] + w )
107100 min_x = min (min_x , lines [i ] - w )
0 commit comments