aboutsummaryrefslogtreecommitdiff
path: root/script.it
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
parent42c3c122c4f53dd68bcdd89411835887c3ae0af9 (diff)
Interior curve evaluation
Diffstat (limited to 'script.it')
-rwxr-xr-xscript.it/outline.ml2
-rwxr-xr-xscript.it/script.ml23
-rwxr-xr-xscript.it/state.ml76
-rwxr-xr-xscript.it/worker.ml6
-rwxr-xr-xscript.it/worker_messages/worker_messages.ml2
5 files changed, 53 insertions, 56 deletions
diff --git a/script.it/outline.ml b/script.it/outline.ml
index 4962d8e..0dbecd0 100755
--- a/script.it/outline.ml
+++ b/script.it/outline.ml
@@ -6,7 +6,7 @@ type t =
; back: Path.Fixed.t
}
-let get_id =
+let get_id () =
let id = !internal_path_id in
incr internal_path_id;
id
diff --git a/script.it/script.ml b/script.it/script.ml
index 9ef15fe..3859cc9 100755
--- a/script.it/script.ml
+++ b/script.it/script.ml
@@ -225,7 +225,10 @@ let on_change canva mouse_position timer state =
in
- Layer.Paths.to_canva (module Layer.Paths.ReprBuild) (current, current) context state.rendering;
+ let back = Path.Path_Builder.map
+ current
+ (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in
+ Layer.Paths.to_canva (module Path.Path_Builder) (current, back) context state.rendering;
List.iter state.paths
~f:(fun path ->
@@ -246,7 +249,7 @@ let on_change canva mouse_position timer state =
in
let p = path.Outline.path in
- Layer.Paths.to_canva (module Layer.Paths.ReprFixed) (p, p) context state.rendering
+ Layer.Paths.to_canva (module Path.Fixed) (p, path.Outline.back) context state.rendering
);
let () = match state.mode with
@@ -257,7 +260,7 @@ let on_change canva mouse_position timer state =
~f:(fun path ->
if id = path.Outline.id then
let p = path.Outline.path in
- Layer.Paths.to_canva (module Layer.Paths.ReprFixed) (p, p) context `Line
+ Layer.Paths.to_canva (module Path.Fixed) (p, path.Outline.back) context `Line
)
| Selection (Point (id, point)) ->
(* As before, mark the selected path *)
@@ -265,22 +268,22 @@ let on_change canva mouse_position timer state =
List.iter
state.paths
- ~f:(fun path ->
- if id = path.Outline.id then
+ ~f:(fun outline ->
+ if id = outline.Outline.id then
let path = begin match pos with
| Some pos ->
let pos_v2 = Gg.V2.of_tuple pos in
if Elements.Timer.delay timer < 0.3 then
- path.Outline.path
+ outline.Outline.path
else
let point' = Path.Point.copy point pos_v2 in
- begin match Path.Fixed.replace_point path.Outline.path point' with
- | None -> path.Outline.path
+ begin match Path.Fixed.replace_point outline.Outline.path point' with
+ | None -> outline.Outline.path
| Some p -> p
end
- | None -> path.Outline.path end in
- Layer.Paths.to_canva (module Layer.Paths.ReprFixed) (path, path) context `Line
+ | None -> outline.Outline.path end in
+ Layer.Paths.to_canva (module Path.Fixed) (path, outline.Outline.back) context `Line
);
(* Now draw the selected point *)
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 }
diff --git a/script.it/worker.ml b/script.it/worker.ml
index 898df39..51fe49c 100755
--- a/script.it/worker.ml
+++ b/script.it/worker.ml
@@ -19,7 +19,7 @@ let execute (command: [> Worker_messages.to_worker]) =
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})
+ post_message (`Complete {outline with path; back})
(* Remove the point from the main line, and reevaluate the whole path *)
| `DeletePoint (point, outline) ->
@@ -28,7 +28,7 @@ let execute (command: [> Worker_messages.to_worker]) =
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})
+ post_message (`Complete {outline with path; back})
(* Only evaluate the interior *)
| `Back outline ->
@@ -36,7 +36,7 @@ let execute (command: [> Worker_messages.to_worker]) =
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 (`Complete {outline with back})
| _ ->
post_message (`Other (Js.string "Unknown message received"))
diff --git a/script.it/worker_messages/worker_messages.ml b/script.it/worker_messages/worker_messages.ml
index a4d05c8..b33bb23 100755
--- a/script.it/worker_messages/worker_messages.ml
+++ b/script.it/worker_messages/worker_messages.ml
@@ -7,6 +7,6 @@ type to_worker = [
]
type from_worker = [
- | `Complete of Path.Fixed.t
+ | `Complete of Outline.t
| `Other of Js.js_string Js.t
]