From 9a6a86713399d80a446f227646fb951313660633 Mon Sep 17 00:00:00 2001 From: Sophia Wisdom Date: Sun, 8 Dec 2024 12:59:24 -0500 Subject: [PATCH 1/5] add __hash__ to ManimColor --- manim/utils/color/core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/manim/utils/color/core.py b/manim/utils/color/core.py index 23864921e0..9ea69f667c 100644 --- a/manim/utils/color/core.py +++ b/manim/utils/color/core.py @@ -1020,6 +1020,9 @@ def __xor__(self, other: Self) -> Self: return self._construct_from_space( self._internal_from_integer(self.to_integer() ^ int(other), 1.0) ) + + def __hash__(self) -> str: + return self.to_hex(with_alpha=True) RGBA = ManimColor From bec6983f0077aa4f7732fbba80779db656150b3f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Dec 2024 18:01:24 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/utils/color/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/utils/color/core.py b/manim/utils/color/core.py index 9ea69f667c..511c78d703 100644 --- a/manim/utils/color/core.py +++ b/manim/utils/color/core.py @@ -1020,7 +1020,7 @@ def __xor__(self, other: Self) -> Self: return self._construct_from_space( self._internal_from_integer(self.to_integer() ^ int(other), 1.0) ) - + def __hash__(self) -> str: return self.to_hex(with_alpha=True) From 92b8c451b2858a4cb1585c1004242b74f16ea53f Mon Sep 17 00:00:00 2001 From: Sophia Wisdom Date: Sun, 8 Dec 2024 13:15:12 -0500 Subject: [PATCH 3/5] Update core.py --- manim/utils/color/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/utils/color/core.py b/manim/utils/color/core.py index 511c78d703..c072d3b8d4 100644 --- a/manim/utils/color/core.py +++ b/manim/utils/color/core.py @@ -1022,7 +1022,7 @@ def __xor__(self, other: Self) -> Self: ) def __hash__(self) -> str: - return self.to_hex(with_alpha=True) + return hash(self.to_hex(with_alpha=True)) RGBA = ManimColor From 1492893b53a96152c3e47fa24b05710d4021d189 Mon Sep 17 00:00:00 2001 From: Sophia Wisdom Date: Sun, 8 Dec 2024 13:19:07 -0500 Subject: [PATCH 4/5] add test --- tests/module/utils/test_color.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/module/utils/test_color.py b/tests/module/utils/test_color.py index c3d468328b..b3acea74a9 100644 --- a/tests/module/utils/test_color.py +++ b/tests/module/utils/test_color.py @@ -2,7 +2,7 @@ import numpy as np -from manim import BLACK, Mobject, Scene, VMobject +from manim import BLACK, WHITE, RED, Mobject, Scene, VMobject def test_import_color(): @@ -49,3 +49,7 @@ 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(WHITE.copy()) + assert hash(WHITE) != hash(RED) From 98d65e1695123af0975e0844288e7df8c40970fe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Dec 2024 18:19:19 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/module/utils/test_color.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/module/utils/test_color.py b/tests/module/utils/test_color.py index b3acea74a9..6996f94ad4 100644 --- a/tests/module/utils/test_color.py +++ b/tests/module/utils/test_color.py @@ -2,7 +2,7 @@ import numpy as np -from manim import BLACK, WHITE, RED, Mobject, Scene, VMobject +from manim import BLACK, RED, WHITE, Mobject, Scene, VMobject def test_import_color(): @@ -50,6 +50,7 @@ def test_set_color(): m.set_color(BLACK) assert m.color.to_hex() == "#000000" + def test_color_hash(): assert hash(WHITE) == hash(WHITE.copy()) assert hash(WHITE) != hash(RED)