/[mcclim]/mcclim/recording.lisp
ViewVC logotype

Diff of /mcclim/recording.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.131 by ahefner, Tue Mar 20 01:48:38 2007 UTC revision 1.132 by ahefner, Sun Jun 3 18:47:03 2007 UTC
# Line 779  the associated sheet can be determined." Line 779  the associated sheet can be determined."
779       old-min-x old-min-y old-max-x old-max-y)       old-min-x old-min-y old-max-x old-max-y)
780    (with-bounding-rectangle* (ox1 oy1 ox2 oy2)  record    (with-bounding-rectangle* (ox1 oy1 ox2 oy2)  record
781      (with-bounding-rectangle* (cx1 cy1 cx2 cy2) changed-child      (with-bounding-rectangle* (cx1 cy1 cx2 cy2) changed-child
782        (let ((child-was-empty (and (= old-min-x old-min-y) ; =(        ;; If record is currently empty, use the child's bbox directly. Else..
783                                    (= old-max-x old-max-y))))        ;; Does the new rectangle of the child contain the original rectangle?
784          ;; If record is currently empty, use the child's bbox directly. Else..        ;; If so, we can use min/max to grow record's current rectangle.
785          ;; Does the new rectangle of the child contain the original rectangle?        ;; If not, the child has shrunk, and we need to fully recompute.
786          ;; If so, we can use min/max to grow record's current rectangle.        (multiple-value-bind (nx1 ny1 nx2 ny2)
787          ;; If not, the child has shrunk, and we need to fully recompute.            (cond
788          (multiple-value-bind (nx1 ny1 nx2 ny2)              ;; The child has been deleted; who knows what the
789              (cond              ;; new bounding box might be.
790                ;; The child has been deleted, but none of its edges contribute              ((not (output-record-parent changed-child))
791                ;; to the bounding rectangle of the parent, so the bounding               (%tree-recompute-extent* record))
792                ;; rectangle cannot be changed by its deletion.              ;; Only one child of record, and we already have the bounds.
793                ;; This is also true if the child was empty.              ((eql (output-record-count record) 1)
794                ((or child-was-empty               (values cx1 cy1 cx2 cy2))
795                     (and (output-record-parent changed-child)              ;; If our record occupied no space (had no children, or had only
796                          (> old-min-x ox1)              ;; children similarly occupying no space, hackishly determined by
797                          (> old-min-y oy1)              ;; null-bounding-rectangle-p), recompute the extent now, otherwise
798                          (< old-max-x ox2)              ;; the next COND clause would, as an optimization, attempt to extend
799                          (< old-max-y oy2)))              ;; our current bounding rectangle, which is invalid.
800                 (values ox1 oy1 ox2 oy2))              ((null-bounding-rectangle-p record)
801                ;; The child has been deleted; who knows what the               (%tree-recompute-extent* record))
802                ;; new bounding box might be.              ;; In the following cases, we can grow the new bounding rectangle
803                ((not (output-record-parent changed-child))              ;; from its previous state:
804                 (%tree-recompute-extent* record))              ((or
805                ;; Only one child of record, and we already have the bounds.                ;; If the child was originally empty, it should not have affected
806                ((eql (output-record-count record) 1)                ;; previous computation of our bounding rectangle.
807                 (values cx1 cy1 cx2 cy2))                ;; This is hackish for reasons similar to the above.
808                ;; If our record occupied no space (had no children, or had only                (and (zerop old-min-x) (zerop old-min-y)
809                ;; children similarly occupying no space, hackishly determined by                     (zerop old-max-x) (zerop old-max-y))
810                ;; null-bounding-rectangle-p), recompute the extent now, otherwise                ;; For each old child coordinate, either it was not
811                ;; the next COND clause would, as an optimization, attempt to extend                ;; involved in determining the bounding rectangle of the
812                ;; our current bounding rectangle, which is invalid.                ;; parent, or else it is the same as the corresponding
813                ((null-bounding-rectangle-p record)                ;; new child coordinate.
814                 (%tree-recompute-extent* record))                (and (or (> old-min-x ox1) (= old-min-x cx1))
815                ;; In the following cases, we can grow the new bounding rectangle                     (or (> old-min-y oy1) (= old-min-y cy1))
816                ;; from its previous state:                     (or (< old-max-x ox2) (= old-max-x cx2))
817                ((or                     (or (< old-max-y oy2) (= old-max-y cy2)))
818                  ;; If the child was originally empty, it should not have affected                ;; New child bounds contain old child bounds, so use min/max
819                  ;; previous computation of our bounding rectangle.                ;; to extend the already-calculated rectangle.
820                  child-was-empty                (and (<= cx1 old-min-x) (<= cy1 old-min-y)
821                  ;; No child edge which may have defined the bounding rectangle of                     (>= cx2 old-max-x) (>= cy2 old-max-y)))
822                  ;; the parent has shrunk inward, so min/max the new child rectangle               (values (min cx1 ox1) (min cy1 oy1)
823                  ;; against the existing rectangle. Other edges of the child may have                       (max cx2 ox2) (max cy2 oy2)))
824                  ;; moved, but this can't affect the parent bounding rectangle.              ;; No shortcuts - we must compute a new bounding box from those of
825                  (and (or (> old-min-x ox1) (>= old-min-x cx1))              ;; all our children. We want to avoid this - in worst cases, such as
826                       (or (> old-min-y oy1) (>= old-min-y cy1))              ;; a toplevel output history, large graph, or table, there may exist
827                       (or (< old-max-x ox2) (<= old-max-x cx2))              ;; thousands of children. Without the above optimizations,
828                       (or (< old-max-y oy2) (<= old-max-y cy2))))              ;; construction becomes O(N^2) due to bounding rectangle calculation.
829                 ;; In these cases, we can grow the rectangle using min/max.              (t (%tree-recompute-extent* record)))
830                 (values (min cx1 ox1) (min cy1 oy1)          ;; XXX banish x, y
831                         (max cx2 ox2) (max cy2 oy2)))          (with-slots (x y)
832                ;; No shortcuts - we must compute a new bounding box from those of              record
833                ;; all our children. We want to avoid this - in worst cases, such as            (setf x nx1 y ny1)
834                ;; a toplevel output history, large graph, or table, there may exist            (setf (rectangle-edges* record) (values  nx1 ny1 nx2 ny2))
835                ;; thousands of children. Without the above optimizations,            (let ((parent (output-record-parent record)))
836                ;; construction becomes O(N^2) due to bounding rectangle calculation.              (unless (or (null parent)
837                (t (%tree-recompute-extent* record)))                          (and (= nx1 ox1) (= ny1 oy1)
838            ;; XXX banish x, y                               (= nx2 ox2) (= nx2 oy2)))
839            (with-slots (x y)                (recompute-extent-for-changed-child parent record
840                record                                                    ox1 oy1 ox2 oy2)))))))
             (setf x nx1 y ny1)  
             (setf (rectangle-edges* record) (values  nx1 ny1 nx2 ny2))  
             (let ((parent (output-record-parent record)))  
               (unless (or (null parent)  
                           (and (= nx1 ox1) (= ny1 oy1)  
                                (= nx2 ox2) (= nx2 oy2)))  
                 (recompute-extent-for-changed-child parent record  
                                                     ox1 oy1 ox2 oy2))))))))  
841    record)    record)
842    
843  ;; There was once an :around method on recompute-extent-for-changed-child here,  ;; There was once an :around method on recompute-extent-for-changed-child here,

Legend:
Removed from v.1.131  
changed lines
  Added in v.1.132

  ViewVC Help
Powered by ViewVC 1.1.5