add Vec2.iter_region

This commit is contained in:
ryan 2023-11-08 10:36:33 -08:00
parent 19a763b73f
commit 383c6c0fca
3 changed files with 10 additions and 7 deletions

View File

@ -73,13 +73,7 @@ let of_lines parse_char lines : 'a t =
;;
let iter_region grid a b callback =
let open Vec2 in
for y = min a.y b.y to max a.y b.y do
for x = min a.x b.x to max a.x b.x do
let pos = { x; y } in
if in_bounds grid pos then callback pos
done
done
Vec2.iter_region a b (fun pos -> if in_bounds grid pos then callback pos)
;;
let iter grid callback =

View File

@ -19,3 +19,11 @@ let ( + ) a b = { x = a.x + b.x; y = a.y + b.y }
let ( - ) a b = { x = a.x - b.x; y = a.y - b.y }
let ( = ) a b = a.x = b.x && a.y = b.y
let abs a = Int.{ x = abs a.x; y = abs a.y }
let iter_region a b callback =
for y = min a.y b.y to max a.y b.y do
for x = min a.x b.x to max a.x b.x do
callback { x; y }
done
done
;;

View File

@ -17,3 +17,4 @@ val ( + ) : t -> t -> t
val ( - ) : t -> t -> t
val ( = ) : t -> t -> bool
val abs : t -> t
val iter_region : t -> t -> (t -> unit) -> unit