change Vec2 implementation to a record type
This commit is contained in:
1 parent
88acb381f1
commit
98f47654f8
2 files changed
+20
-12
No files matched your search
+15
-11
@@ -1,15 +1,19 @@
|
|||||||
open Containers
|
open Containers
|
||||||
|
|
||||||
type t = int * int [@@deriving show]
|
type t =
|
||||||
|
{ x : int
|
||||||
|
; y : int
|
||||||
|
}
|
||||||
|
[@@deriving show]
|
||||||
|
|
||||||
let origin = 0, 0
|
let origin = { x = 0; y = 0 }
|
||||||
let up = 0, 1
|
let up = { x = 0; y = 1 }
|
||||||
let down = 0, -1
|
let down = { x = 0; y = -1 }
|
||||||
let left = -1, 0
|
let left = { x = -1; y = 0 }
|
||||||
let right = 1, 0
|
let right = { x = 1; y = 0 }
|
||||||
let directions = [ up; down; left; right ]
|
let directions = [ up; down; left; right ]
|
||||||
let of_tuple x = x
|
let of_tuple (x, y) = { x; y }
|
||||||
let to_tuple x = x
|
let to_tuple { x; y } = x, y
|
||||||
let ( + ) a b = Pair.map_same2 ( + ) a b
|
let ( + ) a b = { x = a.x + b.x; y = a.y + b.y }
|
||||||
let ( - ) a b = Pair.map_same2 ( - ) a b
|
let ( - ) a b = { x = a.x - b.x; y = a.y - b.y }
|
||||||
let ( = ) a b = Pair.equal ( = ) ( = ) a b
|
let ( = ) a b = a.x = b.x && a.y = b.y
|
||||||
+5
-1
@@ -1,4 +1,8 @@
|
|||||||
type t [@@deriving show]
|
type t =
|
||||||
|
{ x : int
|
||||||
|
; y : int
|
||||||
|
}
|
||||||
|
[@@deriving show]
|
||||||
|
|
||||||
val origin : t
|
val origin : t
|
||||||
val up : t
|
val up : t
|
||||||
|
|||||||
Reference in new issue
Block a user