Skip to content

Commit

Permalink
Add 'lineshuffle' command (#715)
Browse files Browse the repository at this point in the history
* Add 'lineshuffle' command and d.

* Add lineshuffle PR# to CHANGELOG.md

* Revert docs/CHANGELOG.md to a symlink, remove useless lineshuffle test.

* Simplified doc string and code

---------

Co-authored-by: Antoine Beyeler <[email protected]>
  • Loading branch information
gatesphere and abey79 authored Apr 9, 2024
1 parent d5ed0a6 commit 9fd17d5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
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

0 comments on commit 9fd17d5

Please sign in to comment.