zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
U
T±d…›ã@sšddlZddlZddlZddlmZmZddlmZGdd„dƒZddd„Z    z ej
j Z Wne k
rpdZ YnXdd    d
„Zdd d „Zd d„Zdd„ZdS)éNé)ÚImageÚ
ImageColor)Ú    deprecatec @seZdZdZd:dd„Zdd„Zd;dd„Zd<d    d
„Zd=d d „Zd>d d„Z    d?dd„Z
d@dd„Z dAdd„Z dBdd„Z dCdd„ZdDdd„ZdEdd„ZdFdd„ZdGdd œd!d"„Zd#d$„Zd%d&„Zd'd(„ZdHd,d-„ZdId.d/„ZdJd0d1„ZdKd2d3„ZdLd4d5„ZdMd6d7„ZdNd8d9„ZdS)OÚ    ImageDrawNcCsÚ| ¡|jr| ¡d}|dkr(|j}||jkrV|dkrJ|jdkrJd}n d}t|ƒ‚|dkrh|j|_nd|_||_|j|_tj     
|j|¡|_
||_|dkr¬|j
  d¡|_ n|j
  d    ¡|_ |d
krÊd |_ nd |_ d |_dS)a˜
        Create a drawing instance.
 
        :param im: The image to draw in.
        :param mode: Optional mode to use for color values.  For RGB
           images, this argument can be RGB or RGBA (to blend the
           drawing into the image).  For all other modes, this argument
           must be the same as the image mode.  If omitted, the mode
           defaults to the mode of the image.
        rNÚRGBAÚRGBrz mode mismatchÚP)ÚIÚFéÿÿÿÿ)Ú1r    r
r r ÚLF)ÚloadÚreadonlyZ_copyÚmodeÚ
ValueErrorÚpaletteÚ_imageÚimrÚcoreÚdrawÚdraw_inkÚinkÚfontmodeÚfill)ÚselfrrZblendÚmsg©rúDd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PIL/ImageDraw.pyÚ__init__3s2 
 
zImageDraw.__init__cCs"|jsddlm}| ¡|_|jS)a=
        Get the current default font.
 
        To set the default font for this ImageDraw instance::
 
            from PIL import ImageDraw, ImageFont
            draw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
 
        To set the default font for all future ImageDraw instances::
 
            from PIL import ImageDraw, ImageFont
            ImageDraw.ImageDraw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
 
        If the current default font is ``None``,
        it is initialized with ``ImageFont.load_default()``.
 
        :returns: An image font.r)Ú    ImageFont)ÚfontÚr!Z load_default)rr!rrrÚgetfont]s 
zImageDraw.getfontcCsÊ|dkr&|dkr&|jr|j}qÂ|j}nœ|dk    rtt|tƒrFt ||j¡}|jrht|tj    ƒsh|j ||j
¡}|j   |¡}|dk    rÂt|tƒr”t ||j¡}|jr¶t|tj    ƒs¶|j ||j
¡}|j   |¡}||fS©N) rrÚ
isinstanceÚstrrZgetcolorrrÚnumbersÚNumberrrr)rrrrrrÚ_getinkvs"
 
 zImageDraw._getinkrcCs.| |¡\}}|dk    r*|j |||||¡dS)z Draw an arc.N)r*rÚdraw_arc)rÚxyÚstartÚendrÚwidthrrrrÚarc‹sz ImageDraw.arccCs@| ¡| |¡\}}|dkr"|}|dk    r<|j ||j|¡dS)zDraw a bitmap.N)rr*rÚ draw_bitmapr)rr,Úbitmaprrrrrr2‘s zImageDraw.bitmapcCs^| ||¡\}}|dk    r,|j ||||d¡|dk    rZ||krZ|dkrZ|j ||||d|¡dS)z Draw a chord.Nrr)r*rZ
draw_chord©rr,r-r.rÚoutliner/rrrrÚchordšs
zImageDraw.chordcCsV| ||¡\}}|dk    r(|j ||d¡|dk    rR||krR|dkrR|j ||d|¡dS)zDraw an ellipse.Nrr)r*rZ draw_ellipse©rr,rr4r/rrrrÚellipse¢s
zImageDraw.ellipsercs6| |¡d}|dk    r2|j ˆ|ˆ¡|dkr2ˆdkr2tˆdttfƒsl‡fdd„tdtˆƒdƒDƒ‰tdtˆƒdƒD]°}ˆ|}d    d„ˆ|d|f|ˆ|dffDƒ}|d|dkrÈq~‡fd
d „}    |d|dkrú|dd |dkp|d|dko|dd |dk}
|dˆdd|dˆddf|dˆdd|dˆddfg} |
r’|dd |dd } } n|dd |dd } } | | | d | d |¡ˆdkr~|
rú|    ||dd ƒ||    ||dd ƒg}n&|    ||dd ƒ||    ||dd ƒg}|j    ||ddq~dS)z6Draw a line, or a connected sequence of line segments.rNZcurveécs g|]}tˆ||d…ƒ‘qS)é)Útuple©Ú.0Úi)r,rrÚ
<listcomp>±sz"ImageDraw.line.<locals>.<listcomp>r9rc
Ss>g|]6\}}t t |d|d|d|d¡¡d‘qS)rréh)ÚmathÚdegreesÚatan2)r<r-r.rrrr>´sþ(ÿc
sZ|\}}|d8}ˆdd}tdd„||t t |¡¡f||t t |¡¡ffDƒƒS)NéZr9rcss2|]*\}}||dkrt |¡nt |¡VqdS)rN)r@ÚfloorÚceil)r<ÚpZp_drrrÚ    <genexpr>Ásÿz9ImageDraw.line.<locals>.coord_at_angle.<locals>.<genexpr>)r:r@ÚcosÚradiansÚsin)ÚcoordÚangleÚxÚyZdistance©r/rrÚcoord_at_angle½s þþz&ImageDraw.line.<locals>.coord_at_angleé´rCéérO)
r*rZ
draw_linesr&Úlistr:ÚrangeÚlenÚpiesliceÚline)rr,rr/Zjointrr=ÚpointÚanglesrPZflippedZcoordsr-r.Z
gap_coordsr)r/r,rrXªsH
ý "ÿ$þ&&þýýzImageDraw.linecCsT| ¡| ||¡\}}|dk    r0|j ||d¡|dk    rP||krP|j ||d¡dS)z(Experimental) Draw a shape.Nrr)Úcloser*rZ draw_outline)rÚshaperr4rrrrr\æs zImageDraw.shapecCs^| ||¡\}}|dk    r,|j ||||d¡|dk    rZ||krZ|dkrZ|j ||||d|¡dS)zDraw a pieslice.Nrr)r*rÚ draw_pieslicer3rrrrWïs
zImageDraw.pieslicecCs(| |¡\}}|dk    r$|j ||¡dS)z#Draw one or more individual pixels.N)r*rZ draw_points)rr,rrrrrrY÷szImageDraw.pointc Cs&| ||¡\}}|dk    r(|j ||d¡|dk    r"||kr"|dkr"|dkrb|j ||d|¡nÀt d|jj¡}| d¡d}| ¡}t|ƒ}    |    j ||d¡| ¡}
t|
ƒ}    |dd}|    j ||d|¡|j    |
|dt |j
|jj¡} t| ƒ}    |    j ||d|¡|j     | jd| j|j¡dS)zDraw a polygon.Nrrr r9)Úmask)rr) r*rZ draw_polygonrÚnewrÚsizeÚcopyÚDrawÚpaster) rr,rr4r/rr^Zmask_inkZfill_imrZink_imrrrrÚpolygonýs( zImageDraw.polygoncCst|||ƒ}| |||¡dS)zDraw a regular polygon.N)Ú!_compute_regular_polygon_verticesrd)rÚbounding_circleÚn_sidesÚrotationrr4r,rrrÚregular_polygons zImageDraw.regular_polygoncCsV| ||¡\}}|dk    r(|j ||d¡|dk    rR||krR|dkrR|j ||d|¡dS)zDraw a rectangle.Nrr)r*rÚdraw_rectangler6rrrÚ    rectangle"s
zImageDraw.rectangle)Úcornersc st|dttfƒr$|\\‰‰
\‰    ‰ n |\‰‰
‰    ‰ ˆ    ˆkrDd}t|ƒ‚ˆ ˆ
krXd}t|ƒ‚ˆdkrdd‰|d‰d\‰‰tˆƒrĈˆ    ˆk‰ˆr”ˆ    ˆ‰ˆˆ ˆ
k‰ˆr¬ˆ ˆ
‰ˆrĈrĈ |ˆ|ˆ¡SˆdksÔtˆƒs䈠|ˆ|ˆ¡Sˆd}ˆ |ˆ¡\‰‰‡‡‡‡‡‡‡‡‡‡    ‡
‡ f dd    „}    ˆdk    rL|    d
ƒˆr`ˆj     
ˆˆ
|d ˆ    ˆ |d fˆd ¡n(ˆj     
ˆ|d ˆ
ˆ    |d ˆ fˆd ¡ˆsLˆsLˆˆ
ˆ|ˆ g}
ˆdrÂ|
d |d 7<ˆd rà|
d |d 8<ˆj     
|
ˆd ¡ˆ    |ˆ
ˆ    ˆ g} ˆd r| d |d 7<ˆdr<| d |d 8<ˆj     
| ˆd ¡ˆdk    rþˆˆkrþˆdkrþ|    d ƒˆs8ˆˆ
ˆ    ˆ
ˆd g} ˆdrª| d|d 7<ˆd rÈ| d|d 8<ˆj     
| ˆd ¡ˆˆ ˆd ˆ    ˆ g} ˆd r
| d|d 7<ˆdr(| d|d 8<ˆj     
| ˆd ¡ˆsþˆˆ
ˆˆd ˆ g}
ˆdrp|
d |d 7<ˆd rŽ|
d |d 8<ˆj     
|
ˆd ¡ˆ    ˆd ˆ
ˆ    ˆ g} ˆd rÐ| d |d 7<ˆdrî| d |d 8<ˆj     
| ˆd ¡dS)zDraw a rounded rectangle.rz&x1 must be greater than or equal to x0z&y1 must be greater than or equal to y0N)TTTTr9)FFcs<ˆr:ˆˆ
ˆˆˆ
ˆfddfˆˆ ˆˆˆˆ fddff}nˆrtˆˆ
ˆˆˆ
ˆfddfˆ    ˆˆ
ˆ    ˆ
ˆfddff}nˆg}tˆˆ
ˆˆˆ
ˆfddfˆ    ˆˆ
ˆ    ˆ
ˆfddfˆ    ˆˆ ˆˆ    ˆ fddfˆˆ ˆˆˆˆ fddffƒD]\}}ˆ|rà| |¡qà|D]6}|r ˆjj|ˆdfŽnˆjj|ˆˆfސqdS)NrQr?rrCér)Ú    enumerateÚappendrr]r+)rWÚpartsr=Úpart© rlÚdrZfull_xZfull_yrrr/Zx0Úx1Zy0Úy1rrÚ draw_cornersTs,þþüÿ  z1ImageDraw.rounded_rectangle.<locals>.draw_cornersTrrSF) r&rTr:rÚallr7Úanyrkr*rrj)rr,Zradiusrr4r/rlrÚrrvÚleftÚrightÚtopÚbottomrrrrÚrounded_rectangle*s’   " 
*( 
 
 
 
 
 
 
 
 
 
 
 
zImageDraw.rounded_rectanglecCst|tƒrdnd}||kS©NÚ
ó
)r&r'©rÚtextZsplit_characterrrrÚ_multiline_check©szImageDraw._multiline_checkcCst|tƒrdnd}| |¡Sr)r&r'Úsplitr‚rrrÚ_multiline_split®szImageDraw._multiline_splitc
CsFt ¡4tjdtd|jd||dd|W5QR£SQRXdS)NÚignore©ÚcategoryÚA)r"Ú stroke_widthr)ÚwarningsÚcatch_warningsÚfilterwarningsÚDeprecationWarningÚtextsize)rr"Úspacingr‹rrrÚ_multiline_spacing³s
ýüûÿzImageDraw._multiline_spacingr8rzFcsڈ ˆ    ¡r,ˆ ˆ
ˆ    |ˆˆ||ˆˆˆ| | ˆ¡ SˆrFˆjdkrFd}t|ƒ‚ˆdkrVˆ ¡‰‡fdd„}d    ‡‡‡‡‡‡‡‡‡‡    ‡
f dd„    }||ƒ}|dk    rÖd}| r°| dk    r¬|| ƒn|}|dk    rÎ||| ƒ||dƒn||ƒdS)
z
Draw text.©rrú3Embedded color supported only in RGB and RGBA modesNcsˆ |¡\}}|dkr|S|Sr%)r*)rr)rrrÚgetinkëszImageDraw.text.<locals>.getinkrc sªˆj}|dkrˆrd}g}g}tdƒD].}| tˆ
|ƒ¡| t ˆ
|¡d¡q&zPˆjˆ    |fˆžˆˆˆ|ˆ||dœˆ—Ž\}}|d|d|d|df}Wndtk
r
z,ˆjˆ    |ˆˆˆ|ˆ|fˆžd|iˆ—Ž}Wn t    k
rˆ ˆ    ¡}YnXYnX|r2|d|d|d|df}|dkr–|| 
d¡}    }|      d|d?d    @¡|\}
} ˆj   |    |
| |
|jd| |jdf|¡nˆj |||¡dS)
Nrrr9)Ú    directionÚfeaturesÚlanguager‹Úanchorrr-rr-rSééÿ)rrUroÚintr@ÚmodfZgetmask2ÚAttributeErrorZgetmaskÚ    TypeErrorZgetbandZfillbandrrcr`rr1) rr‹Z stroke_offsetrrKr-r=r^ÚoffsetÚcolorrMrN© r™Úargsr–Úembedded_colorr—r"Úkwargsr˜rrƒr,rrÚ    draw_textñsl  þ
ö÷ õ
$ø
ö    ÷ õ
 
.z!ImageDraw.text.<locals>.draw_text)rN)r„Úmultiline_textrrr$)rr,rƒrr"r™r‘Úalignr–r—r˜r‹Ú stroke_fillr¤r£r¥rr•r¦rZ
stroke_inkrr¢rrƒÀs@
ó "5
 zImageDraw.textcCsÀ|dkrd}t|ƒ‚|dkr"d}n2t|ƒdkr<d}t|ƒ‚n|ddkrTd}t|ƒ‚g}d    }| |¡}| ||| ¡}|D],}|j||||    |
d
}| |¡t||ƒ}qx|d}|dd krÔ|t|ƒd|d 8}n |dd krô|t|ƒd|8}t|ƒD]¾\}}|d    }|||}|d    d kr4||d 8}n|d    dkrJ||8}|dkrVn8|dkrn||d 7}n |dkr‚||7}n d}t|ƒ‚|j||f||||||    |
| | | d ||7}qüdS)NÚttbú/ttb direction is unsupported for multiline textÚlar9ú#anchor must be a 2 character stringrÚtbú'anchor not supported for multiline textr©r–r—r˜Úmç@rsryrzÚcenterr{ú)align must be "left", "center" or "right")r–r—r˜r‹r©r¤)    rrVr†r’Ú
textlengthroÚmaxrnrƒ)rr,rƒrr"r™r‘r¨r–r—r˜r‹r©r¤rÚwidthsÚ    max_widthÚlinesÚ line_spacingrXÚ
line_widthr|ÚidxrzÚwidth_differencerrrr§6sv 
 
ÿ
 
 
 
 
õ zImageDraw.multiline_textc
Cs¦tdddƒ| |¡rVt ¡2tjdtd| |||||||¡W5QR£SQRX|dkrf| ¡}t ¡.tjdtd| |||||¡W5QR£SQRXdS)z*Get the size of a given string, in pixels.ré
ztextbbox or textlengthr‡rˆN)    rr„rŒrrŽrÚmultiline_textsizer$Úgetsize)rrƒr"r‘r–r—r˜r‹rrrrˆs0 
 
ù
 
ûzImageDraw.textsizec CsŒtdddƒd}| |¡}    | |||¡}
t ¡Btjdtd|    D](} | | ||||||¡\} } t|| ƒ}qDW5QRX|t    |    ƒ|
|fS)Nr¿r¾Úmultiline_textbboxrr‡rˆ)
rr†r’rŒrrŽrrr¶rV)rrƒr"r‘r–r—r˜r‹r¸r¹rºrXr»Z line_heightrrrr¿­s$
 
 
ù    zImageDraw.multiline_textsizec
CsØ| |¡rd}t|ƒ‚|r0|jdkr0d}t|ƒ‚|dkr@| ¡}|rHdn|j}z| |||||¡WStk
rÒtddƒt     ¡(tj
dt d    |j |||||d
}    W5QRX|d krÆ|    d YS|    d YSXdS)z@Get the length of a given string, in pixels with 1/64 precision.z&can't measure length of multiline textr“r”Nrz.textlength support for fonts without getlengthr¾r‡rˆr°rªrr) r„rrr$rZ    getlengthržrrŒrrŽrr)
rrƒr"r–r—r˜r¤rrr`rrrrµÊs2
 
 
 
û zImageDraw.textlengthc  Cs²| r|jdkrd} t| ƒ‚| |¡rB| |||||||||    |
| ¡ S|dkrR| ¡}| rZdn|j} | || |||    |
|¡}|d|d|d|d|d|d|d|dfS)    z2Get the bounding box of a given string, in pixels.r“r”Nrrrr9rS)rrr„rÁr$rZgetbbox)rr,rƒr"r™r‘r¨r–r—r˜r‹r¤rrÚbboxrrrÚtextbboxïs<
õÿzImageDraw.textbboxc  Cs@|dkrd} t| ƒ‚|dkr"d}n2t|ƒdkr<d} t| ƒ‚n|ddkrTd} t| ƒ‚g} d    }| |¡}| |||
¡}|D].}|j|||||    | d
}|  |¡t||ƒ}qx|d}|dd krÖ|t|ƒd|d 8}n |dd krö|t|ƒd|8}d}t|ƒD]\}}|d    }|| |}|d    d kr<||d 8}n|d    dkrR||8}|dkr^n8|dkrv||d 7}n |dkrŠ||7}n d} t| ƒ‚|j||f||||||    |
| d    }|dkrÆ|}nDt    |d    |d    ƒt    |d|dƒt|d|dƒt|d|dƒf}||7}q|dkr<|d    |d|d    |dfS|S)Nrªr«r¬r9r­rr®r¯r)r–r—r˜r¤r±r²rsryrzr³r{r´)r–r—r˜r‹r¤rS)
rrVr†r’rµror¶rnrÃÚmin)rr,rƒr"r™r‘r¨r–r—r˜r‹r¤rr·r¸r¹rºrXr»r|rÂr¼rzr½Z    bbox_linerrrrÁsŠ 
 
ú
 
 
 
 
÷
ü 
zImageDraw.multiline_textbbox)N)N)Nr)N)NNr)NNr)NrN)NN)NNr)N)NNr)rNN)NNr)rNNr) NNNr8rzNNNrNF) NNNr8rzNNNrNF)Nr8NNNr)Nr8NNNr)NNNNF)    NNr8rzNNNrF)    NNr8rzNNNrF)Ú__name__Ú
__module__Ú __qualname__r"r r$r*r0r2r5r7rXr\rWrYrdrirkr~r„r†r’rƒr§rr¿rµrÃrÁrrrrr0s¸
*
 
 
    
 
 
<
    
 
 
ÿ
 
    ÿÿ ò
zò
Uø
(ø
 ù
)ô
.ôrcCs0z | |¡WStk
r*t||ƒYSXdS)a‹
    A simple 2D drawing interface for PIL images.
 
    :param im: The image to draw in.
    :param mode: Optional mode to use for color values.  For RGB
       images, this argument can be RGB or RGBA (to blend the
       drawing into the image).  For all other modes, this argument
       must be the same as the image mode.  If omitted, the mode
       defaults to the mode of the image.
    N)Úgetdrawržr)rrrrrrb}s  rbcCs`d}|rd|kr6zddlm}Wntk
r4YnX|dkrJddlm}|rX| |¡}||fS)a
    (Experimental) A more advanced 2D drawing interface for PIL images,
    based on the WCK interface.
 
    :param im: The image to draw in.
    :param hints: An optional list of hints.
    :returns: A (drawing context, drawing resource factory) tuple.
    NZnicestr)Ú _imagingagg)Ú
ImageDraw2)r#rÉÚ ImportErrorrÊrb)rÚhintsÚhandlerrrrrȕs   
rÈc Csl| ¡}|\}}z0|||f}t||ƒ|kr2WdS||||f<Wnttfk
rZYdSX||fh}    tƒ}
|    rhtƒ} |    D]à\}}|d|f|d|f||df||dffD]ª\} } | | f|
ks°| dks°| dkrÖq°z|| | f}Wnttfk
rYq°X|
 | | f¡|dkr*t||ƒ|k}n||ko:||k}|r°||| | f<|  | | f¡q°q||    }
| }    qldS)aÏ
    (experimental) Fills a bounded region with a given color.
 
    :param image: Target image.
    :param xy: Seed position (a 2-item coordinate tuple). See
        :ref:`coordinate-system`.
    :param value: Fill color.
    :param border: Optional border value.  If given, the region consists of
        pixels with a color different from the border color.  If not given,
        the region consists of pixels having the same color as the seed
        pixel.
    :param thresh: Optional threshold value which specifies a maximum
        tolerable difference of a pixel value from the 'background' in
        order for it to be replaced. Useful for filling regions of
        non-homogeneous, but similar, colors.
    Nrr)rÚ _color_diffrÚ
IndexErrorÚsetÚadd)Úimager,ÚvalueZborderZthreshZpixelrMrNZ
backgroundZedgeZ    full_edgeZnew_edgeÚsÚtrFrrrrÚ    floodfill­s< 
 4
 rÖcs$t|tƒsd}t|ƒ‚|dkr*d}t|ƒ‚t|ttfƒsDd}t|ƒ‚t|ƒdkr\|^‰‰n"t|ƒdkrr|\‰‰n d}t|ƒ‚tdd„ˆˆf˜Dƒƒs¢d    }t|ƒ‚tˆƒdksºd
}t|ƒ‚ˆd krÎd }t|ƒ‚t|ttfƒsèd }t|ƒ‚dd„‰‡fdd„‰dd„}|||ƒ}‡‡‡fdd„|DƒS)uŽ
    Generate a list of vertices for a 2D regular polygon.
 
    :param bounding_circle: The bounding circle is a tuple defined
        by a point and radius. The polygon is inscribed in this circle.
        (e.g. ``bounding_circle=(x, y, r)`` or ``((x, y), r)``)
    :param n_sides: Number of sides
        (e.g. ``n_sides=3`` for a triangle, ``6`` for a hexagon)
    :param rotation: Apply an arbitrary rotation to the polygon
        (e.g. ``rotation=90``, applies a 90 degree rotation)
    :return: List of regular polygon vertices
        (e.g. ``[(25, 50), (50, 50), (50, 25), (25, 25)]``)
 
    How are the vertices computed?
    1. Compute the following variables
        - theta: Angle between the apothem & the nearest polygon vertex
        - side_length: Length of each polygon edge
        - centroid: Center of bounding circle (1st, 2nd elements of bounding_circle)
        - polygon_radius: Polygon radius (last element of bounding_circle)
        - angles: Location of each polygon vertex in polar grid
            (e.g. A square with 0 degree rotation => [225.0, 315.0, 45.0, 135.0])
 
    2. For each angle in angles, get the polygon vertex at that angle
        The vertex is computed using the equation below.
            X= xcos(φ) + ysin(φ)
            Y= âˆ’xsin(φ) + ycos(φ)
 
        Note:
            Ï† = angle in degrees
            x = 0
            y = polygon_radius
 
        The formula above assumes rotation around the origin.
        In our case, we are rotating around the centroid.
        To account for this, we use the formula below
            X = xcos(φ) + ysin(φ) + centroid_x
            Y = âˆ’xsin(φ) + ycos(φ) + centroid_y
    zn_sides should be an intrSzn_sides should be an int > 2z!bounding_circle should be a tupler9z[bounding_circle should contain 2D coordinates and a radius (e.g. (x, y, r) or ((x, y), r) )css|]}t|ttfƒVqdSr%)r&rœÚfloatr;rrrrG%sz4_compute_regular_polygon_vertices.<locals>.<genexpr>z0bounding_circle should only contain numeric datazBbounding_circle centre should contain 2D coordinates (e.g. (x, y))rz$bounding_circle radius should be > 0z"rotation should be an int or floatc
SsŒt|dt t d|¡¡|dt t d|¡¡|ddƒt|dt t d|¡¡|dt t d|¡¡|ddƒfS)Nrr?rr9)Úroundr@rHrIrJ)rYrAÚcentroidrrrÚ_apply_rotation7s"ÿþüÿþüùz:_compute_regular_polygon_vertices.<locals>._apply_rotationcs|dg}ˆ|||ƒS)Nrr)rÙÚpolygon_radiusrLZ start_point)rÚrrÚ_compute_polygon_vertexGszB_compute_regular_polygon_vertices.<locals>._compute_polygon_vertexcSsRg}d|}dd||}td|ƒD]&}| |¡||7}|dkr&|d8}q&|S)Nr?rmgà?r)rUro)rgrhrZrAZ current_angleÚ_rrrÚ _get_anglesKs
 
z6_compute_regular_polygon_vertices.<locals>._get_anglescsg|]}ˆˆˆ|ƒ‘qSrr)r<rL)rÜrÙrÛrrr>[sz5_compute_regular_polygon_vertices.<locals>.<listcomp>)    r&rœrŸrrTr:rVrwr×)rfrgrhrrÞrZr)rÚrÜrÙrÛrreåsF)
 
ÿ  
ÿrecs<tˆtƒr,t‡‡fdd„tdtˆƒƒDƒƒStˆˆƒSdS)zJ
    Uses 1-norm distance to calculate difference between two values.
    c3s"|]}tˆ|ˆ|ƒVqdSr%)Úabsr;©Zcolor1Zcolor2rrrGesz_color_diff.<locals>.<genexpr>rN)r&r:ÚsumrUrVrßràrràrrÎ`s
"rÎ)N)NN)Nr)r@r(rŒr#rrZ
_deprecaterrrbrr4ZOutlineržrÈrÖrerÎrrrrÚ<module>!s(
S
 
 
 
8{