Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add __hash__ to ManimColor (#4051)

Sophia Wisdom86a971940fd7
diff --git a/manim/utils/color/core.py b/manim/utils/color/core.py
index d742dbb33..28896abde 100644
--- a/manim/utils/color/core.py
+++ b/manim/utils/color/core.py
@@ -1030,6 +1030,9 @@ class ManimColor:
self._internal_from_integer(self.to_integer() ^ int(other), 1.0)
)
+ def __hash__(self) -> int:
+ return hash(self.to_hex(with_alpha=True))
+
RGBA = ManimColor
"""RGBA Color Space"""
diff --git a/tests/module/utils/test_color.py b/tests/module/utils/test_color.py
index c3d468328..602f56460 100644
--- a/tests/module/utils/test_color.py
+++ b/tests/module/utils/test_color.py
@@ -2,7 +2,7 @@ from __future__ import annotations
import numpy as np
-from manim import BLACK, Mobject, Scene, VMobject
+from manim import BLACK, RED, WHITE, ManimColor, Mobject, Scene, VMobject
def test_import_color():
@@ -49,3 +49,9 @@ def test_set_color():
assert m.color.to_hex() == "#FFFFFF"
m.set_color(BLACK)
assert m.color.to_hex() == "#000000"
+
+
+def test_color_hash():
+ assert hash(WHITE) == hash(ManimColor([1.0, 1.0, 1.0, 1.0]))
+ assert hash(WHITE) == hash("#FFFFFFFF")
+ assert hash(WHITE) != hash(RED)