summaryrefslogtreecommitdiff
path: root/script.it/worker.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-01-06 22:09:53 +0100
committerSébastien Dailly <sebastien@chimrod.com>2021-01-06 22:09:53 +0100
commita63662059215a26db627c4b76147a3c9338f5b74 (patch)
treec71b984b2327ebe743809e04b0a29aac0e15cc56 /script.it/worker.ml
parent6ae97ecca8b4f38213f0f45aa6eaef944cd6b497 (diff)
Point suppression
Diffstat (limited to 'script.it/worker.ml')
-rwxr-xr-xscript.it/worker.ml43
1 files changed, 25 insertions, 18 deletions
diff --git a/script.it/worker.ml b/script.it/worker.ml
index 3150869..e2408b7 100755
--- a/script.it/worker.ml
+++ b/script.it/worker.ml
@@ -3,6 +3,7 @@ open Js_of_ocaml
type message = [
| `Complete of (int * (Path.Fixed.path array))
+ | `DeletePoint of (int * Path.Point.t * Path.Fixed.t)
]
exception Empty_Element
@@ -36,27 +37,33 @@ let assoc_point
; Path.Fixed.ctrl1 = bezier.Shapes.Bezier.ctrl1
}
-let execute (command: [> message]) =
- match command with
- | `Complete (id, paths) ->
- (* Convert all the points in list *)
- let points = List.init
- ~len:((Array.length paths) )
- ~f:(fun i -> get_point (Array.get paths i)) in
- let p0 = first_point (Array.get paths 0)in
+let rebuild (id, paths) =
+ (* Convert all the points in list *)
+ let points = List.init
+ ~len:((Array.length paths) )
+ ~f:(fun i -> get_point (Array.get paths i)) in
+ let p0 = first_point (Array.get paths 0)in
+
+ let points = p0::points in
- let points = p0::points in
+ (* We process the whole curve in a single block *)
+ begin match Shapes.Bspline.to_bezier points with
+ | Error `InvalidPath -> ()
+ | Ok beziers ->
- (* We process the whole curve in a single block *)
- begin match Shapes.Bspline.to_bezier points with
- | Error `InvalidPath -> ()
- | Ok beziers ->
+ (* Now for each point, reassociate the same point information,
+ We should have as many points as before *)
+ let rebuilded = Array.map2 beziers paths ~f:assoc_point in
+ Worker.post_message (`Complete (id, rebuilded))
+ end
- (* Now for each point, reassociate the same point information,
- We should have as many points as before *)
- let rebuilded = Array.map2 beziers paths ~f:assoc_point in
- Worker.post_message (`Complete (id, rebuilded))
- end
+let execute (command: [> message]) =
+ match command with
+ | `Complete (id, paths) ->
+ rebuild (id, paths)
+ | `DeletePoint (id, point, path) ->
+ let path = Path.Fixed.remove_point path point in
+ rebuild (id, Path.Fixed.path path)
| any ->
Worker.post_message (`Other any)