diff options
author | David Thompson <dthompson2@worcester.edu> | 2021-09-21 20:13:14 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2021-09-21 20:34:43 -0400 |
commit | d42fe471ffb2ae6c631b1f9fca72ca157b8d72d3 (patch) | |
tree | 59fdc3889d6e796a6d78933d5cdfa7bf804f183e | |
parent | b9d96fd0d0450ac96ef113c0845bf3e773b75e4d (diff) |
graphics: path: Add right-split, up-split, and corner-split procedures.
-rw-r--r-- | chickadee/graphics/path.scm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/chickadee/graphics/path.scm b/chickadee/graphics/path.scm index 48e80d9..3b29b19 100644 --- a/chickadee/graphics/path.scm +++ b/chickadee/graphics/path.scm @@ -83,6 +83,9 @@ pad beside below + right-split + up-split + corner-split painter? painter-bounding-box make-empty-canvas @@ -1463,6 +1466,35 @@ (let ((r (painter-bounding-box painter))) (loop rest (max width (rect-width r)) (+ height (rect-height r))))))))) +;; Adapted from Structure and Interpretation of Computer Programs, +;; section 2.2.4. +(define (right-split painter n) + (if (<= n 0) + painter + (let ((smaller (right-split (scale 0.5 painter) (- n 1)))) + (beside (scale (vec2 0.5 1.0) painter) + (below smaller smaller))))) + +(define (up-split painter n) + (if (<= n 0) + painter + (let ((smaller (up-split (scale 0.5 painter) (- n 1)))) + (below (scale (vec2 1.0 0.5) painter) + (beside smaller smaller))))) + +(define (corner-split painter n) + (if (<= n 0) + painter + (let* ((smaller (scale (vec2 0.5 0.5) painter)) + (up (up-split smaller (- n 1))) + (right (right-split smaller (- n 1))) + (up-small (scale (vec2 0.5 1.0) up)) + (right-small (scale (vec2 1.0 0.5) right))) + (beside (below smaller + (beside up-small up-small)) + (below (below right-small right-small) + (corner-split smaller (- n 1))))))) + (define-record-type <canvas> (%make-canvas matrix compiled-path filled-path-pool stroked-path-pool tesselated-paths) |