def test_approximate_curves(): path = Path() path.curve_to((2, 0), (0, 1), (2, 1)) vertices = list(path.approximate(10)) assert len(vertices) == 11 assert vertices[0] == (0, 0) assert vertices[-1] == (2, 0)
def test_approximate_lines(): path = Path() path.line_to((1, 1)) path.line_to((2, 0)) vertices = list(path.approximate()) assert len(vertices) == 3 assert vertices[0] == path.start == (0, 0) assert vertices[2] == path.end == (2, 0)
def test_approximate_curves(): path = Path() path.curve3_to((2, 0), (1, 1)) path.curve4_to((3, 0), (2, 1), (3, 1)) vertices = list(path.approximate(20)) assert len(vertices) == 41 assert vertices[0] == (0, 0) assert vertices[-1] == (3, 0)
def draw_path(self, path: Path, properties) -> None: """ Fall-back implementation, approximate path by line segments. Override in inherited back-end for a more efficient implementation. """ if len(path): if properties.filling: self.draw_filled_polygon( path.approximate(segments=self.bezier_approximation_count), properties, ) else: vertices = iter( path.approximate(segments=self.bezier_approximation_count)) prev = next(vertices) for vertex in vertices: self.draw_line(prev, vertex, properties) prev = vertex
def draw_path(self, path: Path, properties: Properties) -> None: """ Draw or fill a path (connected string of line segments and Bezier curves) The :meth:`draw_path` implementation is a fall-back implementation which approximates the path using line segments. Backends can override this method if better path drawing functionality is available for that backend. """ if len(path): if properties.filling: self.draw_filled_polygon( path.approximate(segments=self.bezier_approximation_count), properties, ) else: vertices = iter( path.approximate(segments=self.bezier_approximation_count)) prev = next(vertices) for vertex in vertices: self.draw_line(prev, vertex, properties) prev = vertex