More cleanup, fix things broken in last cleanup

This commit is contained in:
Dane Johnson 2024-11-19 11:53:59 -06:00
parent f4b52415dc
commit 3eb52aa430
2 changed files with 8 additions and 13 deletions

View File

@ -18,18 +18,14 @@
(set-node-color (cdr pair) red)
(cdr pair))))
graph))
(define djikstra-generator
(define (make-graph-generator f)
(generator
(djikstra graph 90 9 (lambda (visited heap)
(yield (color-graph graph visited heap))))
#f))
(define a*-generator
(generator
(a* graph 90 9 (lambda (visited heap)
(f graph 90 9 (lambda (visited heap)
(yield (color-graph graph visited heap))))
#f))
(define djikstra-generator (make-graph-generator djikstra))
(define a*-generator (make-graph-generator a*))
(write-graphs-to-file "djikstra.webp" djikstra-generator)
(write-graphs-to-file "astar.webp" a*-generator)

View File

@ -33,12 +33,11 @@
(lambda (node)
(cairo-set-source cr black)
(let-values ([(x y) (car+cdr (node-coords node))]
[edges (node-edges node)])
[(edges) (node-edges node)])
(for-each
(lambda (edge)
(let* ([other (assq-ref graph edge)]
[ox (car (node-coords other))]
[oy (cdr (node-coords other))])
(let*-values ([(other) (assq-ref graph edge)]
[(ox oy) (car+cdr (node-coords other))])
(cairo-move-to cr x y)
(cairo-line-to cr ox oy)
(cairo-stroke cr)))
@ -48,7 +47,7 @@
"Creates a closure that draws the nodes of graph using cr"
(lambda (node)
(let-values ([(x y) (car+cdr (node-coords node))]
[color (or (node-color node) white)])
[(color) (or (node-color node) white)])
(cairo-arc cr x y 4. 0. tau)
(cairo-set-source cr color)
(cairo-fill-preserve cr)