From 42c3c122c4f53dd68bcdd89411835887c3ae0af9 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 11 Jan 2021 11:33:32 +0100 Subject: Outline module --- layer/fillEngine.ml | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 layer/fillEngine.ml (limited to 'layer/fillEngine.ml') diff --git a/layer/fillEngine.ml b/layer/fillEngine.ml new file mode 100755 index 0000000..9a3fe7e --- /dev/null +++ b/layer/fillEngine.ml @@ -0,0 +1,89 @@ +module Make(Layer: Repr.PRINTER) = struct + + type point = Path.Point.t + + type repr = Layer.t + + type t = + { path: Layer.t + ; close : Layer.t -> Layer.t + } + + let create_path + : (Layer.t -> Layer.t) -> t + = fun f -> + { close = f + ; path = Layer.create () + } + + (* Start a new path. *) + + let start + : point -> point -> t -> t + = fun p1 _ {close ; path } -> + let path = Layer.move_to (Path.Point.get_coord p1) path in + { close + ; path + } + + let line_to + : (point * point) -> (point * point) -> t -> t + = fun (p0, p1) (p0', p1') t -> + + let p0 = Path.Point.get_coord p0 + and p1 = Path.Point.get_coord p1 + and p0' = Path.Point.get_coord p0' + and p1' = Path.Point.get_coord p1' in + + let path = + Layer.move_to p1 t.path + |> Layer.line_to p1' + |> Layer.line_to p0' + |> Layer.line_to p0 + |> Layer.line_to p1 + |> Layer.close in + let path = t.close path in + { t with path} + + let quadratic_to + : (point * Gg.v2 * Gg.v2 * point) -> (point * Gg.v2 * Gg.v2 * point) -> t -> t + = fun (p0, ctrl0, ctrl1, p1) (p0', ctrl0', ctrl1', p1') t -> + + let p0 = Path.Point.get_coord p0 + and p1 = Path.Point.get_coord p1 + and p0' = Path.Point.get_coord p0' + and p1' = Path.Point.get_coord p1' + in + + let path = + Layer.move_to p1 t.path + |> Layer.line_to p1' + + (* Backward *) + |> Layer.quadratic_to + ctrl1' + ctrl0' + p0' + |> Layer.line_to p0 + + (* Forward *) + |> Layer.quadratic_to + ctrl0 + ctrl1 + p1 + |> Layer.close + |> t.close in + + + { t with path } + + let stop + : t -> t + = fun t -> + t + + let get + : t -> Layer.t + = fun t -> + t.path +end -- cgit v1.2.3