diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-01-11 11:33:32 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2021-01-11 13:55:43 +0100 |
commit | 42c3c122c4f53dd68bcdd89411835887c3ae0af9 (patch) | |
tree | 856a54955c4bf1648e7f5f1cea809e5601b60c7d /script.it/worker.ml | |
parent | 979be5f588a1ffd6e1d060cd794e87526d517b7a (diff) |
Outline module
Diffstat (limited to 'script.it/worker.ml')
-rwxr-xr-x | script.it/worker.ml | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/script.it/worker.ml b/script.it/worker.ml index 00e4595..898df39 100755 --- a/script.it/worker.ml +++ b/script.it/worker.ml @@ -1,21 +1,43 @@ open Js_of_ocaml +let (let=?) : 'a option -> ('a -> unit) -> unit + = fun f opt -> Option.iter opt f + let post_message : Worker_messages.from_worker -> unit = Worker.post_message let execute (command: [> Worker_messages.to_worker]) = match command with - | `Complete path -> - begin match Path.Fixed.rebuild path with - | Some path -> Worker.post_message (`Complete path) - | None -> () - end - | `DeletePoint (point, path) -> - begin match Path.Fixed.remove_point path point with - | Some path -> Worker.post_message (`Complete path) - | None -> () - end + + (* 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 + Worker.post_message (`Complete {outline with path; back}) + + (* 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 + Worker.post_message (`Complete {outline with path; back}) + + (* Only evaluate the interior *) + | `Back outline -> + let back = Path.Fixed.map + outline.Outline.path + (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in + let=? back = Path.Fixed.rebuild back in + Worker.post_message (`Complete {outline with back}) + | _ -> post_message (`Other (Js.string "Unknown message received")) |