Changeset 7713 for anuga_core/source/anuga/geometry/quad.py
- Timestamp:
- May 11, 2010, 10:59:06 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/geometry/quad.py
r7712 r7713 19 19 """ 20 20 21 def __init__(self, extents, 21 def __init__(self, extents, parent, depth = 0, 22 22 name = 'cell'): 23 23 … … 26 26 27 27 self.extents = extents 28 self.parent = parent 29 self.searched = [-10, -15] 30 self.depth = depth 28 31 29 32 # The points in this cell … … 33 36 34 37 def __repr__(self): 35 str = ' %s: leaves: %d' \36 % (self. name , len(self.leaves))38 str = '(%d)%s: leaves: %d' \ 39 % (self.depth, self.name , len(self.leaves)) 37 40 if self.children: 38 41 str += ', children: %d' % (len(self.children)) … … 82 85 subregion1, subregion2 = self.extents.split() 83 86 if subregion1.is_trivial_in(new_region): 84 self.children = [Cell(subregion1 ), Cell(subregion2)]87 self.children = [Cell(subregion1, self, depth=self.depth+1), Cell(subregion2, self, depth=self.depth+1)] 85 88 self.children[0]._insert(new_leaf) 86 89 return 87 90 elif subregion2.is_trivial_in(new_region): 88 self.children = [Cell(subregion1 ), Cell(subregion2)]91 self.children = [Cell(subregion1, self, depth=self.depth+1), Cell(subregion2, self, depth=self.depth+1)] 89 92 self.children[1]._insert(new_leaf) 90 93 return … … 132 135 133 136 134 def search(self, x, y , get_vertices = False):137 def search(self, x, y): 135 138 """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] 136 143 144 intersecting_regions = self.test_leaves(x, y) 145 146 # recurse down into nodes that the point passes through 147 if self.children: 148 for child in self.children: 149 if child.extents.contains(x, y): 150 intersecting_regions.extend(child.search(x, y)) 151 152 return intersecting_regions 153 154 155 def test_leaves(self, x, y): 137 156 intersecting_regions = [] 138 157 … … 141 160 aabb, data = leaf 142 161 if aabb.contains(x, y): 143 if get_vertices: 144 intersecting_regions.append(leaf) 145 else: 146 intersecting_regions.append(data) 147 148 # recurse down into nodes that the point passes through 149 if self.children: 150 for child in self.children: 151 if child.extents.contains(x, y): 152 intersecting_regions.extend(child.search(x, y, get_vertices)) 153 154 return intersecting_regions 155 162 intersecting_regions.append((data, self)) 163 164 return intersecting_regions 165 166 167 def get_siblings(self): 168 """ return parent and siblings of this node. 169 """ 170 if not self.parent: 171 return [] 172 173 siblings = list(self.parent.children) 174 siblings.remove(self) 175 return siblings 176
Note: See TracChangeset
for help on using the changeset viewer.