Ignore:
Timestamp:
May 7, 2010, 4:00:13 PM (14 years ago)
Author:
hudson
Message:

Refactored geometry classes to live in their own folder.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/fit_interpolate/test_meshquad.py

    r7709 r7711  
    22import numpy as num
    33
    4 from quad import AABB, Cell, build_quadtree
     4from anuga.geometry.aabb import AABB
     5from anuga.geometry.quad import Cell
     6from anuga.fit_interpolate.search_functions import MeshQuadtree
    57from anuga.abstract_2d_finite_volumes.general_mesh import General_mesh as Mesh
    68
     
    1618    def tearDown(self):
    1719        pass
    18 
    19     def test_AABB_contains(self):
    20         box = AABB(1, 21, 1, 11)
    21         assert box.contains(10, 5)
    22         assert box.contains(1, 1)
    23         assert box.contains(20, 6)
    24         assert not box.contains(-1, -1)
    25         assert not box.contains(5, 70)
    26         assert not box.contains(6, -70)
    27         assert not box.contains(-1, 6)
    28         assert not box.contains(50, 6)       
    29        
    30     def test_AABB_split_vert(self):
    31         parent = AABB(1, 21, 1, 11)
    32        
    33         child1, child2 = parent.split(0.6)
    34 
    35         self.assertEqual(child1.xmin, 1)
    36         self.assertEqual(child1.xmax, 13)
    37         self.assertEqual(child1.ymin, 1)
    38         self.assertEqual(child1.ymax, 11)
    39        
    40         self.assertEqual(child2.xmin, 9)
    41         self.assertEqual(child2.xmax, 21)
    42         self.assertEqual(child2.ymin, 1)
    43         self.assertEqual(child2.ymax, 11)   
    44 
    45     def test_AABB_split_horiz(self):
    46         parent = AABB(1, 11, 1, 41)
    47        
    48         child1, child2 = parent.split(0.6)
    49 
    50         self.assertEqual(child1.xmin, 1)
    51         self.assertEqual(child1.xmax, 11)
    52         self.assertEqual(child1.ymin, 1)
    53         self.assertEqual(child1.ymax, 25)
    54        
    55         self.assertEqual(child2.xmin, 1)
    56         self.assertEqual(child2.xmax, 11)
    57         self.assertEqual(child2.ymin, 17)
    58         self.assertEqual(child2.ymax, 41)         
    59        
    60     def test_add_data(self):
    61         cell = Cell(AABB(0,10, 0,5))
    62         cell.insert([(AABB(1,3, 1, 3), 111), (AABB(8,9, 1, 2), 222),  \
    63                      (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])
    64 
    65         result = cell.retrieve()
    66         assert type(result) in [types.ListType,types.TupleType],\
    67                             'should be a list'
    68 
    69         self.assertEqual(len(result),4)
    70        
    71     def test_search(self):
    72         test_region = (AABB(8,9, 1, 2), 222)
    73         cell = Cell(AABB(0,10, 0,5))
    74         cell.insert([(AABB(1,3, 1, 3), 111), test_region,  \
    75                      (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])
    76 
    77         result =  cell.search(x = 8.5, y = 1.5, get_vertices=True)
    78         assert type(result) in [types.ListType,types.TupleType],\
    79                             'should be a list'
    80         self.assertEqual(result, [test_region], 'only 1 point should intersect')
    81 
    82 
    83     def test_clear_1(self):
    84         cell = Cell(AABB(0,10, 0,5))   
    85         cell.insert([(AABB(1,3, 1, 3), 111), (AABB(8,9, 1, 2), 222),  \
    86                      (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])
    87                      
    88         assert len(cell.retrieve()) == 4
    89         cell.clear()
    90 
    91         assert len(cell.retrieve()) == 0
    9220
    9321    def test_build_quadtree(self):
     
    10937        mesh = Mesh(points, vertices)
    11038   
    111         Q = build_quadtree(mesh)
     39        Q = MeshQuadtree(mesh)
    11240        #Q.show()
    11341        #print Q.count()
     
    13866
    13967        #This was causing round off error
    140         Q = build_quadtree(mesh)
     68        Q = MeshQuadtree(mesh)
    14169       
    14270    def NOtest_interpolate_one_point_many_triangles(self):
     
    184112        mesh = Mesh(vertices, triangles)
    185113        try:
    186             Q = build_quadtree(mesh, max_points_per_cell = 9)
     114            Q = MeshQuadtree(mesh, max_points_per_cell = 9)
    187115        except RuntimeError:
    188116            pass
     
    207135        mesh = Mesh(points, vertices)
    208136
    209         Q = build_quadtree(mesh)
     137        Q = MeshQuadtree(mesh)
    210138        results = Q.search(4.5, 3)
    211139        assert len(results) == 1
     
    214142        self.assertEqual(len(results),1)
    215143        self.assertEqual(results[0], 2)
     144       
     145    def NOtest_get_parent():
     146        """ Get a child's parent.
     147        """
     148        cell = Cell(AABB(0, 6, 0, 6), 'cell')
     149
     150        p0 = [2,1]
     151        p1 = [4,1]
     152        p2 = [4,4]
     153        p3 = [2,4]
     154        p4 = [5,4]
     155
     156        points = [p0,p1,p2, p3, p4]
     157        vertices = [[0,1,2],[0,2,3],[1,4,2]]
     158
     159        mesh = Mesh(points, vertices)
     160
     161        Q = MeshQuadtree(mesh)
     162        results = Q.search(4.5, 3)
     163        assert len(results) == 1
     164        self.assertEqual(results[0], 2)
     165        results = Q.search(5,4.)
     166        self.assertEqual(len(results),1)
     167        self.assertEqual(results[0], 2)     
    216168################################################################################
    217169
Note: See TracChangeset for help on using the changeset viewer.