]> git.donarmstrong.com Git - lilypond.git/commitdiff
(ly:optimal-page-breaks): Bugfix: underful
authorJan Nieuwenhuizen <janneke@gnu.org>
Fri, 19 Mar 2004 17:12:27 +0000 (17:12 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Fri, 19 Mar 2004 17:12:27 +0000 (17:12 +0000)
solutions are now optimal too.

ChangeLog
input/test/title-markup.ly
scm/page-layout.scm

index 6a9d50624748453062382b26fe2b1d42a53517f0..a01fa81a8d2202c38de4c0ea0aef3677bcd45896 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2004-03-19  Jan Nieuwenhuizen  <janneke@gnu.org>
 
+       * scm/page-layout.scm (ly:optimal-page-breaks): Bugfix: underful
+       solutions are now optimal too.
+
        * lily/paper-outputter.cc (Paper_outputter): Import page breaking
        functions into safe module.
 
index 5caa3076dc73dc793b316e7ef7c0250a8e2528cc..9d0a77689b63525206e216444eeca825bbc16bd7 100644 (file)
@@ -82,11 +82,9 @@ spaceTest = \markup { "two space chars" }
 
 \score {
     \context Staff \notes \relative c' {
-       %% stress page breaking: keep on 3 pages
-       %% 35 looks very good: 3 pages
-       %% Hmmm.
-       %% 36 seems to show a bug:
-       %% 4 pages, first two half full, last two full
+       %% stress page breaking:
+       %% 35 keep on 3 pages
+       %% 36 spread evenly over 4 pages
        \repeat unfold 35 { a b c d \break }
        c1
     }
index 133032a37a16cb42870a00aab5c00d28645117c8..0c75b5e58acf331e6c1300967ad3dcdb023a0a39 100644 (file)
           (mean (/ (apply + densities) (length densities)))
           (diff (map (lambda (x) (- x mean)) densities))
           (var (map sqr (map (lambda (x) (* (car p-heights) x)) diff))))
-      (if #f
-         (begin
-           (format (current-error-port) "\nDENSITIES")
-           (format (current-error-port) "lines: ~S\n"
-                   (map robust-line-number height-nodes))
-           (format (current-error-port) "page-heighs: ~S\n" p-heights)
-           (format (current-error-port) "heights: ~S\n" heights)
-           (format (current-error-port) "densities: ~S\n" densities)
-           (format (current-error-port) "mean: ~S\n" mean)
-           (format (current-error-port) "diff: ~S\n" diff)
-           (format (current-error-port) "density-var: ~S\n" var)))
       (apply + var)))
 
   (define (walk-paths best node lines nodes paths)
           (path-score (if (null? paths) 0 (node-score (car paths))))
           (score (add-scores path-score this-score)))
 
-      (if #f
-         (begin
-           (format (current-error-port) "page-score: ~S\n" page-score)
-           (format (current-error-port) "density-score: ~S\n" density-score)
-           (format (current-error-port) "this-score: ~S\n" this-score)))
-      
       (if (and (>= score 0)
-              (or (< score (node-score best))
+              (or (<= score (node-score best))
                   (= (node-score best) -1)))
          (begin
            (set! (node-score best) score)
            (set! (node-page best) next-page)
            (set! (node-height best) height)
-           (set! (node-prev best) node)))
-      
-      (if (null? nodes)
+           (set! (node-prev best) (car paths))))
+
+      (if (or (null? nodes)
+             ;; short circuit
+             (and (= path-score -1)
+                  (> (- (/ height page) 1) MAX-CRAMP)))
          best
-         (walk-paths best (car paths) (cons (node-line node) lines)
+         (walk-paths best (car nodes)
+                     (cons (node-line (car paths)) lines)
                      (cdr nodes) (cdr paths)))))
 
   (define (walk-lines lines nodes paths)
        (let* ((prev (node-prev (car nodes)))
               (this (make-node prev (car lines) 0 INFINITY))
               (next (make-node this (cadr lines) 0 0))
-              (best (walk-paths this (car paths)
-                                (list (node-line (car nodes)))
-                                (cddr nodes) (cdr paths))))
+              (best (walk-paths this prev (list (node-line (car nodes)))
+                                (cddr nodes) paths)))
          (walk-lines (cdr lines) (cons next nodes) (cons best paths)))))
   
   (let* ((dummy (make-node '() '() 0 0))
     (format (current-error-port) "ESTIMATE: ~S\n"
            (/ book-height text-height))
     (format (current-error-port) "breaks: ~S\n" breaks)
+    ;; TODO: if solution is bad return no breaks and revert to
+    ;;       ragged bottom
     (force-output (current-error-port))
-
-    (if #f (format (current-error-port) "scores: ~S\n" (map node-score path)))
-         
     (list->vector breaks)))