mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-07-25 04:07:24 +02:00
40 lines
932 B
OCaml
40 lines
932 B
OCaml
|
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
|
||
|
| Coordinate.X -> { t with x = t.x+1 ; tot = t.tot+1 }
|
||
|
| Coordinate.Y -> { t with y = t.y+1 ; tot = t.tot+1 }
|
||
|
| Coordinate.Z -> { t with z = t.z+1 ; tot = t.tot+1 }
|
||
|
|
||
|
let decr coord t =
|
||
|
(*
|
||
|
let test _ = ()
|
||
|
*)
|
||
|
let test x =
|
||
|
if x < 1 then
|
||
|
invalid_arg "Angular_momentum.Powers.decr";
|
||
|
in
|
||
|
match coord with
|
||
|
| Coordinate.X -> (test t.x ; { t with x = t.x-1 ; tot = t.tot-1 })
|
||
|
| Coordinate.Y -> (test t.y ; { t with y = t.y-1 ; tot = t.tot-1 })
|
||
|
| Coordinate.Z -> (test t.z ; { t with z = t.z-1 ; tot = t.tot-1 })
|
||
|
|
||
|
|
||
|
|