mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Address percent bug a better way, but still witha patch that shouldn't be permanent
This commit is contained in:
parent
d702396d87
commit
af0948ea15
2 changed files with 32 additions and 20 deletions
|
@ -22,6 +22,34 @@ from manimlib.utils.color import *
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
|
|
||||||
|
|
||||||
|
def check_and_fix_percent_bug(sym):
|
||||||
|
# This is an ugly patch addressing something which should be
|
||||||
|
# addressed at a deeper level.
|
||||||
|
# The svg path for percent symbols have a known bug, so this
|
||||||
|
# checks if the symbol is (probably) a percentage sign, and
|
||||||
|
# splits it so that it's displayed properly.
|
||||||
|
if len(sym.points) not in [315, 483] or len(sym.get_subpaths()) != 4:
|
||||||
|
return
|
||||||
|
|
||||||
|
sym = sym.family_members_with_points()[0]
|
||||||
|
new_sym = VMobject()
|
||||||
|
path_lengths = [len(path) for path in sym.get_subpaths()]
|
||||||
|
if len(sym.points) == 315:
|
||||||
|
n = sum(path_lengths[:2])
|
||||||
|
p1 = sym.points[:n]
|
||||||
|
p2 = sym.points[n:]
|
||||||
|
elif len(sym.points) == 483:
|
||||||
|
p1 = np.vstack([
|
||||||
|
sym.points[:path_lengths[0]],
|
||||||
|
sym.points[-path_lengths[3]:]
|
||||||
|
])
|
||||||
|
p2 = sym.points[path_lengths[0]:sum(path_lengths[:3])]
|
||||||
|
sym.points = p1
|
||||||
|
new_sym.points = p2
|
||||||
|
sym.add(new_sym)
|
||||||
|
sym.refresh_triangulation()
|
||||||
|
|
||||||
|
|
||||||
def string_to_numbers(num_string):
|
def string_to_numbers(num_string):
|
||||||
num_string = num_string.replace("-", ",-")
|
num_string = num_string.replace("-", ",-")
|
||||||
num_string = num_string.replace("e,-", "e-")
|
num_string = num_string.replace("e,-", "e-")
|
||||||
|
@ -361,6 +389,7 @@ class VMobjectFromSVGPathstring(VMobject):
|
||||||
self.stretch(-1, 1, about_point=ORIGIN)
|
self.stretch(-1, 1, about_point=ORIGIN)
|
||||||
# Save to a file for future use
|
# Save to a file for future use
|
||||||
np.save(filepath, self.points)
|
np.save(filepath, self.points)
|
||||||
|
check_and_fix_percent_bug(self)
|
||||||
|
|
||||||
def get_commands_and_coord_strings(self):
|
def get_commands_and_coord_strings(self):
|
||||||
all_commands = list(self.get_command_to_function_map().keys())
|
all_commands = list(self.get_command_to_function_map().keys())
|
||||||
|
|
|
@ -12,21 +12,7 @@ from manimlib.utils.strings import split_string_list_to_isolate_substrings
|
||||||
from manimlib.utils.tex_file_writing import tex_to_svg_file
|
from manimlib.utils.tex_file_writing import tex_to_svg_file
|
||||||
|
|
||||||
|
|
||||||
TEX_MOB_SCALE_FACTOR = 0.05
|
SCALE_FACTOR_PER_FONT_POINT = 0.001
|
||||||
|
|
||||||
|
|
||||||
def fix_percent(sym):
|
|
||||||
sym = sym.family_members_with_points()[0]
|
|
||||||
# Really need to make this unneeded...
|
|
||||||
new_sym = sym.copy()
|
|
||||||
path_lengths = [len(path) for path in sym.get_subpaths()]
|
|
||||||
n = sum(path_lengths[:2])
|
|
||||||
p1 = sym.points[:n]
|
|
||||||
p2 = sym.points[n:]
|
|
||||||
sym.points = p1
|
|
||||||
new_sym.points = p2
|
|
||||||
sym.add(new_sym)
|
|
||||||
sym.refresh_triangulation()
|
|
||||||
|
|
||||||
|
|
||||||
class TexSymbol(VMobjectFromSVGPathstring):
|
class TexSymbol(VMobjectFromSVGPathstring):
|
||||||
|
@ -42,6 +28,7 @@ class SingleStringTexMobject(SVGMobject):
|
||||||
"fill_opacity": 1.0,
|
"fill_opacity": 1.0,
|
||||||
"stroke_width": 0,
|
"stroke_width": 0,
|
||||||
"should_center": True,
|
"should_center": True,
|
||||||
|
"font_size": 48,
|
||||||
"height": None,
|
"height": None,
|
||||||
"organize_left_to_right": False,
|
"organize_left_to_right": False,
|
||||||
"alignment": "",
|
"alignment": "",
|
||||||
|
@ -57,12 +44,9 @@ class SingleStringTexMobject(SVGMobject):
|
||||||
)
|
)
|
||||||
SVGMobject.__init__(self, file_name=file_name, **kwargs)
|
SVGMobject.__init__(self, file_name=file_name, **kwargs)
|
||||||
if self.height is None:
|
if self.height is None:
|
||||||
self.scale(TEX_MOB_SCALE_FACTOR)
|
self.scale(SCALE_FACTOR_PER_FONT_POINT * self.font_size)
|
||||||
if self.organize_left_to_right:
|
if self.organize_left_to_right:
|
||||||
self.organize_submobjects_left_to_right()
|
self.organize_submobjects_left_to_right()
|
||||||
# TODO, this is temporary
|
|
||||||
if tex_string == "\\%":
|
|
||||||
fix_percent(self)
|
|
||||||
|
|
||||||
def get_modified_expression(self, tex_string):
|
def get_modified_expression(self, tex_string):
|
||||||
result = self.alignment + " " + tex_string
|
result = self.alignment + " " + tex_string
|
||||||
|
@ -177,7 +161,6 @@ class TexMobject(SingleStringTexMobject):
|
||||||
)
|
)
|
||||||
if self.arg_separator == ' ':
|
if self.arg_separator == ' ':
|
||||||
split_list = [str(x).strip() for x in split_list]
|
split_list = [str(x).strip() for x in split_list]
|
||||||
#split_list = list(map(str.strip, split_list))
|
|
||||||
split_list = [s for s in split_list if s != '']
|
split_list = [s for s in split_list if s != '']
|
||||||
return split_list
|
return split_list
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue