summaryrefslogtreecommitdiff
path: root/chickadee/math
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2020-11-19 08:20:56 -0500
committerDavid Thompson <dthompson2@worcester.edu>2020-11-19 08:20:56 -0500
commit4eb0c696bc575210448f79eab92f4eb6965e75f9 (patch)
tree24fc79ae12823693ed7f061f57824124114e19b1 /chickadee/math
parent3d0016c9b83ff71deaf34c7f8a497758a8a310d2 (diff)
math: grid: Add grid-cell-fold and grid-item-fold procedures.
Diffstat (limited to 'chickadee/math')
-rw-r--r--chickadee/math/grid.scm16
1 files changed, 15 insertions, 1 deletions
diff --git a/chickadee/math/grid.scm b/chickadee/math/grid.scm
index 830f7d6..7b2b6d6 100644
--- a/chickadee/math/grid.scm
+++ b/chickadee/math/grid.scm
@@ -45,7 +45,9 @@
grid-item-count
grid-rect-ref
for-each-cell
- for-each-item))
+ grid-cell-fold
+ for-each-item
+ grid-item-fold))
;;;
@@ -192,10 +194,22 @@ cell if RECT is #f."
row))
(grid-rows grid))))
+(define (grid-cell-fold proc init grid)
+ (hash-fold (lambda (y row memo)
+ (hash-fold (lambda (x cell memo)
+ (proc cell x y memo))
+ memo
+ row))
+ init
+ (grid-rows grid)))
+
(define (for-each-item proc grid)
"Call PROC for each item in GRID."
(hash-for-each proc (grid-rects grid)))
+(define (grid-item-fold proc init grid)
+ (hash-fold proc init (grid-rects grid)))
+
(define (grid-add grid item x y width height)
"Add ITEM to GRID represented by axis-aligned bounding box defined
by X, Y, WIDTH, HEIGHT."