application/octet-stream
•
1.01 KB
•
29 lines
; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
; This project uses the MIT license, a copy should be included under /LICENSE
;
;; Contains some routines for working with 2d data
[defun array/2d/allocate [width height]
@[:data [-> [array/allocate [* width height]] [array/fill! 0]] :width width :height height]
]
[defun array/2d/ref [data x y]
[if [or [> x [data :width]] [> y [data :height]]]
[throw [list :out-of-bounds "Trying to access an array out of bounds" data [current-lambda]]]
[array/ref [data :data] [+ x [* y [data :width]]]]]
]
[defun array/2d/set! [data x y val]
[if [or [> x [data :width]] [> y [data :height]]]
[throw [list :out-of-bounds "Trying to access an array out of bounds" data [current-lambda]]]
[array/set! [data :data] [+ x [* y [data :width]]] val]]
]
[defun array/2d/print [data]
[for [y 0 [data :height]]
[for [x 0 [data :width]]
[display [cat [array/2d/ref data x y] " "]]
]
[newline]
]
]