Example #1
0
 def test_for_very_short_line_segments(self, start, delta):
     path = Path((start, 0, 0))
     path.line_to((start + delta, 0, 0))
     path = lines_to_curve4(path)
     assert len(path) == 1
     assert path[0].type == Command.CURVE4_TO
     assert len(list(path.flattening(1))) > 3
Example #2
0
 def test_which_length_is_too_short_to_create_a_curve(self, start, delta):
     path = Path((start, 0, 0))
     path.line_to((start + delta, 0, 0))
     path = lines_to_curve4(path)
     assert len(path) == 1
     assert (
         path[0].type == Command.LINE_TO
     ), "should not remove a single line segment representing a point"
     assert len(list(path.flattening(1))) == 2
Example #3
0
 def test_line_to_curve_creates_a_linear_segment(self, func):
     v1, v2 = 1, 2
     path = Path(start=(v1, v1, v1))
     path.line_to((v2, v2, v2))
     path = func(path)
     vertices = list(path.flattening(1))
     assert len(vertices) > 2
     assert all([
         math.isclose(v.x, v.y) and math.isclose(v.x, v.z) for v in vertices
     ]), "all vertices have to be located along a line (x == y == z)"
Example #4
0
    def draw_path(self, path: Path, properties: Properties) -> None:
        """ Draw an outline path (connected string of line segments and Bezier
        curves).

        The :meth:`draw_path` implementation is a fall-back implementation
        which approximates Bezier curves by flattening as line segments.
        Backends can override this method if better path drawing functionality
        is available for that backend.

        """
        if len(path):
            vertices = iter(
                path.flattening(distance=self.max_flattening_distance))
            prev = next(vertices)
            for vertex in vertices:
                self.draw_line(prev, vertex, properties)
                prev = vertex