mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Update hash_obj method
This commit is contained in:
parent
aef02bfcf9
commit
0bb9216c14
1 changed files with 4 additions and 14 deletions
|
@ -2,6 +2,7 @@ from manimlib.constants import *
|
||||||
from manimlib.mobject.svg.tex_mobject import SingleStringTex
|
from manimlib.mobject.svg.tex_mobject import SingleStringTex
|
||||||
from manimlib.mobject.svg.text_mobject import Text
|
from manimlib.mobject.svg.text_mobject import Text
|
||||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||||
|
from manimlib.utils.iterables import hash_obj
|
||||||
|
|
||||||
|
|
||||||
string_to_mob_map = {}
|
string_to_mob_map = {}
|
||||||
|
@ -86,20 +87,9 @@ class DecimalNumber(VMobject):
|
||||||
return self.data["font_size"][0]
|
return self.data["font_size"][0]
|
||||||
|
|
||||||
def string_to_mob(self, string, mob_class=Text, **kwargs):
|
def string_to_mob(self, string, mob_class=Text, **kwargs):
|
||||||
def make_hash(o):
|
if (string, hash_obj(kwargs)) not in string_to_mob_map:
|
||||||
if isinstance(o, (set, tuple, list)):
|
string_to_mob_map[(string, hash_obj(kwargs))] = mob_class(string, font_size=1, **kwargs)
|
||||||
return tuple([make_hash(e) for e in o])
|
mob = string_to_mob_map[(string, hash_obj(kwargs))].copy()
|
||||||
elif not isinstance(o, dict):
|
|
||||||
return hash(o)
|
|
||||||
from copy import deepcopy as _deepcopy
|
|
||||||
new_o = _deepcopy(o)
|
|
||||||
for k, v in new_o.items():
|
|
||||||
new_o[k] = make_hash(v)
|
|
||||||
return hash(tuple(frozenset(sorted(new_o.items()))))
|
|
||||||
|
|
||||||
if (string, make_hash(kwargs)) not in string_to_mob_map:
|
|
||||||
string_to_mob_map[(string, make_hash(kwargs))] = mob_class(string, font_size=1, **kwargs)
|
|
||||||
mob = string_to_mob_map[(string, make_hash(kwargs))].copy()
|
|
||||||
mob.scale(self.get_font_size())
|
mob.scale(self.get_font_size())
|
||||||
return mob
|
return mob
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue