summaryrefslogtreecommitdiff
path: root/script.it/state.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-01-11 13:51:21 +0100
committerSébastien Dailly <sebastien@chimrod.com>2021-01-11 13:55:43 +0100
commit1aa90219e3e74bac3afbde0ec120e098b50bd0c5 (patch)
tree50613ecc6f1984b9a9824fc347d064df38f33cf0 /script.it/state.ml
parent42c3c122c4f53dd68bcdd89411835887c3ae0af9 (diff)
Interior curve evaluation
Diffstat (limited to 'script.it/state.ml')
-rwxr-xr-xscript.it/state.ml76
1 files changed, 35 insertions, 41 deletions
diff --git a/script.it/state.ml b/script.it/state.ml
index 403efbe..fd35554 100755
--- a/script.it/state.ml
+++ b/script.it/state.ml
@@ -21,10 +21,7 @@ type render_event =
`Rendering of Layer.Paths.printer
]
-type worker_event =
- [ `Basic of Jv.t
- | `Complete of Outline.t
- ]
+type worker_event = Worker_messages.from_worker
type events =
[ canva_events
@@ -280,31 +277,31 @@ let do_action
| Some _ ->
let current = insert_or_replace state point stamp state.current in
- let paths =
-
- let path = Path.Fixed.to_fixed
- (module Path.Path_Builder)
- current in
-
- (* Create a copy from the path with all the interior points *)
- let back = Path.Fixed.map
- path
- (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in
-
- let last =
- { Outline.path = path
- ; Outline.back = back
- ; Outline.id = Outline.get_id
- }
- in
-
- let () = post worker (`Complete last) in
- last::state.paths
- and current = Path.Path_Builder.empty in
-
- { state with
- mode = Out
- ; paths; current }
+ let path = Path.Fixed.to_fixed
+ (module Path.Path_Builder)
+ current in
+
+ (* Create a copy from the path with all the interior points *)
+ let back = Path.Fixed.map
+ path
+ (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in
+
+ let last =
+ { Outline.path = path
+ ; Outline.back = back
+ ; Outline.id = Outline.get_id ()
+ }
+ in
+
+ (* Send to the worker for a full review *)
+ let () = post worker (`Complete last) in
+
+ let state =
+ { state with
+ mode = Out
+ ; paths = last::state.paths
+ ; current = Path.Path_Builder.empty } in
+ state
(* Else, check if there is a curve under the cursor, and remove it *)
| None ->
@@ -357,8 +354,8 @@ let do_action
Layer.Paths.to_svg
~color:Blog.Nord.nord0
- (module Layer.Paths.ReprFixed)
- (path.Outline.path, path.Outline.path)
+ (module Path.Fixed)
+ (path.Outline.path, path.Outline.back)
state.rendering
)) in
@@ -388,20 +385,17 @@ let do_action
| `Rendering rendering, _ ->
{ state with rendering}
-
- | `Basic t, _ ->
+ | `Other t, _ ->
Console.(log [t]);
state
- | `Complete path, _ ->
- let id = path.Outline.id in
- let paths = List.map state.paths
+ | `Complete newPath, _ ->
+ let paths = List.map
+ state.paths
~f:(fun line ->
- let id' = line.Outline.id in
- match id = id' with
- | false -> line
- | true -> path
- ) in
+ match newPath.Outline.id = line.Outline.id with
+ | true -> newPath
+ | false -> line) in
{ state with paths }