aboutsummaryrefslogtreecommitdiff
path: root/script.it/path/fixed.mli
blob: 111187c7b0902243c597739320d7af8be8a016dc (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
(** Signature for points *)
module type P = sig
  type t

  val get_coord : t -> Gg.v2

  val id : t -> int

  val copy : t -> Gg.v2 -> t

end

module Make(Point:P) : sig

  module type BUILDER = sig
    type t

    val repr
      : t -> (module Repr.M with type point = Point.t and type t = 's) -> 's -> 's

  end

  type t 

  (** Create a path from a builder *)
  val to_fixed
    : (module BUILDER with type t = 'a) -> 'a -> t

  (** Represent the path *)
  val repr
    : t -> (module Repr.M with type point = Point.t and type t = 's) -> 's -> 's

  (** Structure to represent all the required information for evaluating the
      distance between a point and a path *)
  type approx =
    { distance : float
    ; closest_point : Gg.v2
    ; ratio : float
    ; p0 : Point.t
    ; p1 : Point.t }

  (** Return the distance between a given point and the curve. May return
      None if the point is out of the curve *)
  val distance
    : Gg.v2 -> t -> approx option

  (** Iterate over a path *)
  val iter
    : t -> f:(Point.t -> unit) -> unit

  (** Map all the points in the path *)
  val map
    : t -> (Point.t -> Point.t) -> t

  (** Reevaluate all the control points on the path in order to get a smooth
      curve *)
  val rebuild 
    : t -> t option

  (** Delete a point in the path. 

      Reconnect the path without the point removed, and reevaluate all the
      control points from the nodes

      return None if the point is not present in the curve
  *)
  val remove_point 
    : t -> Point.t -> t option

  (** Replace a point by the given one. 

      An existing point with the same id shall be present in the path. 

      The path is not fully evaluated, and rebuild shall be runned in order to
      get the path completely smooth.

  *)
  val replace_point 
    : t -> Point.t -> t option

end