logging.warning("no geometry available, cannot compute origin") raise ValueError if len(origin_coords) == 2: origin = origin_coords else: origin = ( 0.5 * (bounds[0] + bounds[2]), 0.5 * (bounds[1] + bounds[3]), ) return cast(Tuple[float, float], origin), layer_ids, bounds @cli.command(group="Transforms") @click.argument("offset", nargs=2, type=LengthType(), required=True) @layer_processor def translate(lc: LineCollection, offset: Tuple[float, float]): """ Translate the geometries. X and Y offsets must be provided. These arguments understand supported units. """ lc.translate(offset[0], offset[1]) return lc # noinspection PyShadowingNames @cli.command(name="scale", group="Transforms") @click.argument("scale", nargs=2, type=LengthType()) @click.option( "-l",
from .cli import cli @cli.command(group="Input") @click.argument("file", type=click.Path(exists=True, dir_okay=False)) @click.option("-m", "--single-layer", is_flag=True, help="Single layer mode.") @click.option( "-l", "--layer", type=LayerType(accept_new=True), help="Target layer or 'new' (single layer mode only).", ) @click.option( "-q", "--quantization", type=LengthType(), default="0.1mm", help= "Maximum length of segments approximating curved elements (default: 0.1mm).", ) @click.option( "-s", "--no-simplify", is_flag=True, default=False, help="Do not run the implicit simplify on imported geometries.", ) @global_processor def read( vector_data: VectorData, file,
import math import click import numpy as np from vpype import LineCollection, LengthType, generator from .cli import cli @cli.command(group="Primitives") @click.argument("x0", type=LengthType()) @click.argument("y0", type=LengthType()) @click.argument("x1", type=LengthType()) @click.argument("y1", type=LengthType()) @generator def line(x0: float, y0: float, x1: float, y1: float) -> LineCollection: """ Generate a single line. The line starts at (X0, Y0) and ends at (X1, Y1). All arguments understand supported units. """ return LineCollection([(complex(x0, y0), complex(x1, y1))]) @cli.command(group="Primitives") @click.argument("x", type=LengthType()) @click.argument("y", type=LengthType()) @click.argument("width", type=LengthType()) @click.argument("height", type=LengthType()) @generator def rect(x: float, y: float, width: float, height: float) -> LineCollection:
import logging import math from typing import Tuple, Union, List import click from vpype import global_processor, VectorData, LineCollection, LengthType, layer_processor, \ LayerType, multiple_to_layer_ids from .cli import cli @cli.command(group="Transforms") @click.argument("offset", nargs=2, type=LengthType(), required=True) @layer_processor def translate(lc: LineCollection, offset: Tuple[float, float]): """ Translate the geometries. X and Y offsets must be provided. These arguments understand supported units. """ lc.translate(offset[0], offset[1]) return lc # noinspection PyShadowingNames @cli.command(group="Transforms") @click.argument("scale", nargs=2, type=LengthType()) @click.option( "-l", "--layer", type=LayerType(accept_multiple=True), default="all",
from vpype import ( LineCollection, LengthType, layer_processor, LineIndex, global_processor, multiple_to_layer_ids, VectorData, LayerType, ) from .cli import cli @cli.command(group="Operations") @click.argument("x", type=LengthType(), required=True) @click.argument("y", type=LengthType(), required=True) @click.argument("width", type=LengthType(), required=True) @click.argument("height", type=LengthType(), required=True) @layer_processor def crop(lines: LineCollection, x: float, y: float, width: float, height: float): """Crop the geometries. The crop area is defined by the (X, Y) top-left corner and the WIDTH and HEIGHT arguments. All arguments understand supported units. """ lines.crop(x, y, x + width, y + height) return lines