MCPcopy Create free account
hub / github.com/pyscript/pyscript / marching_squares

Function marching_squares

core/tests/manual/issue-2302/worker.py:84–114  ·  view source on GitHub ↗
(height_map, sq_threshold)

Source from the content-addressed store, hash-verified

82 stats['minx'] = min(p1[0], p2[0], stats['minx'])
83
84def 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
116def grid_lines():
117 lines = array("d")

Callers 1

worker.pyFile · 0.85

Calls 2

interpolateFunction · 0.85
append_pFunction · 0.70

Tested by

no test coverage detected