mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Reuse hash_string function
This commit is contained in:
parent
f0984487ea
commit
1596356385
1 changed files with 13 additions and 11 deletions
|
@ -1,6 +1,5 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import os
|
import os
|
||||||
from xml.etree import ElementTree as ET
|
from xml.etree import ElementTree as ET
|
||||||
|
|
||||||
|
@ -19,6 +18,7 @@ from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||||
from manimlib.utils.directories import get_mobject_data_dir
|
from manimlib.utils.directories import get_mobject_data_dir
|
||||||
from manimlib.utils.images import get_full_vector_image_path
|
from manimlib.utils.images import get_full_vector_image_path
|
||||||
from manimlib.utils.iterables import hash_obj
|
from manimlib.utils.iterables import hash_obj
|
||||||
|
from manimlib.utils.simple_functions import hash_string
|
||||||
|
|
||||||
|
|
||||||
SVG_HASH_TO_MOB_MAP: dict[int, VMobject] = {}
|
SVG_HASH_TO_MOB_MAP: dict[int, VMobject] = {}
|
||||||
|
@ -106,7 +106,7 @@ class SVGMobject(VMobject):
|
||||||
return get_full_vector_image_path(self.file_name)
|
return get_full_vector_image_path(self.file_name)
|
||||||
|
|
||||||
def modify_xml_tree(self, element_tree: ET.ElementTree) -> ET.ElementTree:
|
def modify_xml_tree(self, element_tree: ET.ElementTree) -> ET.ElementTree:
|
||||||
config_style_dict = self.generate_config_style_dict()
|
config_style_attrs = self.generate_config_style_dict()
|
||||||
style_keys = (
|
style_keys = (
|
||||||
"fill",
|
"fill",
|
||||||
"fill-opacity",
|
"fill-opacity",
|
||||||
|
@ -116,14 +116,17 @@ class SVGMobject(VMobject):
|
||||||
"style"
|
"style"
|
||||||
)
|
)
|
||||||
root = element_tree.getroot()
|
root = element_tree.getroot()
|
||||||
root_style_dict = {
|
style_attrs = {}
|
||||||
k: v for k, v in root.attrib.items()
|
rest_attrs = {}
|
||||||
if k in style_keys
|
for k, v in root.attrib.items():
|
||||||
}
|
if k in style_keys:
|
||||||
|
style_attrs[k] = v
|
||||||
|
else:
|
||||||
|
rest_attrs[k] = v
|
||||||
|
|
||||||
new_root = ET.Element("svg", {})
|
new_root = ET.Element("svg", rest_attrs)
|
||||||
config_style_node = ET.SubElement(new_root, "g", config_style_dict)
|
config_style_node = ET.SubElement(new_root, "g", config_style_attrs)
|
||||||
root_style_node = ET.SubElement(config_style_node, "g", root_style_dict)
|
root_style_node = ET.SubElement(config_style_node, "g", style_attrs)
|
||||||
root_style_node.extend(root)
|
root_style_node.extend(root)
|
||||||
return ET.ElementTree(new_root)
|
return ET.ElementTree(new_root)
|
||||||
|
|
||||||
|
@ -302,8 +305,7 @@ class VMobjectFromSVGPath(VMobject):
|
||||||
# will be saved to a file so that future calls for the same path
|
# will be saved to a file so that future calls for the same path
|
||||||
# don't need to retrace the same computation.
|
# don't need to retrace the same computation.
|
||||||
path_string = self.path_obj.d()
|
path_string = self.path_obj.d()
|
||||||
hasher = hashlib.sha256(path_string.encode())
|
path_hash = hash_string(path_string)
|
||||||
path_hash = hasher.hexdigest()[:16]
|
|
||||||
points_filepath = os.path.join(get_mobject_data_dir(), f"{path_hash}_points.npy")
|
points_filepath = os.path.join(get_mobject_data_dir(), f"{path_hash}_points.npy")
|
||||||
tris_filepath = os.path.join(get_mobject_data_dir(), f"{path_hash}_tris.npy")
|
tris_filepath = os.path.join(get_mobject_data_dir(), f"{path_hash}_tris.npy")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue