mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Merge pull request #450 from ProgrammingIncluded/master
Fixed SVG parsing error with consecutive C or M coordinates.
This commit is contained in:
commit
5b1f54a89e
1 changed files with 20 additions and 7 deletions
|
@ -351,10 +351,19 @@ class VMobjectFromSVGPathstring(VMobject):
|
||||||
if len(new_points) <= 1:
|
if len(new_points) <= 1:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Huh? When does this come up?
|
# Draw relative line-to values.
|
||||||
points = self.points
|
points = self.points
|
||||||
new_points = new_points[1:]
|
new_points = new_points[1:]
|
||||||
command = "L"
|
command = "L"
|
||||||
|
|
||||||
|
# Treat everything as relative line-to until empty
|
||||||
|
for p in new_points:
|
||||||
|
# Treat as relative
|
||||||
|
p[0] += self.points[-1, 0]
|
||||||
|
p[1] += self.points[-1, 1]
|
||||||
|
self.add_line_to(p)
|
||||||
|
return
|
||||||
|
|
||||||
elif command in ["L", "H", "V"]: # lineto
|
elif command in ["L", "H", "V"]: # lineto
|
||||||
if command == "H":
|
if command == "H":
|
||||||
new_points[0, 1] = points[-1, 1]
|
new_points[0, 1] = points[-1, 1]
|
||||||
|
@ -382,13 +391,17 @@ class VMobjectFromSVGPathstring(VMobject):
|
||||||
elif command == "Z": # closepath
|
elif command == "Z": # closepath
|
||||||
return
|
return
|
||||||
|
|
||||||
# Handle situations where there's multiple relative control points
|
# Add first three points
|
||||||
if isLower and len(new_points) > 3:
|
self.add_cubic_bezier_curve_to(*new_points[0:3])
|
||||||
for i in range(3, len(new_points), 3):
|
|
||||||
new_points[i:i + 3] -= points[-1]
|
|
||||||
new_points[i:i + 3] += new_points[i - 1]
|
|
||||||
|
|
||||||
self.add_cubic_bezier_curve_to(*new_points)
|
# Handle situations where there's multiple relative control points
|
||||||
|
if len(new_points) > 3:
|
||||||
|
# Add subsequent offset points relatively.
|
||||||
|
for i in range(3, len(new_points), 3):
|
||||||
|
if isLower:
|
||||||
|
new_points[i:i + 3] -= points[-1]
|
||||||
|
new_points[i:i + 3] += new_points[i - 1]
|
||||||
|
self.add_cubic_bezier_curve_to(*new_points[i:i+3])
|
||||||
|
|
||||||
def string_to_points(self, coord_string):
|
def string_to_points(self, coord_string):
|
||||||
numbers = string_to_numbers(coord_string)
|
numbers = string_to_numbers(coord_string)
|
||||||
|
|
Loading…
Add table
Reference in a new issue