Пример #1
0
def add_bezier3p(path: Path, curves: Iterable[Bezier3P]) -> None:
    """ Add multiple quadratic Bèzier-curves to the given `path`.

    Auto-detect the connection point to the given `path`, if neither the start-
    nor the end point of the curves is close to the path end point, a line from
    the path end point to the start point of the first curve will be added
    automatically.

    .. versionchanged:: 0.16.2

        add linear Bézier curve segments as LINE_TO commands

    """
    curves = list(curves)
    if not len(curves):
        return
    end = curves[-1].control_points[-1]
    if path.end.isclose(end):
        # connect to new curves end point
        curves = reverse_bezier_curves(curves)

    for curve in curves:
        start, ctrl, end = curve.control_points
        if not start.isclose(path.end, abs_tol=1e-9):
            path.line_to(start)

        # add linear bezier segments as LINE_TO commands
        if start.isclose(ctrl, abs_tol=1e-9) or end.isclose(ctrl,
                                                            abs_tol=1e-9):
            path.line_to(end)
        else:
            path.curve3_to(end, ctrl)
Пример #2
0
 def bulge_to(p1: Vec3, p2: Vec3, bulge: float):
     if p1.isclose(p2, rel_tol=IS_CLOSE_TOL, abs_tol=0):
         return
     center, start_angle, end_angle, radius = bulge_to_arc(p1, p2, bulge)
     ellipse = ConstructionEllipse.from_arc(
         center, radius, Z_AXIS,
         math.degrees(start_angle),
         math.degrees(end_angle),
     )
     curves = list(cubic_bezier_from_ellipse(ellipse))
     curve0 = curves[0]
     cp0 = curve0.control_points[0]
     if cp0.isclose(p2, rel_tol=IS_CLOSE_TOL, abs_tol=0):
         curves = reverse_bezier_curves(curves)
     add_bezier4p(path, curves)
Пример #3
0
def add_bezier4p(path: Path, curves: Iterable[Bezier4P]) -> None:
    """ Add multiple cubic Bèzier-curves to the given `path`.

    Auto-detect the connection point to the given `path`, if neither the start-
    nor the end point of the curves is close to the path end point, a line from
    the path end point to the start point of the first curve will be added
    automatically.

    """
    curves = list(curves)
    if not len(curves):
        return
    end = curves[-1].control_points[-1]
    if path.end.isclose(end):
        # connect to new curves end point
        curves = reverse_bezier_curves(curves)

    for curve in curves:
        start, ctrl1, ctrl2, end = curve.control_points
        if not start.isclose(path.end, abs_tol=1e-9):
            path.line_to(start)
        path.curve4_to(end, ctrl1, ctrl2)