Skip to content

Commit

Permalink
V and H commands for Lines. + relative coordinates cduck#135
Browse files Browse the repository at this point in the history
  • Loading branch information
vec2pt committed Jun 24, 2024
1 parent 2ab4c53 commit 3912b5d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions drawsvg/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,24 @@ class Lines(Path):
Additional keyword arguments are output as additional arguments to the SVG
node e.g. fill="red", stroke="#ff4477", stroke_width=2.
'''
def __init__(self, sx, sy, *points, close=False, **kwargs):
def __init__(self, sx, sy, *points, close=False, relative=False, **kwargs):
super().__init__(d='', **kwargs)
self.M(sx, sy)
if len(points) % 2 != 0:
raise TypeError(
'expected an even number of positional arguments x0, y0, '
'x1, y1, ...')
for i in range(len(points) // 2):
self.L(points[2*i], points[2*i+1])
px = points[2*(i-1)] if i > 0 else sx
py = points[2*(i-1)+1] if i > 0 else sy
x = points[2*i]
y = points[2*i+1]
if x == px:
self.v(y - py) if relative else self.V(y)
elif y == py:
self.h(x - px) if relative else self.H(x)
else:
self.l(x - px, y - py) if relative else self.L(x, y)
if close:
self.Z()

Expand All @@ -585,8 +594,10 @@ class Line(Lines):
Additional keyword arguments are output as additional arguments to the SVG
node e.g. fill="red", stroke="#ff4477", stroke_width=2.
'''
def __init__(self, sx, sy, ex, ey, **kwargs):
super().__init__(sx, sy, ex, ey, close=False, **kwargs)
def __init__(self, sx, sy, ex, ey, relative=False, **kwargs):
super().__init__(
sx, sy, ex, ey, close=False, relative=relative, **kwargs
)

class Arc(Path):
'''A circular arc.
Expand Down

0 comments on commit 3912b5d

Please sign in to comment.