Source file geom.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
open! Core

module Dimensions = struct
  type t =
    { height : int
    ; width : int
    }
  [@@deriving sexp, equal, compare]

  include functor Comparator.Make
end

module Position = struct
  type t =
    { x : int
    ; y : int
    }
  [@@deriving sexp, equal, compare]

  include functor Comparator.Make
end

module Region = struct
  type t =
    { x : int
    ; y : int
    ; width : int
    ; height : int
    }
  [@@deriving sexp, equal, compare]

  include functor Comparator.Make

  let contains { x; y; width; height } (position : Position.t) =
    position.x >= x
    && position.y >= y
    && position.x < x + width
    && position.y < y + height
  ;;
end