make Grid.set_e throw out of bounds errors

This commit is contained in:
ryan 2023-10-31 18:05:10 -07:00
parent 61e3520ede
commit 1ca2a95e1d

View File

@ -30,7 +30,12 @@ let at_e (grid : 'a t) (point : Vec2.t) =
Option.get_exn_or "point out of bounds!" @@ at grid point
;;
let set_e grid point item = Array.set grid.items (idx_of_vec2 grid.width point) item
let set_e grid point item =
if in_bounds grid point
then Array.set grid.items (idx_of_vec2 grid.width point) item
else failwith "point out of bounds!"
;;
let ( .%() ) = at_e
let ( .%()<- ) = set_e