change Vec2 implementation to a record type
This commit is contained in:
parent
88acb381f1
commit
98f47654f8
26
src/vec2.ml
26
src/vec2.ml
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
type t [@@deriving show]
|
||||
type t =
|
||||
{ x : int
|
||||
; y : int
|
||||
}
|
||||
[@@deriving show]
|
||||
|
||||
val origin : t
|
||||
val up : t
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user