Return whether the colors *c1* and *c2* are the same. *c1*, *c2* can be single colors or lists/arrays of colors.
(c1, c2)
| 285 | |
| 286 | |
| 287 | def same_color(c1, c2): |
| 288 | """ |
| 289 | Return whether the colors *c1* and *c2* are the same. |
| 290 | |
| 291 | *c1*, *c2* can be single colors or lists/arrays of colors. |
| 292 | """ |
| 293 | c1 = to_rgba_array(c1) |
| 294 | c2 = to_rgba_array(c2) |
| 295 | n1 = max(c1.shape[0], 1) # 'none' results in shape (0, 4), but is 1-elem |
| 296 | n2 = max(c2.shape[0], 1) # 'none' results in shape (0, 4), but is 1-elem |
| 297 | |
| 298 | if n1 != n2: |
| 299 | raise ValueError('Different number of elements passed.') |
| 300 | # The following shape test is needed to correctly handle comparisons with |
| 301 | # 'none', which results in a shape (0, 4) array and thus cannot be tested |
| 302 | # via value comparison. |
| 303 | return c1.shape == c2.shape and (c1 == c2).all() |
| 304 | |
| 305 | |
| 306 | def to_rgba(c, alpha=None): |
searching dependent graphs…