def test_append_empty(self): pl = Polyline() v = [] with raises(ValueError): pl.append_vertex(v) return
def test_append_one_vertex(self): pl = Polyline() v = [[1, 2]] pl.append_vertex(v) assert pl.nvertices == len(pl.vertices) == 1 assert len(pl.segment_lengths) == pl.nsegments == 0 assert pl.vertices[0, 0] == v[0][0] assert pl.vertices[0, 1] == v[0][1] return
def test_append_two_vertices(self): pl = Polyline() v = [[1, 2], [3, 4]] pl.append_vertex(v) assert pl.nvertices == len(pl.vertices) == 2 assert len(pl.segment_lengths) == pl.nsegments == 1 for i, vi in enumerate(v): assert pl.vertices[i, 0] == vi[0] assert pl.vertices[i, 1] == vi[1] assert pl.segment_lengths[0] == approx( norm(v[0][0], v[0][1], v[1][0], v[1][1])) return
def test_append_many_vertices(self): pl = Polyline() v = [[1, 2], [3, 4], [4, 5], [7, 8], [9, 10]] pl.append_vertex(v) assert pl.nvertices == len(pl.vertices) == len(v) assert len(pl.segment_lengths) == pl.nsegments == len(v) - 1 for i, vi in enumerate(v): assert pl.vertices[i, 0] == vi[0] assert pl.vertices[i, 1] == vi[1] if i < len(v) - 1: assert pl.segment_lengths[i] == approx( norm(vi[0], vi[1], v[i + 1][0], v[i + 1][1])) return