-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Scaling and cropping from the centre #41
Comments
Currently, The one weirdness about the As for cropping, my feeling is that a new |
Ah! I was basing my comment on the --help text, so it might be good to specify that in
I like this suggestion. I agree that
I guess I'm wondering what the use case for |
I actual use
This is currently not possible without a change to the data model. Currently, vpype doesn't know of a bounding box per se (independently of the actual vector content). So for vpype, whenever the bounding box is considered (e.g. for Of course, SVG does implement a specific bounding box (with the viewPort, width, height stuff), so this information is actually lost in
As a result, I've been avoiding doing this modification until a very clear workflow emerges that requires it. |
Gotcha, that all makes sense. I think your approach on the bounding box stuff is probably smart! I'll close this issue now as the main outcome - adding |
One more thing: I consider the CLI # noinspection PyShadowingNames
@cli.command(group="Transforms")
@click.argument("scale", nargs=2, type=LengthType())
@click.option(
"-l",
"--layer",
type=LayerType(accept_multiple=True),
default="all",
help="Target layer(s).",
)
# ... shortened ...
@global_processor
def scale(
vector_data: VectorData,
scale: Tuple[float, float],
layer: Union[int, List[int]],
absolute: bool,
keep_proportions: bool,
origin_coords: Tuple[float, float],
):
"""Scale the geometries.
The origin used is the bounding box center, unless the `--origin` option is used.
By default, the arguments are used as relative factors (e.g. `scale 2 2` make the
geometries twice as big in both dimensions). With `--to`, the arguments are interpreted as
the final size. In this case, arguments understand the supported units (e.g.
`scale --to 10cm 10cm`).
By default, act on all layers. If one or more layer IDs are provided with the `--layer`
option, only these layers will be affected. In this case, the bounding box is that of the
listed layers.
"""
# these are the layers we want to act on
layer_ids = multiple_to_layer_ids(layer, vector_data)
bounds = vector_data.bounds(layer_ids)
if not bounds:
return vector_data
# ... shortened ...
return vector_data You can tell a function actually implements a command by the top |
I feel like it should be easier to use the centre of the geometries as the origin for
scale
andcrop
.Rotate already uses the centre as the origin by default, which I think is correct. I feel like
scale
should also operate from the centre by default as this would be the most common use case during pen plotting. If you think this might confuse users, allowing--origin center
might be a good compromise. One can, of course, always use--center
in thewrite
command to fix this, but I don't think that giving users an alternative here is a bad idea.With crop it's a little trickier because it uses X and Y rather than
--origin
. But again - I feel like a common use case would be cropping in from all the edges evenly, and this is currently very difficult to calculate manually. Might be worth thinking about refactoring this to use--origin
too, so it matches the other commands?The text was updated successfully, but these errors were encountered: