(height_map, sq_threshold)
| 82 | stats['minx'] = min(p1[0], p2[0], stats['minx']) |
| 83 | |
| 84 | def marching_squares(height_map, sq_threshold): |
| 85 | lines = array("d") |
| 86 | |
| 87 | for y in range(grid_hs-1): |
| 88 | for x in range(grid_ws-1): #cf |
| 89 | tl = height_map[y*grid_ws + x] |
| 90 | tr = height_map[y*grid_ws + x+1] |
| 91 | bl = height_map[(y+1)*grid_ws + x] |
| 92 | br = height_map[(y+1)*grid_ws + x+1] |
| 93 | |
| 94 | sq_idx = 0 |
| 95 | if tl > sq_threshold: |
| 96 | sq_idx |= 8 |
| 97 | if tr > sq_threshold: |
| 98 | sq_idx |= 4 |
| 99 | if br > sq_threshold: |
| 100 | sq_idx |= 2 |
| 101 | if bl > sq_threshold: |
| 102 | sq_idx |= 1 |
| 103 | |
| 104 | edge_points = [ |
| 105 | (x + interpolate(sq_threshold, tl, tr), y), |
| 106 | (x + 1, y + interpolate(sq_threshold, tr, br)), |
| 107 | (x + interpolate(sq_threshold, bl, br), y + 1), |
| 108 | (x, y + interpolate(sq_threshold, tl, bl)), |
| 109 | ] |
| 110 | |
| 111 | for a, b in edge_table[sq_idx]: |
| 112 | append_p(lines, edge_points[a], edge_points[b]) |
| 113 | |
| 114 | return lines |
| 115 | |
| 116 | def grid_lines(): |
| 117 | lines = array("d") |
no test coverage detected