2024-01-17 13:59:05 +01:00
|
|
|
(** Type *)
|
2018-02-19 11:24:15 +01:00
|
|
|
|
2020-12-28 01:08:55 +01:00
|
|
|
type t = {
|
|
|
|
x : int ;
|
|
|
|
y : int ;
|
|
|
|
z : int ;
|
2024-01-17 13:59:05 +01:00
|
|
|
tot : int ; (* ~tot~ always contains ~x+y+z~. *)
|
2020-12-28 01:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-17 13:59:05 +01:00
|
|
|
(** Conversions *)
|
2020-12-28 01:08:55 +01:00
|
|
|
|
2021-01-28 00:34:26 +01:00
|
|
|
let of_int_tuple t =
|
2018-02-19 11:24:15 +01:00
|
|
|
let result =
|
2021-01-28 00:34:26 +01:00
|
|
|
match t with
|
2018-02-19 11:24:15 +01:00
|
|
|
| (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
|
|
|
|
|
|
|
|
|
2020-12-28 01:08:55 +01:00
|
|
|
let to_int_tuple { x ; y ; z ; _ } = (x,y,z)
|
|
|
|
|
|
|
|
|
2024-01-17 13:59:05 +01:00
|
|
|
(** Operations *)
|
2020-12-28 01:08:55 +01:00
|
|
|
|
2018-02-19 11:24:15 +01:00
|
|
|
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
|
|
|
|
2024-01-17 13:59:05 +01:00
|
|
|
|
|
|
|
(** Printers *)
|
|
|
|
|
2020-12-28 01:08:55 +01:00
|
|
|
let pp ppf t =
|
|
|
|
Format.fprintf ppf "@[x^%d + y^%d + z^%d@]" t.x t.y t.z
|
2024-01-17 13:59:05 +01:00
|
|
|
|