def test_make_twin(self): # # New HalfEdge # v1 = Vertex((0,0)) v2 = Vertex((2,2)) h12 = HalfEdge(v1,v2) h21 = h12.make_twin() self.assertIsNotNone(h12.twin()) self.assertIsNotNone(h21.twin()) self.assertEqual(h12.base(),h21.head()) self.assertEqual(h21.base(),h12.head())
def test_split(self): # Rectangle v1 = Vertex((0, 0)) v2 = Vertex((1, 0)) v3 = Vertex((1, 1)) v4 = Vertex((0, 1)) v5 = Vertex((2, 0)) v6 = Vertex((2, 1)) h12 = HalfEdge(v1, v2) h23 = HalfEdge(v2, v3) h34 = HalfEdge(v3, v4) h41 = HalfEdge(v4, v1) cell = QuadCell([h12, h23, h34, h41]) cell.split() self.assertTrue(cell.has_children()) # Check that interior half_edges are twinned child_0 = cell.get_child(0) child_1 = cell.get_child(1) self.assertEqual(child_0.get_half_edge(1).twin(), \ child_1.get_half_edge(3)) # Make another cell, check that it is a neighbor, and then split it h25 = HalfEdge(v2, v5) h56 = HalfEdge(v5, v6) h63 = HalfEdge(v6, v3) h32 = h23.make_twin() cell_1 = QuadCell([h25, h56, h63, h32]) # Check that they are neighbors self.assertEqual(cell_1.get_neighbors(h32), cell) # Child_s doesn't have a neighbor self.assertIsNone(child_1.get_neighbors(child_1.get_half_edge(1))) cell_1.split() # Now the child has a neighbor self.assertEqual(child_1.get_neighbors(child_1.get_half_edge(1)), cell_1.get_child(0))
def test_get_neighbors(self): # # HalfEdge pivot # # # Cell with no neighbors # v1 = Vertex((0,0)) v2 = Vertex((1,0)) v3 = Vertex((0,1)) h12 = HalfEdge(v1, v2) h23 = HalfEdge(v2, v3) h31 = HalfEdge(v3, v1) # # Make triangle # cell = Cell([h12, h23, h31]) # No neighbors self.assertIsNone(cell.get_neighbors(h12)) self.assertEqual(cell.get_neighbors(v1),[]) # Add a new neighboring triangle v4 = Vertex((1,1)) h24 = HalfEdge(v2, v4) h43 = HalfEdge(v4 ,v3) h32 = h23.make_twin() ncell_1 = Cell([h24, h43, h32]) # Make sure they are neighbors wrt halfedge self.assertEqual(cell.get_neighbors(h23),ncell_1) # Neighbors wrt vertices self.assertEqual(cell.get_neighbors(v2),[ncell_1]) self.assertEqual(cell.get_neighbors(v3),[ncell_1]) # # Add a third neighboring triangle # v5 = Vertex((1,2)) h34 = h43.make_twin() h45 = HalfEdge(v4, v5) h53 = HalfEdge(v5, v3) ncell_2 = Cell([h34, h45, h53]) # Check if it's a neighbor wrt halfedge self.assertEqual(ncell_1.get_neighbors(h43), ncell_2) # 2 Neighbors wrt v3 self.assertEqual(cell.get_neighbors(v3),[ncell_1, ncell_2]) self.assertEqual(ncell_1.get_neighbors(v3), [ncell_2, cell]) self.assertEqual(ncell_2.get_neighbors(v3), [cell, ncell_1]) # # Split h31 and make an illegal neighbor # v6 = Vertex((-1,0.5)) h31.split() h331 = h31.get_child(0) h133 = h331.make_twin() h36 = HalfEdge(v3, v6) h613 = HalfEdge(v6, h133.base()) ncell_3 = Cell([h133, h36, h613]) # No neighbors wrt shared edges self.assertIsNone(cell.get_neighbors(h31)) self.assertIsNone(ncell_3.get_neighbors(h133)) # Neighbors wrt vertices remain as they are. self.assertEqual(cell.get_neighbors(v3),[ncell_1, ncell_2]) self.assertEqual(ncell_1.get_neighbors(v3), [ncell_2, cell]) self.assertEqual(ncell_2.get_neighbors(v3), [cell, ncell_1]) self.assertEqual(ncell_3.get_neighbors(v3), [])