abey79 / vpype

The Swiss-Army-knife command-line tool for plotter vector graphics.
https://vpype.readthedocs.io/
MIT License
702 stars 61 forks source link

Confusing behaviour of `scale` parameters #17

Closed vytis closed 4 years ago

vytis commented 4 years ago

I am trying out vpype and hit a problem early on. At first I thought it's a bug:

vpype read foo.svg scale 10cm 10cm write scaled.svg

However I should have actually used --to to achieve what I want:

vpype read foo.svg scale --to 10cm 10cm write scaled.svg

The resulting file initially was huge as the factor that it was scaled with is actually centimetres converted to px:

INFO:root:executing global processor `scale` (kwargs: {'scale': (377.95275590551176, 377.95275590551176), 'layer': -2, 'absolute': False, 'keep_proportions': False, 'origin_coords': ()})

There could be few things that would have helped me to see what goes wrong:

  1. scale would error out when passed size with units.
  2. scale would default to scale --to when passed size with units.
  3. It could be two separate commands.
abey79 commented 4 years ago

Thanks for the feedback, this is very useful. I see how this could be confusing.

On several occasions I did use the ability to do (relative) scale with units in factors, especially when using script or writing plugins. This allows me to use arbitrary units when generating geometries (for example a regular grid whose cells have unit width and height) and subsequently scale it to a predictable physical size (the unit-cell grid, when scaled with scale 1cm 1cm, would then have 1cm-sized cells, irrespective of the number of cell). This (admittedly advanced) use-case leads me to reject (1) and, thus, (2).

Having a separate scaleto command (for the lack of a better name) would definitely make sense, and would be easy to implement. I further think than it should default to the keep proportion behaviour since its the most common use-case, with an option to tight fit. Would that make sense to you? Any proposal for the command name?

vytis commented 4 years ago

Makes sense, I didn't think of this use case. So as I understand the --to parameter would be dropped and scaleto would then be the same as what scale --to is now? I don't have any preference on the naming to be honest...

abey79 commented 4 years ago

Yes, scaleto would be the same as scale --to --keep-proportions, with an option to not keep proportions.

abey79 commented 4 years ago

Further commit d2be51fbea6de3bf1a14abf4b9c592aa50614837 to default to keeping proportions.