Changeset 7703


Ignore:
Timestamp:
Apr 29, 2010, 6:23:15 PM (14 years ago)
Author:
hudson
Message:

Refactored quad.py to remove unused methods and duplicated code.

Location:
anuga_core/source/anuga/utilities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/quad.py

    r7317 r7703  
    1919
    2020    Public Methods:
    21         prune()
    2221        insert(point)
    2322        search(x, y)
    24         collapse()
    2523        split()
    2624        store()
     
    8078        """
    8179        branch = []
    82         points = []
    83         if self.children:
    84             for child in self:
    85                 if child.contains(x,y):
    86                     brothers = list(self.children)
    87                     brothers.remove(child)
    88                     branch.append(brothers)
    89                     points, branch = child.search_branch(x,y, branch,
    90                                                   get_vertices=get_vertices)
    91         else:
    92             # Leaf node: Get actual waypoints
    93             points = self.retrieve(get_vertices=get_vertices)
    94         self.branch = branch   
     80        points, branch = self.search_branch(x, y, branch, get_vertices=get_vertices)
     81        self.branch = branch 
    9582        return points
    9683
     
    10289        if self.children:
    10390            for child in self:
    104                 if child.contains(x,y):
     91                if (child.western <= x < child.eastern) and (child.southern <= y < child.northern):
    10592                    brothers = list(self.children)
    10693                    brothers.remove(child)
     
    129116
    130117
    131     def contains(*args):   
     118    def contains(self, point_id):   
    132119        """True only if P's coordinates lie within cell boundaries
    133120        This methods has two forms:
     
    135122        cell.contains(index)
    136123        #True if cell contains indexed point
    137         cell.contains(x, y)
    138         #True if cell contains point (x,y)     
    139         """
    140         self = args[0]
    141         if len(args) == 2:
    142             point_id = int(args[1])
    143             x, y = self.mesh.get_node(point_id, absolute=True)
    144         elif len(args) == 3:
    145             x = float(args[1])
    146             y = float(args[2])
    147         else:
    148             msg = 'Number of arguments to method must be two or three'
    149             raise msg                         
    150        
    151         if y <  self.southern: return False
    152         if y >= self.northern: return False
    153         if x <  self.western:  return False
    154         if x >= self.eastern:  return False
    155         return True
     124        """
     125        x, y = self.mesh.get_node(point_id, absolute=True)     
     126       
     127        return (self.western <= x < self.eastern) and (self.southern <= y < self.northern)
    156128   
    157129   
     
    319291            for child in self:              # split (possibly newly created)
    320292                child.split(threshold)      # child cells recursively
    321                
    322 
    323 
    324     def collapse(self,threshold=None):
    325         """
    326         collapse child cells into immediate parent if total number of contained waypoints
    327         in subtree below is less than or equal to threshold.
    328         All waypoints are then moved into parent cell and
    329         children are removed. If self is a leaf node initially, do nothing.
    330         """
    331        
    332         if threshold is None:
    333             threshold = self.max_points_per_cell       
    334 
    335 
    336         if self.children:                   # Parent cell   
    337             if self.count() <= threshold:   # collapse
    338                 points = self.retrieve()    # Get all points from child cells
    339                 self.clear()                # Remove children, self is now a leaf node
    340                 self.insert(points)         # Insert all points in local storage
    341             else:                         
    342                 for child in self:          # Check if any sub tree can be collapsed
    343                     child.collapse(threshold)
     293             
    344294
    345295
  • anuga_core/source/anuga/utilities/test_quad.py

    r7276 r7703  
    9898        assert self.cell.count() == 8
    9999
    100 
    101 
    102     def test_collapse(self):
    103         self.cell.insert([0,1,2,3,4,5,6,7], split = False)
    104 
    105         #Split maximally
    106         self.cell.split(1)
    107 
    108         #Now there are children
    109         assert self.cell.children is not None
    110         assert self.cell.count() == 8
    111 
    112         #Collapse
    113         self.cell.collapse(8)
    114 
    115         #No children
    116         assert self.cell.children is None
    117         assert self.cell.count() == 8
    118100
    119101    def test_build_quadtree(self):
Note: See TracChangeset for help on using the changeset viewer.