From 59c0938252a457fcfbcdc1caaeed84f94b0049f4 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 5 Feb 2019 11:41:41 -0800 Subject: [PATCH] wrap a degen case better --- quad/quad/wrap.rkt | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/quad/quad/wrap.rkt b/quad/quad/wrap.rkt index 70cddb81..b78fd0b3 100644 --- a/quad/quad/wrap.rkt +++ b/quad/quad/wrap.rkt @@ -128,14 +128,29 @@ previous-wrap-ender other-qs)] [(empty? next-wrap-head) - (debug-report 'would-overflow-hard-without-captured-break) - (loop (cons (finish-wrap next-wrap-tail previous-wrap-ender wrap-idx) wraps) - (wrap-count wrap-idx q) - null - null - #false - (car next-wrap-tail) - qs)] + (cond + [(empty? next-wrap-tail) + ;; degenerate case where we have something big enough to trigger a wrap on its own, + ;; and nothing left in next-wrap-head or next-wrap-tail. + ;; so we put it in a wrap on its own, because otherwise we can't proceed + ;; though it will look screwy + (debug-report 'making-the-best-of-a-bad-situation) + (loop (cons (finish-wrap (list q) previous-wrap-ender wrap-idx) wraps) + (wrap-count wrap-idx q) + null + null + #false + q + (cdr qs))] + [else + (debug-report 'would-overflow-hard-without-captured-break) + (loop (cons (finish-wrap next-wrap-tail previous-wrap-ender wrap-idx) wraps) + (wrap-count wrap-idx q) + null + null + #false + (car next-wrap-tail) + qs)])] [else ; finish the wrap & reset the line without consuming a quad (loop (cons (finish-wrap next-wrap-head previous-wrap-ender wrap-idx) wraps) (wrap-count wrap-idx q)