8000 add many more test cases + tweaks · dragoncoder047/schemascii@df69da4 · GitHub
[go: up one dir, main page]

Skip to content

Commit df69da4

Browse files
add many more test cases + tweaks
1 parent c7c4f5b commit df69da4

File tree

1 file changed

+94
-44
lines changed

1 file changed

+94
-44
lines changed

test_data/blob_test.py

Lines changed: 94 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import enum
21
import typing
32

43
strings = [
54
"""
5+
#########################
6+
#########################
7+
#########################
8+
#########################
9+
#########################
10+
#########################""",
11+
"""
12+
#########################
13+
#########################
14+
#############
15+
#########################
16+
#########################
17+
""",
18+
"""
619
#
720
###
821
#####
@@ -87,7 +100,42 @@
87100
"""
88101
###############
89102
###################
90-
###############"""]
103+
###############""",
104+
"""
105+
################
106+
################
107+
################
108+
################
109+
################
110+
################
111+
################
112+
################""",
113+
"""
114+
# # # # # # # #
115+
################
116+
################
117+
################
118+
################
119+
################
120+
# # # # # # # #""",
121+
"""
122+
#
123+
####
124+
#######
125+
##########
126+
#############
127+
################
128+
###################
129+
######################
130+
#########################
131+
######################
132+
###################
133+
################
134+
#############
135+
##########
136+
#######
137+
####
138+
#"""]
91139

92140
"""
93141
idea for new algorithm
@@ -170,9 +218,9 @@ def cull_disallowed_edges(
170218
# (the above algorithm has some weird edge cases where it may produce
171219
# one-way edges on accident)
172220
# XXX This causes issues when it is enabled, why?
173-
for p1 in all_points:
174-
for p2 in fixed_edges.setdefault(p1, set()):
175-
fixed_edges.setdefault(p2, set()).add(p1)
221+
for p, c in fixed_edges.items():
222+
for q in c:
223+
fixed_edges.setdefault(q, set()).add(p)
176224
return fixed_edges
177225

178226

@@ -186,7 +234,6 @@ def walk_graph_to_loop(
186234
swd_into: dict[complex, set[complex]] = {}
187235
while not all(e in out for e in edges) or current != start:
188236
out.append(current)
189-
print(debug_singular_polyline_in_svg(out, current))
190237
# log the direction we came from
191238
swd_into.setdefault(current, set()).add(current_dir)
192239
choices_directions = (rot(current_dir, i)
@@ -198,23 +245,22 @@ def walk_graph_to_loop(
198245
if nxt in edges[current]:
199246
if nxt not in swd_into.keys():
200247
# if we haven't been there before, go there
201-
print("go new place")
202248
current = nxt
203249
current_dir = d
204250
break
205251
# otherwise, if we've been there before, but haven't
206252
# come from this direction, then save it for later
207253
if d not in swd_into.get(nxt, set()) and bt_d is None:
208254
bt_d = d
209-
print("saving", d)
210255
else:
211256
if bt_d is not None:
212257
# if we have a saved direction to go, go that way
213258
current = current + bt_d
214259
current_dir = bt_d
215260
else:
216261
raise RuntimeError
217-
print("finished normally")
262+
print("path clockwise is")
263+
print(debug_singular_polyline_in_svg(out, current))
218264
return out
219265

220266

@@ -262,13 +308,14 @@ def remove_unnecessary(pts: list[complex],
262308
# numbers for all others
263309
maxima = [is_mid_maxima(a, b, c) for (a, b, c) in triples(distances)]
264310
points_to_maybe_discard = set(
265-
pt for (pt, dist, maxima) in zip(pts, distances, maxima)
311+
pt for pt, dist, maxima, pointy in zip(pts, distances, maxima, dotnos)
266312
# keep all the local maxima
267313
# keep ones that are flat enough
268314
# --> remove the ones that are not sloped enough
269315
# and are not local maxima
270316
if ((dist is not None and dist < maxslope)
271-
and not maxima))
317+
and not maxima
318+
and pointy != 0))
272319
# the ones to definitely keep are the convex ones
273320
# as well as concave ones that are adjacent to only straight ones that
274321
# are being deleted
@@ -281,7 +328,7 @@ def remove_unnecessary(pts: list[complex],
281328
# special case: keep concave ones that are 2-near at
282329
# least one convex pointy point (where pointy additionally means that
283330
# it isn't a 180)
284-
points_to_def_keep |= set(
331+
points_to_def_keep.update(set(
285332
p for (
286333
p,
287334
(dot_2l, _, _, _, dot_2r),
@@ -290,27 +337,33 @@ def remove_unnecessary(pts: list[complex],
290337
) in zip(pts, fiveles(dotnos), fiveles(signos), fiveles(dirs))
291338
if sig_m < 0 and (
292339
(sig_2l > 0 and dot_2l < 0 and dd1_2l != -dd2_2l)
293-
or (sig_2r > 0 and dot_2r < 0 and dd1_2r != -dd2_2r)))
340+
or (sig_2r > 0 and dot_2r < 0 and dd1_2r != -dd2_2r))))
294341
# for debugging
295342
a = dots([], edges)
296343
i = a.replace("</svg>", "".join(f"""<circle cx="{
297-
p.real
344+
pt.real
298345
}" cy="{
299-
p.imag
300-
}" r="0.5" fill="{
301-
"red" if r > 0
302-
else "blue" if r < 0
346+
pt.imag
347+
}" r="{
348+
0.5 if conc == 0
349+
else 0.8 if conc > 0
350+
else 0.2
351+
}" fill="{
352+
"red" if sharp > 0
353+
else "blue" if sharp < 0
303354
else "black"
304355
}" opacity="50%"></circle>"""
305-
for p, q, r in zip(pts, distances, dotnos)) + "</svg>")
356+
for pt, sharp, conc in zip(pts, dotnos, signos)) + "</svg>")
306357
z = a.replace("</svg>", "".join(f"""<circle cx="{
307358
p.real
308359
}" cy="{
309360
p.imag
310361
}" r="0.5" fill="red" opacity="50%"></circle>"""
311362
for p in (points_to_maybe_discard - points_to_def_keep)) + "</svg>")
312-
print("begin conc", i, "end conc")
313-
print("begin discard", z, "end discard")
363+
print("pointyness / concavity")
364+
print(i)
365+
print("will be discarded")
366+
print(z)
314367
# end debugging
315368
return [p for p in pts
316369
if p not in points_to_maybe_discard
@@ -332,11 +385,12 @@ def process_group(g: list[complex], all_pts: list[complex]) -> list[complex]:
332385

333386
def get_outline_points(pts: list[complex]) -> list[list[complex]]:
334387
# find the edge points
335-
edge_points: list[complex] = []
388+
edge_points: set[complex] = set()
336389
for p in pts:
337-
if not all(p + d in pts for d in DIRECTIONS) and not all(
338-
p + d in pts for d in VN_DIRECTIONS):
339-
edge_points.append(p)
390+
if not all(p + d in pts for d in DIRECTIONS):
391+
if not all(
392+
p + d in pts for d in VN_DIRECTIONS):
393+
edge_points.add(p)
340394
# find all of the disconnected loop groups
341395
loop_groups: list[list[complex]] = []
342396
while edge_points:
@@ -376,32 +430,28 @@ def debug_singular_polyline_in_svg(
376430
points: list[complex], current: complex, scale: float = 20) -> str:
377431
vbx = max(x.real for x in points) + 1
378432
vby = max(x.imag for x in points) + 1
379-
return f"""<svg viewBox="-1 -1 {vbx+2} {vby+2}" width="{
380-
vbx * scale}" height="{vby * scale}"><polyline
381-
fill="none"
382-
stroke="black"
383-
stroke-width="0.1"
384-
points="{" ".join(map(lambda x: f"{x.real},{x.imag}", points))}">
385-
</polyline><circle cx="{current.real}" cy="{
433+
return (f"""<svg viewBox="-1 -1 {vbx+2} {vby+2}" width="{
434+
vbx * scale}" height="{vby * scale}"><polyline fill="none" """
435+
f"""stroke="black" stroke-width="0.1" points="{
436+
" ".join(map(lambda x: f"{x.real},{x.imag}", points))
437+
}"></polyline><circle cx="{current.real}" cy="{
386438
current.imag
387-
}" r="0.3" fill="blue" /></svg>"""
439+
}" r="0.3" fill="blue" /></svg>""")
388440

389441

390442
def example(all_points: list[complex], scale: float = 20) -> str:
391443
ps = get_outline_points(all_points)
392444
vbx = max(x.real for p in ps for x in p) + 1
393445
vby = max(x.imag for p in ps for x in p) + 1
394-
polylines = "".join(f"""<polyline
395-
fill="none"
396-
stroke="black"
397-
stroke-width="0.1"
398-
points="{" ".join(map(lambda x: f"{x.real},{x.imag}", p))}">
399-
</polyline>""" for p in ps)
400-
return f"""<svg
401-
viewBox="-1 -1 {vbx + 2} {vby + 2}"
402-
width="{vbx * scale}"
403-
height="{vby * scale}">
404-
{polylines}</svg>"""
446+
polylines = "".join("""<polyline fill="none" stroke="black" """
447+
f"""stroke-width="0.1" points="{
448+
" ".join(map(lambda x: f"{x.real},{x.imag}",
449+
p + [p[0]]))
450+
}"></polyline>""" for p in ps)
451+
print("final")
452+
return f"""<svg viewBox="-1 -1 {vbx + 2} {vby + 2}" width="{
453+
vbx * scale
454+
}" height="{vby * scale}">{polylines}</svg>"""
405455

406456

407457
print("<style>svg { border: 1px solid black}body{white-space: pre}</style>")

0 commit comments

Comments
 (0)
0