aboutsummaryrefslogtreecommitdiff
path: root/script.it/state/state.ml
diff options
context:
space:
mode:
Diffstat (limited to 'script.it/state/state.ml')
-rwxr-xr-xscript.it/state/state.ml41
1 files changed, 16 insertions, 25 deletions
diff --git a/script.it/state/state.ml b/script.it/state/state.ml
index f3be91d..6c48979 100755
--- a/script.it/state/state.ml
+++ b/script.it/state/state.ml
@@ -1,3 +1,5 @@
+module Path = Script_path
+
type mode =
| Edit
| Selection of Selection.t
@@ -19,48 +21,37 @@ type state =
; mouse_down_position : Gg.v2
}
-include Application.Make(struct type t = state end)
+include Application.Make (struct
+ type t = state
+end)
+
+let post : Brr_webworkers.Worker.t -> Worker_messages.to_worker -> unit =
+ Brr_webworkers.Worker.post
-let post
- : Brr_webworkers.Worker.t -> Worker_messages.to_worker -> unit
- = Brr_webworkers.Worker.post
let insert_or_replace state ((x, y) as p) stamp path =
let width = state.width
and angle = state.angle in
let point = Path.Point.create ~x ~y ~angle ~width ~stamp in
match Path.Path_Builder.peek path with
- | None ->
- Path.Path_Builder.add_point
- point
- path
+ | None -> Path.Path_Builder.add_point point path
| Some p1 ->
- let open Gg.V2 in
+ let open Gg.V2 in
+ let p1' = Path.Point.get_coord p1 in
- let p1' = Path.Point.get_coord p1 in
+ let dist = norm (p1' - of_tuple p) in
+ if dist < 5. then path else Path.Path_Builder.add_point point path
- let dist = (norm (p1' - (of_tuple p))) in
- if dist < 5. then (
- path
- ) else (
- Path.Path_Builder.add_point
- point
- path
- )
(** Select the given segment, and modify angle and width accordingly *)
let select_segment _ (_, selected, p0, p1) state dist =
-
let point' = Path.Point.mix dist (Path.Point.get_coord p0) p0 p1 in
- let angle = (Float.round @@ 10. *. Path.Point.get_angle point') /. 10.
- and width = (Float.round @@ 10. *. Path.Point.get_width point') /. 10. in
+ let angle = (Float.round @@ (10. *. Path.Point.get_angle point')) /. 10.
+ and width = (Float.round @@ (10. *. Path.Point.get_width point')) /. 10. in
let id = Selection.select_path selected in
- { state with
- mode = (Selection id)
- ; angle
- ; width }
+ { state with mode = Selection id; angle; width }
let init =