summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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."