1# Copyright (c) 2019-2020 Manfred Moitzi
2# License: MIT License
3import pytest
4
5from ezdxf.entities.polyline import vertex_attribs, DXFVertex
6from ezdxf.math import Vec3
7from ezdxf.layouts import VirtualLayout
8
9def test_vertext_attribs_xy():
10    result = vertex_attribs((1, 2), format='xy')
11    assert result == {'location': Vec3(1, 2)}
12
13
14def test_vertext_attribs_xyb():
15    result = vertex_attribs((1, 2, .5), format='xyb')
16    assert result == {'location': Vec3(1, 2), 'bulge': 0.5}
17
18
19def test_vertext_attribs_xyseb():
20    result = vertex_attribs((1, 2, 3, 4, .5), format='xyseb')
21    assert result == {'location': Vec3(1, 2), 'bulge': 0.5, 'start_width': 3, 'end_width': 4}
22
23
24def test_vertext_attribs_vseb():
25    result = vertex_attribs(((1, 2), 3, 4, .5), format='vseb')
26    assert result == {'location': Vec3(1, 2), 'bulge': 0.5, 'start_width': 3, 'end_width': 4}
27
28
29def test_append_formatted_vertices():
30    msp = VirtualLayout()
31    p = msp.add_polyline2d([(1, 2, .5), (3, 4, .7)], format='xyb')
32    assert len(p) == 2
33    v1 = p.vertices[0]
34    assert v1.dxf.location == (1, 2)
35    assert v1.dxf.bulge == 0.5
36    v2 = p.vertices[1]
37    assert v2.dxf.location == (3, 4)
38    assert v2.dxf.bulge == 0.7
39
40
41def test_vertex_format():
42    v = DXFVertex.new(dxfattribs={'location': (1, 2, 3), 'bulge': 5, 'end_width': 7, 'start_width': 6})
43    assert v.format('xyz') == (1, 2, 3)
44    assert v.format('xyb') == (1, 2, 5)
45    assert v.format('vb') == ((1, 2, 3), 5)
46    assert v.format('se') == (6, 7)
47
48
49if __name__ == '__main__':
50    pytest.main([__file__])
51