blob: ec6f8ad3140226d2ebe1ab5bbdc1edc62991751e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
let internal_id = ref 0
type t =
{ p: Gg.v2
; size : float
; angle: float
; stamp : float
; id : int
}
let empty =
{ p = Gg.V2.of_tuple (0., 0.)
; size = 0.
; angle = 0.
; stamp = 0.
; id = 0
}
let create ~angle ~width ~stamp ~x ~y =
incr internal_id;
{ p = Gg.V2.v x y
; size = width
; angle = Gg.Float.rad_of_deg (180. -. angle )
; stamp
; id = !internal_id
}
let copy point p =
{ point with
p
}
let set_angle p angle =
{ p with angle = Gg.Float.rad_of_deg (180. -. angle) }
let get_angle { angle; _} = 180. -. (Gg.Float.deg_of_rad angle)
let set_width p size =
{ p with size }
let get_width { size; _} = size
let (+) p1 p2 =
{ p1 with p = Gg.V2.(+) p1.p p2 }
let get_coord { p; _ } = p
let get_stamp { stamp; _} = stamp
let get_coord'
: t -> Gg.v2
= fun t ->
let open Gg.V2 in
let trans = of_polar @@ v t.size t.angle in
t.p + trans
let mix
: float -> Gg.v2 -> t -> t -> t
= fun f point p0 p1 ->
let angle0 = p0.angle
and angle1 = p1.angle
and width0 = get_width p0
and width1 = get_width p1
and stamp0 = get_stamp p0
and stamp1 = get_stamp p1 in
let angle = angle0 +. f *. ( angle1 -. angle0 ) in
let width = width0 +. f *. ( width1 -. width0 ) in
let stamp = stamp0 +. f *. ( stamp1 -. stamp0 ) in
{ p = point
; size = width
; angle
; stamp
; id = !internal_id
}
let id { id; _} = id
|