open StdLabels type t = | Path of int | Point of (int * Path.Point.t) let threshold = 20. let get_from_paths : (float * float) -> Path.Fixed.t list -> float * (Gg.v2 * Path.Fixed.t * Path.Point.t * Path.Point.t) option = fun position paths -> let point = Gg.V2.of_tuple position in (* If the user click on a curve, select it *) List.fold_left paths ~init:(threshold, None) ~f:(fun (dist, selection) path -> match Path.Fixed.distance point path with | Some (point', p, p0, p1) when p < dist -> dist, Some (point', path, p0, p1) | _ -> dist, selection ) let select_path : Path.Fixed.t -> t = fun path -> Path (Path.Fixed.id path) let select_point : Path.Fixed.t -> Gg.v2 -> t = fun path v2_point -> let point' = ref None in let dist = ref threshold in Path.Fixed.iter path ~f:(fun p -> let open Gg.V2 in let new_dist = norm ((Path.Point.get_coord p) - v2_point) in match (new_dist < !dist) with | false -> () | true -> dist:= new_dist; point' := Some p ); match !point' with | Some point -> Point (Path.Fixed.id path, point) | None -> Path (Path.Fixed.id path) (* (* If the point does not exists, find the exact point on the curve *) let coord = Gg.V2.to_tuple v2_point in begin match get_from_paths coord [path] with | _, None -> Path (Path.Fixed.id path) | f, Some (point, path, p0, p1) -> let point' = Path.Point.mix f point p0 p1 in Point (Path.Fixed.id path, point') end *)