Skip to content

Commit 2b94694

Browse files
committed
fix up arcs
1 parent a406383 commit 2b94694

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

svgpath/parser.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ def parse_path(pathdef, current_pos=0j, matrix = None, svgState=None):
358358
arc = float(elements.pop())
359359
sweep = float(elements.pop())
360360
end = float(elements.pop()) + float(elements.pop()) * 1j
361-
361+
362362
if not absolute:
363363
end += current_pos
364364

365-
segments.append(path.Arc(scaler(current_pos), scaler(radius)-scaler(0j), rotation, arc, sweep, scaler(end)))
365+
segments.append(path.Arc(current_pos, radius, rotation, arc, sweep, end, scaler))
366366
current_pos = end
367367

368368
return segments
@@ -637,8 +637,6 @@ def scale(width, height, viewBox, z):
637637

638638
getPaths(paths, matrix, svg, path.SVGState(), {})
639639

640-
scaler = lambda z : applyMatrix(matrix, z)
641-
642640
return ( paths, applyMatrix(matrix, complex(viewBox[0], viewBox[1])),
643641
applyMatrix(matrix, complex(viewBox[2], viewBox[3])) )
644642

svgpath/path.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,21 @@ def length(self, error=None, min_depth=None):
229229
return s
230230

231231
class Arc(Segment):
232-
def __init__(self, start, radius, rotation, arc, sweep, end):
232+
def __init__(self, start, radius, rotation, arc, sweep, end, scaler=lambda z:z):
233233
"""radius is complex, rotation is in degrees,
234234
large and sweep are 1 or 0 (True/False also work)"""
235235

236-
super(Arc, self).__init__(start,end)
236+
super(Arc, self).__init__(scaler(start),scaler(end))
237+
self.start0 = start
238+
self.end0 = end
237239
self.radius = radius
238240
self.rotation = rotation
239241
self.arc = bool(arc)
240242
self.sweep = bool(sweep)
243+
self.scaler = scaler
241244

242245
self._parameterize()
243-
246+
244247
def __repr__(self):
245248
return 'Arc(start=%s, radius=%s, rotation=%s, arc=%s, sweep=%s, end=%s)' % (
246249
self.start, self.radius, self.rotation, self.arc, self.sweep, self.end)
@@ -263,8 +266,8 @@ def _parameterize(self):
263266

264267
cosr = cos(radians(self.rotation))
265268
sinr = sin(radians(self.rotation))
266-
dx = (self.start.real - self.end.real) / 2
267-
dy = (self.start.imag - self.end.imag) / 2
269+
dx = (self.start0.real - self.end0.real) / 2
270+
dy = (self.start0.imag - self.end0.imag) / 2
268271
x1prim = cosr * dx + sinr * dy
269272
x1prim_sq = x1prim * x1prim
270273
y1prim = -sinr * dx + cosr * dy
@@ -293,9 +296,9 @@ def _parameterize(self):
293296
cyprim = -c * ry * x1prim / rx
294297

295298
self.center = complex((cosr * cxprim - sinr * cyprim) +
296-
((self.start.real + self.end.real) / 2),
299+
((self.start0.real + self.end0.real) / 2),
297300
(sinr * cxprim + cosr * cyprim) +
298-
((self.start.imag + self.end.imag) / 2))
301+
((self.start0.imag + self.end0.imag) / 2))
299302

300303
ux = (x1prim - cxprim) / rx
301304
uy = (y1prim - cyprim) / ry
@@ -323,7 +326,7 @@ def _parameterize(self):
323326
self.delta = delta % 360
324327
if not self.sweep:
325328
self.delta -= 360
326-
329+
327330
def point(self, pos):
328331
if pos == 0.:
329332
return self.start
@@ -337,7 +340,7 @@ def point(self, pos):
337340
self.radius.imag + self.center.real)
338341
y = (sinr * cos(angle) * self.radius.real + cosr * sin(angle) *
339342
self.radius.imag + self.center.imag)
340-
return complex(x, y)
343+
return self.scaler(complex(x, y))
341344

342345
def length(self, error=ERROR, min_depth=MIN_DEPTH):
343346
"""The length of an elliptical arc segment requires numerical

0 commit comments

Comments
 (0)