def test_quadratic_to_cubic_bezier(): r = random.Random(0) def random_vec() -> Vec3: return Vec3(r.uniform(-10, 10), r.uniform(-10, 10), r.uniform(-10, 10)) for i in range(1000): quadratic = Bezier3P((random_vec(), random_vec(), random_vec())) quadratic_approx = list(quadratic.approximate(10)) cubic = quadratic_to_cubic_bezier(quadratic) cubic_approx = list(cubic.approximate(10)) assert len(quadratic_approx) == len(cubic_approx) for p1, p2 in zip(quadratic_approx, cubic_approx): assert p1.isclose(p2)
def test_curve3_to(self): bez3 = Bezier3P([(0, 0), (2, 1), (4, 0)]) p = path.Path() p.curve3_to(bez3.control_points[2], bez3.control_points[1]) qpath = path.to_qpainter_path([p]) # Qt converts quadratic bezier curves unto cubic bezier curves assert qpath.elementCount() == 4 bez4 = quadratic_to_cubic_bezier(bez3) q1 = qpath.elementAt(1) assert q1.isCurveTo() # start of cure assert q1.x, q1.y == bez4.control_points[1] q2 = qpath.elementAt(2) assert q2.type == 3 # curve data element assert q2.x, q2.y == bez4.control_points[2] q3 = qpath.elementAt(3) assert q3.type == 3 # curve data element assert q3.x, q3.y == bez4.control_points[2]