10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-09 15:43:41 +01:00
QCaml/common/lib/powers.ml

37 lines
958 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
2018-02-25 00:53:09 +01:00
if result.x < 0 ||
result.y < 0 ||
result.z < 0 ||
result.tot < 0 then
invalid_arg (__FILE__^": of_int_tuple");
2018-02-19 11:24:15 +01:00
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