Exemple #1
0
def test_bezier_decomposition():
    bspline = BSpline.from_fit_points([
        (0, 0),
        (10, 20),
        (30, 10),
        (40, 10),
        (50, 0),
        (60, 20),
        (70, 50),
        (80, 70),
    ])
    bezier_segments = list(bspline.bezier_decomposition())
    assert len(bezier_segments) == 5
    # results visually checked to be correct
    assert close_vectors(
        bezier_segments[0],
        [
            (0.0, 0.0, 0.0),
            (2.02070813064438, 39.58989657555839, 0.0),
            (14.645958536022286, 10.410103424441612, 0.0),
            (30.0, 10.0, 0.0),
        ],
    )
    assert close_vectors(
        bezier_segments[-1],
        [
            (60.0, 20.0, 0.0),
            (66.33216513897267, 43.20202388489432, 0.0),
            (69.54617236126121, 50.37880459351478, 0.0),
            (80.0, 70.0, 0.0),
        ],
    )
    def test_split_cubic_bezier(self, points3):
        left, right = split_bezier(points3, 0.5)
        assert (close_vectors(
            left,
            [(0.0, 0.0), (0.0, 0.5), (0.375, 0.6875), (0.8125, 0.90625)],
        ) is True)

        assert (close_vectors(
            right,
            [(2.0, 2.0), (1.75, 1.375), (1.25, 1.125), (0.8125, 0.90625)],
        ) is True)
Exemple #3
0
def test_control_vertices(p1):
    vertices = list(p1.control_vertices())
    assert close_vectors(vertices, [(0, 0), (2, 0), (2, 1), (4, 1), (4, 0),
                                    (5, -1), (6, 0)])
    path = Path()
    assert len(list(path.control_vertices())) == 0
    assert list(path.control_vertices()) == list(path.approximate(2))
    path = converter.from_vertices([(0, 0), (1, 0)])
    assert len(list(path.control_vertices())) == 2
Exemple #4
0
def test_bspline_interpolation(fit_points):
    spline = global_bspline_interpolation(fit_points, degree=3, method="chord")
    assert len(spline.control_points) == len(fit_points)

    t_array = list(create_t_vector(fit_points, "chord"))
    assert t_array[0] == 0.0
    assert t_array[-1] == 1.0
    assert len(t_array) == len(fit_points)

    t_points = [spline.point(t) for t in t_array]
    assert close_vectors(t_points, fit_points)
Exemple #5
0
 def test_to_splines_and_polylines(self, path):
     entities = list(to_splines_and_polylines([path]))
     assert len(entities) == 2
     polyline = entities[0]
     spline = entities[1]
     assert polyline.dxftype() == "POLYLINE"
     assert spline.dxftype() == "SPLINE"
     assert polyline.vertices[0].dxf.location.isclose((0, 0))
     assert polyline.vertices[1].dxf.location.isclose((4, 0))
     assert close_vectors(
         Vec3.generate(spline.control_points),
         [(4, 0, 0), (3, 1, 1), (1, 1, 1), (0, 0, 0)],
     )
    def test_chain2(self, m44):
        s = m44.scale(10, 20, 30)
        t = m44.translate(10, 20, 30)
        r = m44.axis_rotate(angle=pi / 2, axis=(0.0, 0.0, 1.0))
        points = ((23.0, 97.0, 0.5), (2.0, 7.0, 13.0))

        p1 = s.transform_vertices(points)
        p1 = t.transform_vertices(p1)
        p1 = r.transform_vertices(p1)

        c = m44.chain(s, t, r)
        p2 = c.transform_vertices(points)
        assert close_vectors(p1, p2) is True
Exemple #7
0
 def test_to_edge_path_hatches(self, path):
     hatches = list(to_hatches(path, edge_path=True))
     assert len(hatches) == 1
     h0 = hatches[0]
     assert h0.dxftype() == "HATCH"
     assert len(h0.paths) == 1
     edge_path = h0.paths[0]
     assert edge_path.type == BoundaryPathType.EDGE
     line, spline = edge_path.edges
     assert line.type == EdgeType.LINE
     assert line.start == (0, 0)
     assert line.end == (4, 0)
     assert spline.type == EdgeType.SPLINE
     assert close_vectors(
         Vec3.generate(spline.control_points),
         [(4, 0), (3, 1), (1, 1), (0, 0)],
     )
 def test_to_edge_path_hatches(self, path):
     hatches = list(to_hatches(path, edge_path=True))
     assert len(hatches) == 1
     h0 = hatches[0]
     assert h0.dxftype() == 'HATCH'
     assert len(h0.paths) == 1
     edge_path = h0.paths[0]
     assert edge_path.PATH_TYPE == 'EdgePath'
     line, spline = edge_path.edges
     assert line.EDGE_TYPE == 'LineEdge'
     assert line.start == (0, 0)
     assert line.end == (4, 0)
     assert spline.EDGE_TYPE == 'SplineEdge'
     assert close_vectors(Vec3.generate(spline.control_points), [(4, 0),
                                                                 (3, 1),
                                                                 (1, 1),
                                                                 (0, 0)])
def test_weighted_point_evaluator(py_weval, cy_weval, t_vector):
    py_points = list(py_weval.points(t_vector))
    cy_points = list(cy_weval.points(t_vector))
    assert close_vectors(py_points, cy_points) is True
def test_open_arrow():
    a = open_arrow(3, 60)
    assert len(a) == 3
    assert close_vectors(a, [(-3, 1.5), (0, 0), (-3, -1.5)])
Exemple #11
0
def test_reversing_path_ctrl_vertices(p1):
    p2 = p1.reversed()
    assert close_vectors(p2.control_vertices(),
                         reversed(list(p1.control_vertices())))
Exemple #12
0
def test_reversing_one_curve4():
    p = Path()
    p.curve4_to((3, 0), (1, 1), (2, 1))
    p2 = list(p.reversed().control_vertices())
    assert close_vectors(p2, [(3, 0), (2, 1), (1, 1), (0, 0)])
Exemple #13
0
def test_reversing_one_line():
    p = Path()
    p.line_to((1, 0))
    p2 = list(p.reversed().control_vertices())
    assert close_vectors(p2, [(1, 0), (0, 0)])
def test_weighted_derivative_evaluator(py_weval, cy_weval, t_vector):
    py_ders = list(py_weval.derivatives(t_vector, 2))
    cy_ders = list(cy_weval.derivatives(t_vector, 2))
    for d1, d2 in zip(py_ders, cy_ders):
        assert close_vectors(d1, d2)
def test_square():
    sq = square(2)
    assert len(sq) == 4
    assert close_vectors(sq, [(0, 0), (2, 0), (2, 2), (0, 2)])
def test_box():
    b = box(3, 2)
    assert len(b) == 4
    assert close_vectors(b, [(0, 0), (3, 0), (3, 2), (0, 2)])
Exemple #17
0
def test_reversing_path_approx(p1):
    p2 = p1.reversed()
    v1 = list(p1.approximate())
    v2 = list(p2.approximate())
    assert close_vectors(v1, reversed(v2))
def test_closed_arrow():
    a = arrow2(3, 60, 45)
    assert len(a) == 4
    assert close_vectors(a, [(-3, 1.5), (0, 0), (-3, -1.5), (-1.5, 0)])
Exemple #19
0
def test_reverse(bezier):
    curve = bezier(DEFPOINTS2D)
    vertices = list(curve.approximate(10))
    rev_curve = curve.reverse()
    rev_vertices = list(rev_curve.approximate(10))
    assert close_vectors(reversed(vertices), rev_vertices)