aboutsummaryrefslogtreecommitdiff
path: root/script.it/state/selection.ml
diff options
context:
space:
mode:
Diffstat (limited to 'script.it/state/selection.ml')
-rwxr-xr-xscript.it/state/selection.ml85
1 files changed, 41 insertions, 44 deletions
diff --git a/script.it/state/selection.ml b/script.it/state/selection.ml
index f5f135a..3590a98 100755
--- a/script.it/state/selection.ml
+++ b/script.it/state/selection.ml
@@ -1,4 +1,5 @@
open StdLabels
+module Path = Script_path
type 'a selection =
| Path of 'a
@@ -6,59 +7,55 @@ type 'a selection =
type t = int selection
-let find_selection
- : int selection -> Outline.t list -> Outline.t selection option
- = fun selection paths ->
- match selection with
- | Path id -> Option.map (fun p -> Path p) (Outline.find paths id)
- | Point (id, pt) -> Option.map (fun p -> Point (p, pt)) (Outline.find paths id)
+let find_selection :
+ int selection -> Outline.t list -> Outline.t selection option =
+ fun selection paths ->
+ match selection with
+ | Path id -> Option.map (fun p -> Path p) (Outline.find paths id)
+ | Point (id, pt) ->
+ Option.map (fun p -> Point (p, pt)) (Outline.find paths id)
+
let threshold = 20.
-let get_from_paths
- : (float * float) -> Outline.t list -> float * (Gg.v2 * Outline.t * Path.Point.t * Path.Point.t) option
- = fun position outlines ->
- let point = Gg.V2.of_tuple position in
- (* If the user click on a curve, select it *)
- List.fold_left outlines
- ~init:(threshold, None)
- ~f:(fun (dist, selection) outline ->
- match Path.Fixed.distance point outline.Outline.path with
- | Some { closest_point ; distance; p0; p1 ; ratio} when distance < dist ->
- ratio, Some (closest_point, outline, p0, p1)
- | _ -> dist, selection
- )
+let get_from_paths :
+ float * float
+ -> Outline.t list
+ -> float * (Gg.v2 * Outline.t * Path.Point.t * Path.Point.t) option =
+ fun position outlines ->
+ let point = Gg.V2.of_tuple position in
+ (* If the user click on a curve, select it *)
+ List.fold_left
+ outlines
+ ~init:(threshold, None)
+ ~f:(fun (dist, selection) outline ->
+ match Path.Fixed.distance point outline.Outline.path with
+ | Some { closest_point; distance; p0; p1; ratio } when distance < dist ->
+ (ratio, Some (closest_point, outline, p0, p1))
+ | _ -> (dist, selection) )
-let select_path
- : Outline.t -> t
- = fun outline -> Path outline.Outline.id
-let select_point
- : Outline.t -> Gg.v2 -> t
- = fun outline v2_point ->
+let select_path : Outline.t -> t = fun outline -> Path outline.Outline.id
- let point' = ref None in
- let dist = ref threshold in
+let select_point : Outline.t -> Gg.v2 -> t =
+ fun outline v2_point ->
+ let point' = ref None in
+ let dist = ref threshold in
- Path.Fixed.iter
- outline.Outline.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
- );
+ Path.Fixed.iter outline.Outline.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 (outline.Outline.id, point)
- | None ->
- Path (outline.Outline.id)
+ match !point' with
+ | Some point -> Point (outline.Outline.id, point)
+ | None -> Path outline.Outline.id
- (*
+(*
(* 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