def test_default_new(): entity = Spline.new( handle="ABBA", owner="0", dxfattribs={ "color": 7, "flags": 4, "degree": 4, "knot_tolerance": 42, "control_point_tolerance": 43, "fit_tolerance": 44, "start_tangent": (1, 2, 3), "end_tangent": (4, 5, 6), "extrusion": (7, 8, 9), }, ) assert entity.dxf.layer == "0" assert entity.dxf.color == 7 assert entity.dxf.flags == 4 assert entity.dxf.degree == 4 assert entity.dxf.knot_tolerance == 42 assert entity.dxf.control_point_tolerance == 43 assert entity.dxf.fit_tolerance == 44 assert entity.dxf.start_tangent == (1, 2, 3) assert entity.dxf.end_tangent == (4, 5, 6) assert entity.dxf.extrusion == (7, 8, 9)
def test_spline_to_code(): from ezdxf.entities.spline import Spline entity = Spline.new( handle="ABBA", owner="0", dxfattribs={ "color": "7", "degree": 3, }, ) entity.fit_points = [(1, 2, 0), (4, 3, 0), (7, 8, 0)] entity.control_points = [(1, 2, 0), (4, 3, 0), (7, 8, 0)] entity.knots = [1, 2, 3, 4, 5, 6, 7] entity.weights = [1.0, 2.0, 3.0] new_entity = translate_to_code_and_execute(entity) for name in ( "color", "n_knots", "n_control_points", "n_fit_points", "degree", ): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name) assert new_entity.knots == entity.knots assert new_entity.control_points.values == entity.control_points.values assert new_entity.fit_points.values == entity.fit_points.values assert new_entity.weights == entity.weights
def test_load_from_text(): entity = Spline.from_text(SPLINE) assert entity.dxf.layer == "0" assert entity.dxf.color == 256, "default color is 256 (by layer)" assert entity.dxf.extrusion == (0, 0, 1) assert entity.dxf.flags == 0 assert entity.dxf.degree == 3 assert entity.dxf.n_knots == 0 assert entity.dxf.n_control_points == 0 assert entity.dxf.n_fit_points == 0
def test_from_arc(): from ezdxf.entities import Arc spline = Spline.from_arc(Arc.new(dxfattribs={ 'center': (1, 1), 'radius': 2, 'start_angle': 30, # degrees 'end_angle': 150, 'layer': 'arc', })) assert spline.dxf.layer == 'arc' assert spline.dxf.degree == 2 assert len(spline.control_points) > 2 assert len(spline.weights) > 2 assert len(spline.fit_points) == 0 assert len(spline.knots) == required_knot_values(len(spline.control_points), spline.dxf.degree + 1)
def test_from_circle(): from ezdxf.entities import Circle spline = Spline.from_arc(Circle.new(dxfattribs={ 'center': (1, 1), 'radius': 2, 'layer': 'circle', })) assert spline.dxf.handle is None assert spline.dxf.owner is None assert spline.dxf.layer == 'circle' assert spline.dxf.degree == 2 assert len(spline.control_points) > 2 assert len(spline.weights) > 2 assert len(spline.fit_points) == 0 assert len(spline.knots) == required_knot_values(len(spline.control_points), spline.dxf.degree + 1)
def test_from_ellipse(): from ezdxf.entities import Ellipse spline = Spline.from_arc(Ellipse.new(dxfattribs={ 'center': (1, 1), 'major_axis': (2, 0), 'ratio': 0.5, 'start_param': 0.5, # radians 'end_param': 3, 'layer': 'ellipse', })) assert spline.dxf.layer == 'ellipse' assert spline.dxf.degree == 2 assert len(spline.control_points) > 2 assert len(spline.weights) > 2 assert len(spline.fit_points) == 0 assert len(spline.knots) == required_knot_values(len(spline.control_points), spline.dxf.degree + 1)
def test_spline_transform_interface(): spline = Spline() spline.set_uniform([(1, 0, 0), (3, 3, 0), (6, 0, 1)]) spline.dxf.start_tangent = Vec3(1, 0, 0) spline.dxf.end_tangent = Vec3(2, 0, 0) spline.dxf.extrusion = Vec3(3, 0, 0) spline.transform(Matrix44.translate(1, 2, 3)) assert spline.control_points[0] == (2, 2, 3) # direction vectors are not transformed by translation assert spline.dxf.start_tangent == (1, 0, 0) assert spline.dxf.end_tangent == (2, 0, 0) assert spline.dxf.extrusion == (3, 0, 0)
def test_spline_to_code(): from ezdxf.entities.spline import Spline entity = Spline.new(handle='ABBA', owner='0', dxfattribs={ 'color': '7', 'degree': 3, }) entity.fit_points = [(1, 2, 0), (4, 3, 0), (7, 8, 0)] entity.control_points = [(1, 2, 0), (4, 3, 0), (7, 8, 0)] entity.knots = [1, 2, 3, 4, 5, 6, 7] entity.weights = [1., 2., 3.] new_entity = translate_to_code_and_execute(entity) for name in ('color', 'n_knots', 'n_control_points', 'n_fit_points', 'degree'): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name) assert new_entity.knots == entity.knots assert new_entity.control_points.values == entity.control_points.values assert new_entity.fit_points.values == entity.fit_points.values assert new_entity.weights == entity.weights
def test_from_arc(): from ezdxf.entities import Arc spline = Spline.from_arc( Arc.new( dxfattribs={ "center": (1, 1), "radius": 2, "start_angle": 30, # degrees "end_angle": 150, "layer": "arc", })) assert spline.dxf.layer == "arc" assert spline.dxf.degree == 2 assert len(spline.control_points) > 2 assert len(spline.weights) > 2 assert len(spline.fit_points) == 0 assert len(spline.knots) == required_knot_values( len(spline.control_points), spline.dxf.degree + 1)
def test_from_ellipse(): from ezdxf.entities import Ellipse spline = Spline.from_arc( Ellipse.new( dxfattribs={ "center": (1, 1), "major_axis": (2, 0), "ratio": 0.5, "start_param": 0.5, # radians "end_param": 3, "layer": "ellipse", })) assert spline.dxf.layer == "ellipse" assert spline.dxf.degree == 2 assert len(spline.control_points) > 2 assert len(spline.weights) > 2 assert len(spline.fit_points) == 0 assert len(spline.knots) == required_knot_values( len(spline.control_points), spline.dxf.degree + 1)
def test_default_new(): entity = Spline.new(handle='ABBA', owner='0', dxfattribs={ 'color': 7, 'flags': 4, 'degree': 4, 'knot_tolerance': 42, 'control_point_tolerance': 43, 'fit_tolerance': 44, 'start_tangent': (1, 2, 3), 'end_tangent': (4, 5, 6), 'extrusion': (7, 8, 9), }) assert entity.dxf.layer == '0' assert entity.dxf.color == 7 assert entity.dxf.flags == 4 assert entity.dxf.degree == 4 assert entity.dxf.knot_tolerance == 42 assert entity.dxf.control_point_tolerance == 43 assert entity.dxf.fit_tolerance == 44 assert entity.dxf.start_tangent == (1, 2, 3) assert entity.dxf.end_tangent == (4, 5, 6) assert entity.dxf.extrusion == (7, 8, 9)
def test_write_dxf(): entity = Spline.from_text(SPLINE2) result = TagCollector.dxftags(entity) expected = basic_tags_from_text(SPLINE2) assert cmp_tags(result, expected, abs_tol=1e-4) == 0
def test_default_init(): entity = Spline() assert entity.dxftype() == "SPLINE" assert entity.dxf.handle is None assert entity.dxf.owner is None
def test_from_line_with_type_error(): from ezdxf.entities import Line with pytest.raises(TypeError): Spline.from_arc(Line.new())
def test_ignore_invalid_tangent_values_at_loading_stage(): spline = Spline.from_text(SPLINE_INVALID_TANGENT) assert spline.dxf.hasattr("start_tangent") is False assert spline.dxf.hasattr("end_tangent") is False
def spline(): return Spline.from_text(SPLINE)