Skip to content

Commit f5225c4

Browse files
committed
Restore @theomega invert_axis
1 parent 1453829 commit f5225c4

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

vpype_gcode/gwrite.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,41 @@
66
import vpype as vp
77

88
# Load the default config
9+
from vpype import LayerType
10+
911
vp.CONFIG_MANAGER.load_config_file(str(Path(__file__).parent / "bundled_configs.toml"))
1012

1113

14+
def invert_axis(
15+
document: vp.Document,
16+
invert_x: bool,
17+
invert_y: bool
18+
):
19+
""" Inverts none, one or borth axis of the document.
20+
This applies a relative scale operation with factors of 1 or -1
21+
on the two axis to all layers. The invertion happens relative to
22+
the center of the bounds.
23+
"""
24+
25+
layer_ids = vp.multiple_to_layer_ids(LayerType.ALL, document)
26+
bounds = document.bounds(layer_ids)
27+
28+
if not bounds:
29+
return document
30+
31+
origin = (
32+
0.5 * (bounds[0] + bounds[2]),
33+
0.5 * (bounds[1] + bounds[3]),
34+
)
35+
36+
for vid in layer_ids:
37+
lc = document[vid]
38+
lc.translate(-origin[0], -origin[1])
39+
lc.scale(-1 if invert_x else 1, -1 if invert_y else 1)
40+
lc.translate(origin[0], origin[1])
41+
42+
return document
43+
1244
@click.command()
1345
@click.argument("output", type=click.File("w"))
1446
@click.option(

0 commit comments

Comments
 (0)