aboutsummaryrefslogtreecommitdiff
path: root/path/builder.mli
blob: f5adef137dd5d5468730c49c711356bb2ff05853 (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
78
79
80
81
82
83
84
85
86
(** Signature for points *)
module type P = sig
  type t

  val empty : t

  val get_coord : t -> Gg.v2

  (** Copy a point and all thoses properties to the given location *)
  val copy : t -> Gg.v2 -> t

end

module type REPR = sig
  type t

  type 'a repr

  val create_path
    : unit -> 'a repr

  (* Start a new path. *)
  val start
    : t -> 'a repr -> 'a repr

  val line_to
    : t -> t -> 'a repr -> 'a repr

  val quadratic_to
    : t -> Gg.v2 -> Gg.v2 -> t -> 'a repr -> 'a repr

  val stop
    : 'a repr -> 'a repr
end

module Make(P:P) : sig

  type bezier =
    { p0:P.t        (* The starting point *)
    ; p1:P.t        (* The end point *)
    ; ctrl0:Gg.v2   (* The control point *)
    ; ctrl1:Gg.v2 } (* The control point *)

  type t

  (** Create an empty path *)
  val empty: t

  val add_point
    : P.t -> t -> t

  (** Replace the last alement in the path by the one given in parameter *)
  val replace_last
    : P.t -> t -> t

  (** Retrieve the last element, if any *)
  val peek 
    : t -> P.t option

  (** Retrieve the last element, if any *)
  val peek2
    : t -> (P.t * P.t) option

  val get
    : t -> P.t list * bezier list

  val points_to_beziers
    : P.t list -> Shapes.Bezier.t array -> bezier array

  module Draw(Repr:REPR with type t = P.t) : sig

    (** Represent the the current path *)
    val draw
      : t -> 'a Repr.repr
  end

  type fixedPath

  val to_fixed : t -> fixedPath

  module DrawFixed(Repr:REPR with type t = P.t) : sig 
    val draw
      : fixedPath -> 'a Repr.repr
  end

end