change Vec2 implementation to a record type

This commit is contained in:
ryan 2023-10-31 15:56:54 -07:00
parent 88acb381f1
commit 98f47654f8
2 changed files with 20 additions and 12 deletions

View File

@ -1,15 +1,19 @@
open Containers
type t = int * int [@@deriving show]
type t =
{ x : int
; y : int
}
[@@deriving show]
let origin = 0, 0
let up = 0, 1
let down = 0, -1
let left = -1, 0
let right = 1, 0
let origin = { x = 0; y = 0 }
let up = { x = 0; y = 1 }
let down = { x = 0; y = -1 }
let left = { x = -1; y = 0 }
let right = { x = 1; y = 0 }
let directions = [ up; down; left; right ]
let of_tuple x = x
let to_tuple x = x
let ( + ) a b = Pair.map_same2 ( + ) a b
let ( - ) a b = Pair.map_same2 ( - ) a b
let ( = ) a b = Pair.equal ( = ) ( = ) a b
let of_tuple (x, y) = { x; y }
let to_tuple { x; y } = x, y
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

View File

@ -1,4 +1,8 @@
type t [@@deriving show]
type t =
{ x : int
; y : int
}
[@@deriving show]
val origin : t
val up : t