From 1aa90219e3e74bac3afbde0ec120e098b50bd0c5 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 11 Jan 2021 13:51:21 +0100 Subject: Interior curve evaluation --- script.it/state.ml | 76 +++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 41 deletions(-) (limited to 'script.it/state.ml') 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 } -- cgit v1.2.3