def test_matrix44_insert(): insert = Insert.new(handle='ABBA', owner='0', dxfattribs={ 'insert': (1, 2, 3), }) m = insert.matrix44() assert m.transform((0, 0, 0)) == (1, 2, 3) assert m.transform_direction((1, 0, 0)) == (1, 0, 0)
def test_insert_transformation_error(): insert = Insert.new(dxfattribs={ 'name': 'AXIS', 'insert': (0, 0, 0), 'rotation': 45, }) m = Matrix44.scale(0.5, 1, 1) with pytest.raises(InsertTransformationError): insert.transform(m)
def test_insert_to_code(): from ezdxf.entities.insert import Insert entity = Insert.new(handle='ABBA', owner='0', dxfattribs={ 'name': 'block1', 'insert': (2, 3, 4), }) new_entity = translate_to_code_and_execute(entity) for name in ('name', 'insert'): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
def test_has_scaling(): entity = Insert.new(handle='ABBA', owner='0', dxfattribs={'xscale': 2}) assert entity.has_scaling is True assert entity.has_uniform_scaling is False entity = Insert.new(handle='ABBA', owner='0', dxfattribs={'yscale': 2}) assert entity.has_scaling is True assert entity.has_uniform_scaling is False entity = Insert.new(handle='ABBA', owner='0', dxfattribs={'zscale': 2}) assert entity.has_scaling is True assert entity.has_uniform_scaling is False # reflections are under control, so (-2, 2, 2) is a uniform scaling entity = Insert.new(handle='ABBA', owner='0', dxfattribs={ 'xscale': -2, 'yscale': 2, 'zscale': 2, }) assert entity.has_uniform_scaling is True
def test_matrix44_direction(): insert = Insert.new(handle='ABBA', owner='0', dxfattribs={ 'insert': (1, 2, 3), 'xscale': 2, }) m = insert.matrix44() assert m.transform((1, 0, 0)) == (3, 2, 3) assert m.transform_direction((1, 0, 0)) == (2, 0, 0), \ 'only scaling has to be applied for directions'
def test_matrix44_scaled(): insert = Insert.new(handle='ABBA', owner='0', dxfattribs={ 'xscale': 2, 'yscale': 3, 'zscale': 4, }) m = insert.matrix44() assert m.transform((1, 1, 1)) == (2, 3, 4) assert m.transform_direction((1, 0, 0)) == ( 2, 0, 0), 'scaling has to be applied for directions'
def test_matrix44_rotation(): insert = Insert.new(handle='ABBA', owner='0', dxfattribs={ 'insert': (0, 0, 0), 'rotation': 90, }) m = insert.matrix44() assert list(m.transform_vertices([(1, 0, 0), (0, 0, 1)])) == [(0, 1, 0), (0, 0, 1)] assert m.transform_direction((1, 0, 0)) == (0, 1, 0)
def test_matrix44_rotation(): insert = Insert.new(handle='ABBA', owner='0', dxfattribs={ 'insert': (0, 0, 0), 'rotation': 90, }) m = insert.matrix44() for v1, v2 in zip( m.transform_vertices([(1, 0, 0), (0, 0, 1)]), [(0, 1, 0), (0, 0, 1)]): assert v1.isclose(v2) assert m.transform_direction((1, 0, 0)).isclose((0, 1, 0))
def test_matrix44_insert(): insert = Insert.new( handle="ABBA", owner="0", dxfattribs={ "insert": (1, 2, 3), }, ) m = insert.matrix44() assert m.transform((0, 0, 0)) == (1, 2, 3) assert m.transform_direction((1, 0, 0)) == (1, 0, 0)
def test_has_scaling(): entity = Insert.new(handle="ABBA", owner="0", dxfattribs={"xscale": 2}) assert entity.has_scaling is True assert entity.has_uniform_scaling is False entity = Insert.new(handle="ABBA", owner="0", dxfattribs={"yscale": 2}) assert entity.has_scaling is True assert entity.has_uniform_scaling is False entity = Insert.new(handle="ABBA", owner="0", dxfattribs={"zscale": 2}) assert entity.has_scaling is True assert entity.has_uniform_scaling is False # reflections are under control, so (-2, 2, 2) is a uniform scaling entity = Insert.new( handle="ABBA", owner="0", dxfattribs={ "xscale": -2, "yscale": 2, "zscale": 2, }, ) assert entity.has_uniform_scaling is True
def test_add_virtual_insert_with_attribs_to_layout(doc): doc.blocks.new('TestAddVirtualInsert') msp = doc.modelspace() insert = Insert.new(dxfattribs={'name': 'TestAddVirtualInsert'}) insert.add_attrib('TAG', 'TEXT', (0, 0)) msp.add_entity(insert) assert factory.is_bound(insert, doc) is True assert factory.is_bound(insert.seqend, doc) is True, \ 'SEQEND must be bound to document' assert insert.attribs_follow is True assert factory.is_bound(insert.attribs[0], doc) is True, \ 'ATTRIB must be bound to document'
def test_insert_to_code(): from ezdxf.entities.insert import Insert entity = Insert.new( handle="ABBA", owner="0", dxfattribs={ "name": "block1", "insert": (2, 3, 4), }, ) new_entity = translate_to_code_and_execute(entity) for name in ("name", "insert"): assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
def test_add_virtual_insert_with_attribs_to_layout(doc): doc.blocks.new("TestAddVirtualInsert") msp = doc.modelspace() insert = Insert.new(dxfattribs={"name": "TestAddVirtualInsert"}) insert.add_attrib("TAG", "TEXT", (0, 0)) msp.add_entity(insert) assert factory.is_bound(insert, doc) is True assert (factory.is_bound(insert.seqend, doc) is True), "SEQEND must be bound to document" assert insert.attribs_follow is True assert (factory.is_bound(insert.attribs[0], doc) is True), "ATTRIB must be bound to document"
def test_matrix44_rotation(): insert = Insert.new( handle="ABBA", owner="0", dxfattribs={ "insert": (0, 0, 0), "rotation": 90, }, ) m = insert.matrix44() for v1, v2 in zip(m.transform_vertices([(1, 0, 0), (0, 0, 1)]), [(0, 1, 0), (0, 0, 1)]): assert v1.isclose(v2) assert m.transform_direction((1, 0, 0)).isclose((0, 1, 0))
def test_matrix44_direction(): insert = Insert.new( handle="ABBA", owner="0", dxfattribs={ "insert": (1, 2, 3), "xscale": 2, }, ) m = insert.matrix44() assert m.transform((1, 0, 0)) == (3, 2, 3) assert m.transform_direction((1, 0, 0)) == ( 2, 0, 0, ), "only scaling has to be applied for directions"
def test_matrix44_scaled(): insert = Insert.new( handle="ABBA", owner="0", dxfattribs={ "xscale": 2, "yscale": 3, "zscale": 4, }, ) m = insert.matrix44() assert m.transform((1, 1, 1)) == (2, 3, 4) assert m.transform_direction((1, 0, 0)) == ( 2, 0, 0, ), "scaling has to be applied for directions"
def test_new_constructor(): insert = Insert.new(handle='ABBA', owner='0', dxfattribs={ 'color': '7', 'insert': (1, 2, 3), }) assert insert.is_virtual is True, 'Has no assigned document' assert insert.dxf.layer == '0' assert insert.dxf.color == 7 assert insert.dxf.linetype == 'BYLAYER' assert insert.dxf.insert == (1, 2, 3) assert insert.dxf.insert.x == 1, 'is not Vec3 compatible' assert insert.dxf.insert.y == 2, 'is not Vec3 compatible' assert insert.dxf.insert.z == 3, 'is not Vec3 compatible' assert insert.has_scaling is False assert insert.has_uniform_scaling is True # can set DXF R2007 value insert.dxf.shadow_mode = 1 assert insert.dxf.shadow_mode == 1
def test_new_constructor(): insert = Insert.new( handle="ABBA", owner="0", dxfattribs={ "color": "7", "insert": (1, 2, 3), }, ) assert insert.is_virtual is True, "Has no assigned document" assert insert.dxf.layer == "0" assert insert.dxf.color == 7 assert insert.dxf.linetype == "BYLAYER" assert insert.dxf.insert == (1, 2, 3) assert insert.dxf.insert.x == 1, "is not Vec3 compatible" assert insert.dxf.insert.y == 2, "is not Vec3 compatible" assert insert.dxf.insert.z == 3, "is not Vec3 compatible" assert insert.has_scaling is False assert insert.has_uniform_scaling is True # can set DXF R2007 value insert.dxf.shadow_mode = 1 assert insert.dxf.shadow_mode == 1
def test_matrix44_no_transform(): insert = Insert.new(handle='ABBA', owner='0') m = insert.matrix44() assert m.transform((0, 0, 0)) == (0, 0, 0) assert m.transform_direction((1, 0, 0)) == (1, 0, 0)