Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the V and H commands in the "d" attribute for Lines. + relative coordinates #135

Open
vec2pt opened this issue Jun 24, 2024 · 0 comments

Comments

@vec2pt
Copy link

vec2pt commented Jun 24, 2024

To reduce the size of the "d" attribute for Line and Lines I propose:

  1. implement the H and V commands
  2. add the possibility of creating these objects in relative coordinates

Current:

import drawsvg as dw

line = dw.Line(30, 30, 30, 90)
print(line.args["d"])
# M30,30 L30,90

line = dw.Line(30, 30, 90, 30)
print(line.args["d"])
# M30,30 L90,30

line = dw.Line(30, 30, 90, 90)
print(line.args["d"])
# M30,30 L90,90

lines = dw.Lines(10, 10, 20, 10, 20, 20, 5, 25)
print(lines.args["d"])
# M10,10 L20,10 L20,20 L5,25

polygon = dw.Lines(10, 10, 20, 10, 20, 20, 5, 25, close=True)
print(polygon.args["d"])
# M10,10 L20,10 L20,20 L5,25 Z

After the change:

import drawsvg as dw

line = dw.Line(30, 30, 30, 90)
print(line.args["d"])
# M30,30 V90

line = dw.Line(30, 30, 90, 30)
print(line.args["d"])
# M30,30 H90

line = dw.Line(30, 30, 90, 90)
print(line.args["d"])
# M30,30 L90,90

lines = dw.Lines(10, 10, 20, 10, 20, 20, 5, 25)
print(lines.args["d"])
# M10,10 H20 V20 L5,25

polygon = dw.Lines(10, 10, 20, 10, 20, 20, 5, 25, close=True)
print(polygon.args["d"])
# M10,10 H20 V20 L5,25 Z


# Relative coordinates

line = dw.Line(30, 30, 30, 90, relative=True)
print(line.args["d"])
# M30,30 v60

line = dw.Line(30, 30, 90, 30, relative=True)
print(line.args["d"])
# M30,30 h60

line = dw.Line(30, 30, 90, 90, relative=True)
print(line.args["d"])
# M30,30 l60,60

lines = dw.Lines(10, 10, 20, 10, 20, 20, 5, 25, relative=True)
print(lines.args["d"])
# M10,10 h10 v10 l-15,5

polygon = dw.Lines(10, 10, 20, 10, 20, 20, 5, 25, close=True, relative=True)
print(polygon.args["d"])
# M10,10 h10 v10 l-15,5 Z
vec2pt added a commit to vec2pt/drawsvg that referenced this issue Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant