Changeset 7714


Ignore:
Timestamp:
May 11, 2010, 11:31:16 AM (14 years ago)
Author:
hudson
Message:

Minor refactorings and optimisations in quadtree search code

Location:
anuga_core/source/anuga
Files:
4 edited

Legend:

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

    r7713 r7714  
    7272            return True, sigma0, sigma1, sigma2, k
    7373
    74     # search to bottom of tree from last found leaf
    7574    branch = last_triangle[0][1]
    7675   
    7776    if branch == -10:
    7877        branch = root   
    79    
    80     tri_data = branch.search(x[0], x[1])
     78
     79    # test neighbouring tris
     80    tri_data = branch.test_leaves(x)
     81    triangles = _trilist_from_data(mesh, tri_data)           
     82    element_found, sigma0, sigma1, sigma2, k = \
     83                _search_triangles_of_vertices(triangles, x)
     84    if element_found:
     85        return True, sigma0, sigma1, sigma2, k       
     86
     87    # search to bottom of tree from last found leaf   
     88    tri_data = branch.search(x)
    8189    triangles = _trilist_from_data(mesh, tri_data)           
    8290    element_found, sigma0, sigma1, sigma2, k = \
     
    95103           
    96104        for sibling in siblings:
    97             tri_data = sibling.search(x[0], x[1])
     105            tri_data = sibling.search(x)
    98106            triangles = _trilist_from_data(mesh, tri_data)           
    99107            element_found, sigma0, sigma1, sigma2, k = \
     
    104112        branch = branch.parent
    105113        if branch:
    106             tri_data = branch.test_leaves(x[0], x[1])
     114            tri_data = branch.test_leaves(x)
    107115            triangles = _trilist_from_data(mesh, tri_data)           
    108116            element_found, sigma0, sigma1, sigma2, k = \
     
    112120
    113121    return element_found, sigma0, sigma1, sigma2, k
    114 
    115 
    116     ## Get triangles in the cell that the point is in.
    117     #tri_data = root.search(x[0], x[1])
    118     #triangles = _trilist_from_data(mesh, tri_data)
    119    
    120     #element_found, sigma0, sigma1, sigma2, k = \
    121                    #_search_triangles_of_vertices(triangles, x)
    122 
    123     #if element_found:
    124         #return True, sigma0, sigma1, sigma2, k
    125122
    126123
  • anuga_core/source/anuga/geometry/aabb.py

    r7711 r7714  
    6868        return True
    6969 
    70     def contains(self, x, y):
    71         return (self.xmin <= x <= self.xmax) and (self.ymin <= y <= self.ymax)
     70    def contains(self, x):
     71        return (self.xmin <= x[0] <= self.xmax) and (self.ymin <= x[1] <= self.ymax)
    7272       
  • anuga_core/source/anuga/geometry/quad.py

    r7713 r7714  
    135135 
    136136
    137     def search(self, x, y):
     137    def search(self, x):
    138138        """return a list of possible intersections with geometry"""
    139 
    140  #       if self.searched == [x,y]:
    141  #           print 'ERROR: already searched at ', [x,y]
    142  #       self.searched = [x,y]
    143139       
    144         intersecting_regions = self.test_leaves(x, y)
     140        intersecting_regions = self.test_leaves(x)
    145141       
    146142        # recurse down into nodes that the point passes through
    147143        if self.children:
    148144            for child in self.children:   
    149                 if child.extents.contains(x, y):
    150                     intersecting_regions.extend(child.search(x, y))
     145                if child.extents.contains(x):
     146                    intersecting_regions.extend(child.search(x))
    151147             
    152148        return intersecting_regions
    153149 
    154150 
    155     def test_leaves(self, x, y):
     151    def test_leaves(self, x):
    156152        intersecting_regions = []
    157153       
     
    159155        for leaf in self.leaves:
    160156            aabb, data = leaf
    161             if aabb.contains(x, y):
     157            if aabb.contains(x):
    162158                intersecting_regions.append((data, self))
    163159               
  • anuga_core/source/anuga/geometry/test_geometry.py

    r7713 r7714  
    1919    def test_AABB_contains(self):
    2020        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)       
     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])       
    2929       
    3030    def test_AABB_split_vert(self):
Note: See TracChangeset for help on using the changeset viewer.