def test_serialize(): Tout = Delaunay2(left_edge, right_edge) Tout.insert(pts) out = Tout.serialize() Tin = Delaunay2() Tin.deserialize(pts, *out) print(Tout.num_cells, Tin.num_cells) assert (Tout.num_verts == Tin.num_verts) assert (Tout.num_cells == Tin.num_cells)
def test_insert(): # without duplicates T = Delaunay2(left_edge, right_edge) T.insert(pts) assert (T.is_valid()) # with duplicates T = Delaunay2(left_edge, right_edge) T.insert(pts_dup) assert (T.is_valid())
def test_io(): fname = 'test_io2348_2.dat' Tout = Delaunay2(left_edge, right_edge) Tout.insert(pts) Tout.write_to_file(fname) Tin = Delaunay2() Tin.read_from_file(fname) assert (Tout.num_verts == Tin.num_verts) assert (Tout.num_cells == Tin.num_cells) os.remove(fname)
def setup_param(self): self._func = Delaunay2 self.param_runs = [ ((pts,), {}), ((pts_dup,), {}), ] self.T = Delaunay2() self.T.insert(pts) self.Tdup = Delaunay2() self.Tdup.insert(pts_dup) self.pts = pts self.pts_dup = pts_dup
def test_clear(): T = Delaunay2(left_edge, right_edge) T.insert(pts) T.clear() print(T.num_finite_verts, T.num_cells) assert (T.num_finite_verts == 0) assert (T.num_cells == 0)
def test_vertices(): T = Delaunay2() T.insert(pts) v = T.vertices assert(v.shape[0] == pts.shape[0]) assert(v.shape[1] == pts.shape[1]) assert(np.allclose(pts, v))
def test_outgoing_points(): T = Delaunay2(left_edge, right_edge) T.insert(pts) le = np.array([[-2, -2], [-1, -1], [+0, 0], [+1, 1]], 'float64') re = np.array([[-1, -1], [+0, 0], [+1, 1], [+2, 2]], 'float64') out = T.outgoing_points(le, re) assert (len(out) == le.shape[0])
def test_finite_cells(): T = Delaunay2(left_edge, right_edge) T.insert(pts) count = 0 for c in T.finite_cells: assert ((not c.is_infinite())) count += 1 assert (count == T.num_stored_cells)
def test_io(self): fname = 'test_io2348_2.dat' Tout = self.T Tout.write_to_file(fname) Tin = Delaunay2.from_file(fname) assert(Tout.num_verts == Tin.num_verts) assert(Tout.num_cells == Tin.num_cells) os.remove(fname)
def test_plot2D(): fname_test = "test_plot2D.png" T = Delaunay2() T.insert(pts2) axs = T.plot(plotfile=fname_test, title='Test') os.remove(fname_test) # T.plot(axs=axs) del axs
def test_get_conflicts(): T = Delaunay2() T.insert(pts) v = T.get_vertex(0) c = v.incident_cells()[0] p = c.circumcenter cells = T.get_conflicts(p, c) print(len(cells))
def test_num_edges(): # without duplicates T = Delaunay2(left_edge, right_edge) T.insert(pts) print(T.num_finite_edges, T.num_infinite_edges, T.num_edges) assert (T.num_finite_edges == nedges_fin) assert (T.num_infinite_edges == nedges_inf) assert (T.num_edges == nedges) assert (T.num_stored_edges == T.num_sheets_total * nedges) # with duplicates T = Delaunay2(left_edge, right_edge) T.insert(pts_dup) print(T.num_finite_edges, T.num_infinite_edges, T.num_edges) assert (T.num_finite_edges == nedges_fin) assert (T.num_infinite_edges == nedges_inf) assert (T.num_edges == nedges) assert (T.num_stored_edges == T.num_sheets_total * nedges)
def test_get_conflicts_and_boundary(): T = Delaunay2() T.insert(pts) v = T.get_vertex(0) c = v.incident_cells()[0] p = c.circumcenter cells, edges = T.get_conflicts_and_boundary(p, c) print(len(cells), len(edges))
def test_line_walk(): T = Delaunay2() T.insert(pts) p1 = np.array([-1, -1], 'float64') p2 = np.array([+1, +1], 'float64') x = T.line_walk(p1, p2) print(len(x)) assert(len(x) == 6)
def test_get_boundary_of_conflicts(): T = Delaunay2(left_edge, right_edge) T.insert(pts) v = T.get_vertex(0) c = v.incident_cells()[0] p = c.circumcenter edges = T.get_boundary_of_conflicts(p, c) print(len(edges))
def test_finite_verts(): T = Delaunay2(left_edge, right_edge) T.insert(pts) count = 0 for v in T.finite_verts: assert ((not v.is_infinite())) count += 1 assert (count == T.num_stored_verts)
def test_finite_edges(): T = Delaunay2(left_edge, right_edge) T.insert(pts) count = 0 for e in T.finite_edges: assert ((not e.is_infinite())) count += 1 print(count) assert (count == T.num_stored_edges)
def test_mirror(): T = Delaunay2(left_edge, right_edge) T.insert(pts) for c in T.all_cells: idx = 0 i2 = T.mirror_index(c, idx) assert (c == c.neighbor(idx).neighbor(i2)) v2 = T.mirror_vertex(c, idx) assert (v2 == c.neighbor(idx).vertex(i2))
def test_flippable(): T = Delaunay2() T.insert(pts) for c in T.all_cells: T.flip(c, 0) print(T.num_edges, nedges) assert(T.num_edges == nedges) for e in T.all_edges: e.flip() print(T.num_edges, nedges)
def test_cell_incident_cells(): T = Delaunay2() T.insert(pts) count = 0 for v in T.all_cells: c0 = 0 for e in v.incident_cells(): c0 += 1 count += 1 print(c0) print(count) assert(count == 42)
def test_cell_incident_edges(): T = Delaunay2(left_edge, right_edge) T.insert(pts) count = 0 for v in T.all_cells: c0 = 0 for e in v.incident_edges(): c0 += 1 count += 1 print(c0) print(count) assert (count == 432)
def test_vert_incident_verts(): T = Delaunay2(left_edge, right_edge) T.insert(pts) count = 0 for v in T.all_verts: c0 = 0 for c in v.incident_vertices(): c0 += 1 count += 1 print(v.index, c0) print(count) assert (count == 432)
def test_move(): T = Delaunay2() T.insert(pts) v0 = T.get_vertex(0) new_pos = np.zeros(2, 'float64') v = T.move(v0, new_pos) assert(np.allclose(v.point, new_pos)) assert(np.allclose(v0.point, new_pos)) v1 = T.get_vertex(1) v = T.move(v1, new_pos) assert(np.allclose(v.point, new_pos)) assert(T.num_verts == (nverts-1))
def test_edge_incident_edges(): T = Delaunay2() T.insert(pts) count = 0 for v in T.all_edges: c0 = 0 for e in v.incident_edges(): c0 += 1 count += 1 print(c0) print(count) assert(count == 156)
def test_vert_incident_cells(): T = Delaunay2() T.insert(pts) count = 0 for v in T.all_verts: c0 = 0 for c in v.incident_cells(): c0 += 1 count += 1 print(v.index, c0) print(count) assert(count == 42)
def test_flip(): T = Delaunay2() T.insert(pts) for c in T.all_cells: out = T.flip(c, 0) assert(out) print(T.num_edges, nedges) assert(T.num_edges == nedges) for e in T.all_edges: out = e.flip() assert(out) print(T.num_edges, nedges)
def test_all_cells(): T = Delaunay2(left_edge, right_edge) T.insert(pts) count_fin = count_inf = 0 for c in T.all_cells: if c.is_infinite(): count_inf += 1 else: count_fin += 1 count = count_fin + count_inf assert (count_fin == T.num_stored_cells) assert (count_inf == T.num_infinite_cells) assert (count == T.num_stored_cells)
def test_locate(): T = Delaunay2(left_edge, right_edge) T.insert(pts) for c in T.finite_cells: p = c.center print('{}\n{}\n{}'.format(c, p, T.locate(p))) assert (c == T.locate(p, c)) assert (c == T.locate(p)) assert (c.vertex(0) == T.locate(c.vertex(0).point)) assert (c.vertex(0) == T.locate(c.vertex(0).point, c)) # assert(c.edge(0) == T.locate(c.edge(0).midpoint)) # assert(c.edge(0) == T.locate(c.edge(0).midpoint, c)) break
def test_mirror(): T = Delaunay2() T.insert(pts) for e in T.all_edges: e2 = T.mirror_edge(e) del(e2) break for c in T.all_cells: idx = 0 i2 = T.mirror_index(c, idx) assert(c == c.neighbor(idx).neighbor(i2)) v2 = T.mirror_vertex(c, idx) assert(v2 == c.neighbor(idx).vertex(i2))
def test_move_if_no_collision(): T = Delaunay2() T.insert(pts) v0 = T.get_vertex(0) new_pos = np.zeros(2, 'float64') v = T.move_if_no_collision(v0, new_pos) assert(np.allclose(v.point, new_pos)) assert(np.allclose(v0.point, new_pos)) v1 = T.get_vertex(1) v = T.move_if_no_collision(v1, new_pos) assert(np.allclose(v.point, new_pos)) assert(np.allclose(v1.point, pts[1, :])) assert(T.num_verts == nverts)