(points, module, head, curr_index, curr_stroke, splits, strokes, radius_dec)
| 153 | |
| 154 | |
| 155 | def build_tree_from_strokes_rec(points, module, head, curr_index, curr_stroke, splits, strokes, radius_dec): |
| 156 | if len(points)>1: |
| 157 | pos = points.popleft() |
| 158 | direction = points[0]-pos |
| 159 | choice = 'branch' |
| 160 | radius = module.head_1_radius if head == 0 else module.head_2_radius |
| 161 | |
| 162 | for parent_stroke, point_index, child_stroke in splits: |
| 163 | if curr_stroke == parent_stroke and point_index == curr_index: |
| 164 | child_points = deque(strokes[child_stroke]) |
| 165 | child_points.popleft() |
| 166 | child_points.popleft() |
| 167 | child_direction = (child_points[0] - pos) |
| 168 | child_length = child_direction.length |
| 169 | if child_length < 1.5*radius: |
| 170 | for i in range(int(1.5*radius/child_length)): |
| 171 | if len(child_points)>1: |
| 172 | child_points.popleft() |
| 173 | child_direction = (child_points[0] - pos) |
| 174 | child_length = child_direction.length |
| 175 | child_direction.normalize() |
| 176 | spin = directions_to_spin(direction, child_direction) |
| 177 | choice = 'split' |
| 178 | break |
| 179 | if choice == 'branch': |
| 180 | new_module = Branch(pos, direction.normalized(), radius, direction.length, head_radius=radius_dec, |
| 181 | resolution=0, spin=module.spin) |
| 182 | elif choice == 'split': |
| 183 | new_module = Split(pos, direction.normalized(), radius, 0, 0, spin, head_2_length=child_length) |
| 184 | if direction.length < radius*.6: |
| 185 | number_to_pop = int(radius*.6/direction.length) |
| 186 | for i in range(number_to_pop): |
| 187 | if len(points)>1: |
| 188 | points.popleft() |
| 189 | direction = points[0] - pos |
| 190 | new_module.head_1_length = direction.length |
| 191 | new_module.head_2_direction = child_direction |
| 192 | new_module.secondary_angle = direction.angle(child_direction) |
| 193 | |
| 194 | if head == 0: |
| 195 | module.head_module_1 = new_module |
| 196 | else: |
| 197 | module.head_module_2 = new_module |
| 198 | new_module.creator = "gp_trunk" if curr_stroke == 0 else "gp_branch" |
| 199 | build_tree_from_strokes_rec(points, new_module, 0, curr_index+1, curr_stroke, splits, strokes, radius_dec) |
| 200 | if choice == 'split': |
| 201 | build_tree_from_strokes_rec(child_points, new_module, 1, 2, child_stroke, splits, strokes, radius_dec) |
| 202 |
no test coverage detected