Esempio n. 1
0
def test_bezire4p_tangents_2d():
    dbcurve = Bezier4P(DEFPOINTS2D)
    for index, epoint in enumerate(TANGENTS2D):
        etx, ety = epoint
        d1 = dbcurve.tangent(index * .1)
        assert isclose(etx, d1[0])
        assert isclose(ety, d1[1])
Esempio n. 2
0
def test_bezier4p_points_2d():
    bcurve = Bezier4P(DEFPOINTS2D)
    for index, epoint in enumerate(POINTS2D):
        epx, epy = epoint
        rpx, rpy, rpz = bcurve.point(index * .1)
        assert isclose(epx, rpx) is True
        assert isclose(epy, rpy) is True
Esempio n. 3
0
 def approximate(self) -> Iterable[Vector]:
     control_points = [
         self.start,
         self.start + self.start_tangent,
         self.end + self.end_tangent,
         self.end,
     ]
     bezier = Bezier4P(control_points)
     return bezier.approximate(self.segments)
Esempio n. 4
0
def test_bezier4p_tangents_2d():
    dbcurve = Bezier4P(DEFPOINTS2D)
    for index, chk in enumerate(TANGENTS2D):
        assert dbcurve.tangent(index * .1).isclose(chk)
Esempio n. 5
0
def test_bezier4p_points_2d():
    bcurve = Bezier4P(DEFPOINTS2D)
    for index, chk in enumerate(POINTS2D):
        assert bcurve.point(index * .1).isclose(chk)
Esempio n. 6
0
def test_reverse():
    curve = Bezier4P(DEFPOINTS2D)
    vertices = list(curve.approximate(10))
    rev_curve = curve.reverse()
    rev_vertices = list(rev_curve.approximate(10))
    assert list(reversed(vertices)) == rev_vertices
Esempio n. 7
0
def test_2d_tangent_computation():
    dbcurve = Bezier4P(DEFPOINTS2D)
    for index, chk in enumerate(Vec2.generate(TANGENTS2D)):
        assert dbcurve.tangent(index * .1).isclose(chk)
Esempio n. 8
0
def test_objects_are_immutable():
    curve = Bezier4P(DEFPOINTS3D)
    with pytest.raises(TypeError):
        curve.control_points[0] = (1, 2, 3)
Esempio n. 9
0
def test_accepts_2d_points():
    curve = Bezier4P(DEFPOINTS2D)
    for index, chk in enumerate(Vec2.generate(POINTS2D)):
        assert curve.point(index * .1).isclose(chk)
Esempio n. 10
0
def test_transform_returns_always_3d_curves():
    curve = Bezier4P(DEFPOINTS2D)
    new = curve.transform(Matrix44.translate(1, 2, 3))
    assert len(new.control_points[0]) == 3
Esempio n. 11
0
def test_transform_interface():
    curve = Bezier4P(DEFPOINTS3D)
    new = curve.transform(Matrix44.translate(1, 2, 3))
    assert new.control_points[0] == Vector(DEFPOINTS3D[0]) + (1, 2, 3)
    assert new.control_points[0] != curve.control_points[
        0], 'expected a new object'
Esempio n. 12
0
def test_flattening():
    curve = Bezier4P([(0, 0), (1, 1), (2, -1), (3, 0)])
    assert len(list(curve.flattening(1.0, segments=4))) == 5
    assert len(list(curve.flattening(0.1, segments=4))) == 7
Esempio n. 13
0
def test_approximate():
    curve = Bezier4P([(0, 0), (0, 1), (1, 1), (1, 0)])
    with pytest.raises(ValueError):
        list(curve.approximate(0))
    assert list(curve.approximate(1)) == [(0, 0), (1, 0)]
    assert list(curve.approximate(2)) == [(0, 0), (0.5, 0.75), (1, 0)]