Source of the module: r_collide.ml.
The couple (x, y) stands for the position of the rectangle and
(w, h) stands for the width and the height.
let r_collide a b = if ((a.x + a.w) <= b.x) then (false) else if (a.x >= (b.x + b.w)) then (false) else if ((a.y + a.h) <= b.y) then (false) else if (a.y >= (b.y + b.h)) then (false) else (true) let r_collide_2 a b = if ((a.x + a.w) < b.x) then (false) else if (a.x > (b.x + b.w)) then (false) else if ((a.y + a.h) < b.y) then (false) else if (a.y > (b.y + b.h)) then (false) else (true)
$ \ocaml r_collide.ml false true
The first function detects if the rectangles collide-only
or if they collide-or-touch.
# collide_only := false # collide_or_touch := true