From 228eceeed40b0f86e75a394fe8d65e6e93ca2370 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 12 Jan 2021 13:41:00 +0100 Subject: Move path, some refactoring --- script.it/worker.ml | 54 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 16 deletions(-) (limited to 'script.it/worker.ml') 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 -- cgit v1.2.3