Skip to content

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

@vec2pt

Description

@vec2pt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions