def test_get_half_edge(self): # # Construct Cell # v1 = Vertex((0,0)) v2 = Vertex((1,0)) v3 = Vertex((0,1)) h12 = HalfEdge(v1, v2) h23 = HalfEdge(v2, v3) h31 = HalfEdge(v3, v1) # Check whether you get the right he's back hes = [h12, h23, h31] cell = Cell(hes) for i in range(3): self.assertEqual(cell.get_half_edge(i), hes[i])
def test_constructor(self): """ Constructor """ # # Triangle # v1 = Vertex((0,0)) v2 = Vertex((1,0)) v3 = Vertex((0,1)) h12 = HalfEdge(v1, v2) h23 = HalfEdge(v2, v3) h31 = HalfEdge(v3, v1) # Vertices not in order bad_list_1 = [h12, h31, h23] self.assertRaises(Exception, Cell, *[bad_list_1]) # Not a closed loop bad_list_2 = [h12, h23] self.assertRaises(Exception, Cell, *[bad_list_2]) triangle_half_edges = [h12, h23, h31] cell = Cell(triangle_half_edges) self.assertAlmostEqual(cell.area(),0.5) self.assertEqual(cell.n_vertices(),3) self.assertEqual(cell.n_half_edges(),3) half_edge = cell.get_half_edge(0) for i in range(3): self.assertEqual(half_edge.next(), triangle_half_edges[(i+1)%3]) half_edge = half_edge.next() # # Square # v4 = Vertex((1,1)) h24 = HalfEdge(v2,v4) h43 = HalfEdge(v4,v3) square_half_edges = [h12, h24, h43, h31] cell = Cell(square_half_edges) self.assertAlmostEqual(cell.area(),1) self.assertEqual(cell.n_vertices(),4) self.assertEqual(cell.n_half_edges(),4)