示例#1
0
import click

import vpype as vp

from .cli import cli


@cli.command(group="Primitives")
@click.argument("x0", type=vp.LengthType())
@click.argument("y0", type=vp.LengthType())
@click.argument("x1", type=vp.LengthType())
@click.argument("y1", type=vp.LengthType())
@vp.generator
def line(x0: float, y0: float, x1: float, y1: float) -> vp.LineCollection:
    """
    Generate a single line.

    The line starts at (X0, Y0) and ends at (X1, Y1). All arguments understand supported units.
    """
    return vp.LineCollection([vp.line(x0, y0, x1, y1)])


@cli.command(group="Primitives")
@click.argument("x", type=vp.LengthType())
@click.argument("y", type=vp.LengthType())
@click.argument("width", type=vp.LengthType())
@click.argument("height", type=vp.LengthType())
@vp.generator
def rect(x: float, y: float, width: float, height: float) -> vp.LineCollection:
    """Generate a rectangle.
示例#2
0
    "layout",
    "linemerge",
    "linesimplify",
    "linesort",
    "multipass",
    "pagesize",
    "reloop",
    "reverse",
    "snap",
    "splitall",
    "trim",
)


@cli.command(group="Operations")
@click.argument("x", type=vp.LengthType(), required=True)
@click.argument("y", type=vp.LengthType(), required=True)
@click.argument("width", type=vp.LengthType(), required=True)
@click.argument("height", type=vp.LengthType(), required=True)
@vp.layer_processor
def crop(lines: vp.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
示例#3
0
        logging.warning("no geometry available, cannot compute origin")
        raise ValueError

    if origin_coords is not None and 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=vp.LengthType(), required=True)
@vp.layer_processor
def translate(lc: vp.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=vp.LengthType())
@click.option(
    "-l",
示例#4
0
import click

import vpype as vp

from .cli import cli


@cli.command(group="Filters")
@click.option(
    "-a",
    "--amplitude",
    type=vp.LengthType(),
    default="0.5mm",
    help="Amplitude of the noise-based displacement (default: 0.5mm).",
)
@click.option(
    "-p",
    "--period",
    type=vp.LengthType(),
    default="3mm",
    help="Period of the noise-based displacement (default: 3mm).",
)
@click.option(
    "-q",
    "--quantization",
    type=vp.LengthType(),
    default="0.05mm",
    help="Maximum segment size used for the resampling (default: 0.05mm).",
)
@vp.layer_processor
def squiggles(lines: vp.LineCollection, amplitude: float, period: float,
示例#5
0
from typing import Optional, Tuple

import click

import vpype as vp

from .cli import cli


@cli.command(group="Text")
@click.argument("string", type=str)
@click.option(
    "-f", "--font", type=click.Choice(vp.FONT_NAMES), default="futural", help="Font to use."
)
@click.option(
    "-s", "--size", type=vp.LengthType(), default=18, help="Text size (default: 18)."
)
@click.option("-w", "--wrap", type=vp.LengthType(), help="Wrap to provided width.")
@click.option("-j", "--justify", is_flag=True, help="Justify text block (wrap-mode only).")
@click.option(
    "-p",
    "--position",
    nargs=2,
    type=vp.LengthType(),
    default=[0, 0],
    help="Position of the text (default: 0, 0).",
)
@click.option(
    "-a",
    "--align",
    type=click.Choice(["left", "right", "center"]),