aboutsummaryrefslogtreecommitdiff
path: root/layer/fillPrinter.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-01-03 05:42:35 +0100
committerSébastien Dailly <sebastien@chimrod.com>2021-01-03 20:19:14 +0100
commita8f37f041dce3f16917b6659d3ca97492f178f4d (patch)
tree35223969024c9ebaed7309b5a6299f8de5f18d1f /layer/fillPrinter.ml
parent20addbe8fd0ac4c79c8a69a4f888ec320a9ca4c3 (diff)
Communication with webworker
Diffstat (limited to 'layer/fillPrinter.ml')
-rwxr-xr-xlayer/fillPrinter.ml73
1 files changed, 73 insertions, 0 deletions
diff --git a/layer/fillPrinter.ml b/layer/fillPrinter.ml
new file mode 100755
index 0000000..2297d15
--- /dev/null
+++ b/layer/fillPrinter.ml
@@ -0,0 +1,73 @@
+module Point = Path.Point
+module Make(Repr: Repr.PRINTER) = struct
+
+ type t = Point.t
+
+ type repr =
+ { path: Repr.t
+ ; close : Repr.t -> Repr.t
+ }
+
+ let create_path
+ : (Repr.t -> Repr.t) -> repr
+ = fun f ->
+ { close = f
+ ; path = Repr.create ()
+ }
+
+ (* Start a new path. *)
+ let start
+ : Path.Point.t -> repr -> repr
+ = fun t {close ; path } ->
+ let path = Repr.move_to (Point.get_coord t) path in
+ { close
+ ; path
+ }
+
+ let line_to
+ : Point.t -> Point.t -> repr -> repr
+ = fun p0 p1 t ->
+ let path =
+ Repr.move_to (Point.get_coord p1) t.path
+ |> Repr.line_to (Point.get_coord' p1)
+ |> Repr.line_to (Point.get_coord' p0)
+ |> Repr.line_to (Point.get_coord p0)
+ |> Repr.line_to (Point.get_coord p1)
+ |> Repr.close in
+ let path = t.close path in
+ { t with path}
+
+ let quadratic_to
+ : Point.t -> Gg.v2 -> Gg.v2 -> Point.t -> repr -> repr
+ = fun p0 ctrl0 ctrl1 p1 t ->
+
+ let ctrl0' = Point.copy p1 ctrl0
+ and ctrl1' = Point.copy p1 ctrl1 in
+
+ let path =
+ Repr.move_to (Point.get_coord p1) t.path
+ |> Repr.line_to (Point.get_coord' p1)
+ |> Repr.quadratic_to
+ (Point.get_coord' ctrl1')
+ (Point.get_coord' ctrl0')
+ (Point.get_coord' p0)
+ |> Repr.line_to (Point.get_coord p0)
+ |> Repr.quadratic_to
+ (Point.get_coord ctrl0')
+ (Point.get_coord ctrl1')
+ (Point.get_coord p1)
+ |> Repr.close in
+ let path = t.close path in
+ { t with path}
+
+
+ let stop
+ : repr -> repr
+ = fun t ->
+ t
+
+ let get
+ : repr -> Repr.t
+ = fun t ->
+ t.path
+end