File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import vpype as vp
77
88# Load the default config
9+ from vpype import LayerType
10+
911vp .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 (
You can’t perform that action at this time.
0 commit comments