10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-06-19 03:35:28 +02:00
QCaml/Utils/Powers.ml

33 lines
851 B
OCaml
Raw Normal View History

2018-02-19 11:24:15 +01:00
type t = { x: int ; y : int ; z : int ; tot : int }
let of_int_tuple t =
let result =
match t with
| (x,y,z) -> { x ; y ; z ; tot=x+y+z }
in
assert (result.tot >= 0);
result
let to_int_tuple { x ; y ; z ; _ } = (x,y,z)
let get coord t =
match coord with
| Coordinate.X -> t.x
| Coordinate.Y -> t.y
| Coordinate.Z -> t.z
let incr coord t =
match coord with
2018-02-19 16:01:13 +01:00
| Coordinate.X -> let r = t.x+1 in { t with x = r ; tot = t.tot+1 }
| Coordinate.Y -> let r = t.y+1 in { t with y = r ; tot = t.tot+1 }
| Coordinate.Z -> let r = t.z+1 in { t with z = r ; tot = t.tot+1 }
2018-02-19 11:24:15 +01:00
let decr coord t =
match coord with
2018-02-19 16:01:13 +01:00
| Coordinate.X -> let r = t.x-1 in { t with x = r ; tot = t.tot-1 }
| Coordinate.Y -> let r = t.y-1 in { t with y = r ; tot = t.tot-1 }
| Coordinate.Z -> let r = t.z-1 in { t with z = r ; tot = t.tot-1 }
2018-02-19 11:24:15 +01:00