Skip to content
Snippets Groups Projects
Commit 363aa062 authored by Ethan White's avatar Ethan White
Browse files

feat: add __len__ to ColorPalette

For downstream use being able to determine how many colors are in a
ColorPalette object can be useful. E.g., checking if a user has provided
a color palette that matches the number of labels. ColorPalette doesn't
currenly have a __len__ attribute meaning that `mypalette.colors` has
to be used for calculating lengths. This change adds __len__ to make
this more intutitive by allowing `len(mypalette)`.
parent e63611de
No related merge requests found
......@@ -397,6 +397,15 @@ class ColorPalette:
idx = idx % len(self.colors)
return self.colors[idx]
def __len__(self) -> int:
"""
Returns the number of colors in the palette.
Returns:
int: The number of colors.
"""
return len(self.colors)
def unify_to_bgr(color: Union[Tuple[int, int, int], Color]) -> Tuple[int, int, int]:
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment