@@ -291,98 +291,93 @@ def add_to_splice_points():
291291 should_switch_to_splicing ()
292292
293293 while True :
294- match path_dir :
295- case WD .East :
296- while goal [curr_x ][curr_y ] and not goal [curr_x ][curr_y - 1 ]:
297- if curr_x not in path_flips :
298- path_flips [curr_x ] = []
299- path_flips [curr_x ].append (curr_y )
300- curr_x += 1
301- assert curr_x != last_x
302- path_dir = (
303- WD .North if goal [curr_x ][curr_y - 1 ] else WD .South
304- )
305- if do_splice or (curr_x , curr_y ) != (start_x , start_y ):
306- subpath_tail .cmds += abs_or_delta ("hH" , curr_x , last_x )
307-
308- # only a left turn with a hole coming up on the right is spliceable
309- if path_dir == WD .North and not goal [curr_x ][curr_y ]:
310- add_to_splice_points ()
311-
312- if (curr_x , curr_y ) == (start_x , start_y ):
313- break # subpath is done
314- if should_switch_to_splicing ():
315- continue
316-
317- case WD .West :
318- while (
319- not goal [curr_x - 1 ][curr_y ]
320- and goal [curr_x - 1 ][curr_y - 1 ]
321- ):
322- curr_x -= 1
323- if curr_x not in path_flips :
324- path_flips [curr_x ] = []
325- path_flips [curr_x ].append (curr_y )
326- assert curr_x != last_x
327- path_dir = (
328- WD .South if goal [curr_x - 1 ][curr_y ] else WD .North
329- )
330- if do_splice or (curr_x , curr_y ) != (start_x , start_y ):
331- subpath_tail .cmds += abs_or_delta ("hH" , curr_x , last_x )
332-
333- # only a left turn with a hole coming up on the right is spliceable
334- if (
335- path_dir == WD .South
336- and not goal [curr_x - 1 ][curr_y - 1 ]
337- ):
338- add_to_splice_points ()
339-
340- if (curr_x , curr_y ) == (start_x , start_y ):
341- break # subpath is done
342- if should_switch_to_splicing ():
343- continue
344-
345- case WD .North :
346- while (
347- goal [curr_x ][curr_y - 1 ]
348- and not goal [curr_x - 1 ][curr_y - 1 ]
349- ):
350- curr_y -= 1
351- assert curr_y != last_y
352- path_dir = (
353- WD .West if goal [curr_x - 1 ][curr_y - 1 ] else WD .East
354- )
355- if do_splice or (curr_x , curr_y ) != (start_x , start_y ):
356- subpath_tail .cmds += abs_or_delta ("vV" , curr_y , last_y )
357-
358- # only a left turn with a hole coming up on the right is spliceable
359- if path_dir == WD .West and not goal [curr_x ][curr_y - 1 ]:
360- add_to_splice_points ()
361-
362- if (curr_x , curr_y ) == (start_x , start_y ):
363- break # subpath is done
364- if should_switch_to_splicing ():
365- continue
366-
367- case WD .South :
368- while not goal [curr_x ][curr_y ] and goal [curr_x - 1 ][curr_y ]:
369- curr_y += 1
370- assert curr_y != last_y
371- path_dir = WD .East if goal [curr_x ][curr_y ] else WD .West
372- if do_splice or (curr_x , curr_y ) != (start_x , start_y ):
373- subpath_tail .cmds += abs_or_delta ("vV" , curr_y , last_y )
374-
375- # only a left turn with a hole coming up on the right is spliceable
376- if path_dir == WD .East and not goal [curr_x - 1 ][curr_y ]:
377- add_to_splice_points ()
378-
379- if (curr_x , curr_y ) == (start_x , start_y ):
380- break # subpath is done
381- if should_switch_to_splicing ():
382- continue
383-
384- case _:
385- raise
294+ if path_dir == WD .East :
295+ while goal [curr_x ][curr_y ] and not goal [curr_x ][curr_y - 1 ]:
296+ if curr_x not in path_flips :
297+ path_flips [curr_x ] = []
298+ path_flips [curr_x ].append (curr_y )
299+ curr_x += 1
300+ assert curr_x != last_x
301+ path_dir = (
302+ WD .North if goal [curr_x ][curr_y - 1 ] else WD .South
303+ )
304+ if do_splice or (curr_x , curr_y ) != (start_x , start_y ):
305+ subpath_tail .cmds += abs_or_delta ("hH" , curr_x , last_x )
306+
307+ # only a left turn with a hole coming up on the right is spliceable
308+ if path_dir == WD .North and not goal [curr_x ][curr_y ]:
309+ add_to_splice_points ()
310+
311+ if (curr_x , curr_y ) == (start_x , start_y ):
312+ break # subpath is done
313+ if should_switch_to_splicing ():
314+ continue
315+ elif path_dir == WD .West :
316+ while (
317+ not goal [curr_x - 1 ][curr_y ]
318+ and goal [curr_x - 1 ][curr_y - 1 ]
319+ ):
320+ curr_x -= 1
321+ if curr_x not in path_flips :
322+ path_flips [curr_x ] = []
323+ path_flips [curr_x ].append (curr_y )
324+ assert curr_x != last_x
325+ path_dir = (
326+ WD .South if goal [curr_x - 1 ][curr_y ] else WD .North
327+ )
328+ if do_splice or (curr_x , curr_y ) != (start_x , start_y ):
329+ subpath_tail .cmds += abs_or_delta ("hH" , curr_x , last_x )
330+
331+ # only a left turn with a hole coming up on the right is spliceable
332+ if (
333+ path_dir == WD .South
334+ and not goal [curr_x - 1 ][curr_y - 1 ]
335+ ):
336+ add_to_splice_points ()
337+
338+ if (curr_x , curr_y ) == (start_x , start_y ):
339+ break # subpath is done
340+ if should_switch_to_splicing ():
341+ continue
342+ elif path_dir == WD .North :
343+ while (
344+ goal [curr_x ][curr_y - 1 ]
345+ and not goal [curr_x - 1 ][curr_y - 1 ]
346+ ):
347+ curr_y -= 1
348+ assert curr_y != last_y
349+ path_dir = (
350+ WD .West if goal [curr_x - 1 ][curr_y - 1 ] else WD .East
351+ )
352+ if do_splice or (curr_x , curr_y ) != (start_x , start_y ):
353+ subpath_tail .cmds += abs_or_delta ("vV" , curr_y , last_y )
354+
355+ # only a left turn with a hole coming up on the right is spliceable
356+ if path_dir == WD .West and not goal [curr_x ][curr_y - 1 ]:
357+ add_to_splice_points ()
358+
359+ if (curr_x , curr_y ) == (start_x , start_y ):
360+ break # subpath is done
361+ if should_switch_to_splicing ():
362+ continue
363+ elif path_dir == WD .South :
364+ while not goal [curr_x ][curr_y ] and goal [curr_x - 1 ][curr_y ]:
365+ curr_y += 1
366+ assert curr_y != last_y
367+ path_dir = WD .East if goal [curr_x ][curr_y ] else WD .West
368+ if do_splice or (curr_x , curr_y ) != (start_x , start_y ):
369+ subpath_tail .cmds += abs_or_delta ("vV" , curr_y , last_y )
370+
371+ # only a left turn with a hole coming up on the right is spliceable
372+ if path_dir == WD .East and not goal [curr_x - 1 ][curr_y ]:
373+ add_to_splice_points ()
374+
375+ if (curr_x , curr_y ) == (start_x , start_y ):
376+ break # subpath is done
377+ if should_switch_to_splicing ():
378+ continue
379+ else :
380+ raise
386381 assert (last_x , last_y ) != (curr_x , curr_y ), goal
387382 (last_x , last_y ) = (curr_x , curr_y )
388383
0 commit comments