Source

hack-and-slash / vec.ml

open Core.Std

module Export = struct
  type _vec = { x: int; y : int } with sexp, bin_io
  let vec x y = { x; y }
end
open Export

type t = Export._vec
with sexp, bin_io

let add t1 t2 =
  { x = t1.x + t2.x
  ; y = t1.y + t2.y
  }

let manhattan_distance t1 t2 =
  Int.abs (t1.x - t2.x) + Int.abs (t1.y - t2.y)