aboutsummaryrefslogtreecommitdiff
path: root/script.it/worker.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-01-12 13:41:00 +0100
committerSébastien Dailly <sebastien@chimrod.com>2021-01-12 14:07:56 +0100
commit228eceeed40b0f86e75a394fe8d65e6e93ca2370 (patch)
tree1409c2d9aa6924a35464e30af78e7281502ab36e /script.it/worker.ml
parent1aa90219e3e74bac3afbde0ec120e098b50bd0c5 (diff)
Move path, some refactoring
Diffstat (limited to 'script.it/worker.ml')
-rwxr-xr-xscript.it/worker.ml54
1 files changed, 38 insertions, 16 deletions
diff --git a/script.it/worker.ml b/script.it/worker.ml
index 51fe49c..62104ec 100755
--- a/script.it/worker.ml
+++ b/script.it/worker.ml
@@ -7,28 +7,28 @@ let post_message
: Worker_messages.from_worker -> unit
= Worker.post_message
-let execute (command: [> Worker_messages.to_worker]) =
+
+let rebuild outline =
+ let path = outline.Outline.path in
+
+ let=? path = Path.Fixed.rebuild path in
+ let back = Path.Fixed.map
+ path
+ (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in
+ let=? back = Path.Fixed.rebuild back in
+ post_message (`Complete {outline with path; back})
+
+let execute (command: Worker_messages.to_worker) =
match command with
(* Full rebuild, evaluate the whole path *)
| `Complete outline ->
- let path = outline.Outline.path in
-
- let=? path = Path.Fixed.rebuild path in
- let back = Path.Fixed.map
- path
- (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in
- let=? back = Path.Fixed.rebuild back in
- post_message (`Complete {outline with path; back})
+ rebuild outline
(* Remove the point from the main line, and reevaluate the whole path *)
| `DeletePoint (point, outline) ->
let=? path = Path.Fixed.remove_point outline.Outline.path point in
- let back = Path.Fixed.map
- path
- (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in
- let=? back = Path.Fixed.rebuild back in
- post_message (`Complete {outline with path; back})
+ rebuild { outline with path }
(* Only evaluate the interior *)
| `Back outline ->
@@ -38,8 +38,30 @@ let execute (command: [> Worker_messages.to_worker]) =
let=? back = Path.Fixed.rebuild back in
post_message (`Complete {outline with back})
- | _ ->
- post_message (`Other (Js.string "Unknown message received"))
+ | `TranslatePath (outline, delta) ->
+ let path = Path.Fixed.map
+ outline.path
+ (fun pt -> Path.Point.get_coord pt
+ |> Gg.V2.add delta
+ |> Path.Point.copy pt)
+ and back = Path.Fixed.map
+ outline.back
+ (fun pt -> Path.Point.get_coord pt
+ |> Gg.V2.add delta
+ |> Path.Point.copy pt) in
+ post_message (`Complete {outline with path; back})
+
+ | `TranslatePoint (point, outline) ->
+ (* I do not use the function Path.Fixed.replace_point here, I just
+ replace the point position and run a full rebuild *)
+ let path = Path.Fixed.map outline.path
+ (fun pt ->
+ match Path.Point.id pt = Path.Point.id point with
+ | true -> point
+ | false -> pt
+ ) in
+
+ rebuild { outline with path }
let () =
Worker.set_onmessage execute