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

Add 'lineshuffle' command #715

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Release date: UNRELEASED
### New features and improvements

* Added a `--orientation` option to the `pagerotate` command to conditionally rotate the page to a target orientation (thanks to @gatesphere) (#705)
* Added a `lineshuffle` command to randomize the plotting order of lines in the current geometry (thanks to @gatesphere) (#715)

### Bug fixes

Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import vpype as vp


project = "vpype"
# noinspection PyShadowingBuiltins
copyright = "2020-2022, Antoine Beyeler"
Expand Down
4 changes: 4 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ CLI reference
.. click:: vpype_cli:linemerge
:prog: linemerge

.. _cmd_lineshuffle:
.. click:: vpype_cli:lineshuffle
:prog: lineshuffle

.. _cmd_linesimplify:
.. click:: vpype_cli:linesimplify
:prog: linesimplify
Expand Down
1 change: 1 addition & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Command:
Command("skew 0 0"),
Command("translate 0 0"),
Command("crop 0 0 1 1"),
Command("lineshuffle"),
Command("linesort"),
Command("linesort --two-opt"),
Command("random linesort"), # make sure there is something sort
Expand Down
16 changes: 16 additions & 0 deletions vpype_cli/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import math
import random
from typing import cast

import click
Expand All @@ -25,6 +26,7 @@
"filter_command",
"layout",
"linemerge",
"lineshuffle",
"linesimplify",
"linesort",
"multipass",
Expand Down Expand Up @@ -328,6 +330,20 @@ def linesimplify(lines: vp.LineCollection, tolerance):
return new_lines


@cli.command(group="Operations")
@layer_processor
def lineshuffle(lines: vp.LineCollection) -> vp.LineCollection:
"""Randomizes the line order within layer.

This command may be useful for testing purposes or spreading out the area in which the pen
is drawing over time, for example to let ink dry. It will almost always increase plotting
time, sometimes considerably.
"""

random.shuffle(lines.lines)
return lines


@cli.command(group="Operations")
@click.option(
"-t",
Expand Down
Loading