Beispiel #1
0
    def _document_as_border(self) -> None:
        """
        Adds a beam blocking contour on the borders of the document to
        prevent the beams from going to infinity
        """

        svg = self.document.getroot()
        w = self.svg.unittouu(svg.get('width'))
        h = self.svg.unittouu(svg.get('height'))
        contour_geometry = geom.CompositeCubicBezier([geom.CubicBezierPath([
                geom.CubicBezier(np.array([[0, 0], [0, 0], [w, 0], [w, 0]])),
                geom.CubicBezier(np.array([[w, 0], [w, 0], [w, h], [w, h]])),
                geom.CubicBezier(np.array([[w, h], [w, h], [0, h], [0, h]])),
                geom.CubicBezier(
                        np.array([[0, h], [0, h], [0, 0], [0, 0]]))])])
        self._document_border = OpticalObject(contour_geometry, mat.BeamDump())
        self._world.add_object(self._document_border)
Beispiel #2
0
def superpath_to_bezier_segments(superpath: inkex.CubicSuperPath) \
        -> geom.CompositeCubicBezier:
    """
    Converts a superpath with a representation
    [Subpath0[handle0_0, point0, handle0_1], ...], ...]
    to a representation of consecutive bezier segments of the form
    CompositeCubicBezier([CubicBezierPath[CubicBezier[point0, handle0_1,
    handle1_0, point1], ...], ...]).
    """

    composite_bezier = list()
    for subpath in superpath:
        bezier_path = list()
        for (__, p0, p1), (p2, p3, __) in pairwise(subpath):
            bezier = geom.CubicBezier(np.array([p0, p1, p2, p3]))
            bezier_path.append(bezier)
        composite_bezier.append(geom.CubicBezierPath(bezier_path))
    return geom.CompositeCubicBezier(composite_bezier)