diff options
Diffstat (limited to 'layer')
-rwxr-xr-x | layer/ductusPrinter.ml | 4 | ||||
-rwxr-xr-x | layer/fillPrinter.ml | 68 | ||||
-rwxr-xr-x | layer/paths.ml | 6 |
3 files changed, 62 insertions, 16 deletions
diff --git a/layer/ductusPrinter.ml b/layer/ductusPrinter.ml index 2ee96e4..8383a9c 100755 --- a/layer/ductusPrinter.ml +++ b/layer/ductusPrinter.ml @@ -46,9 +46,9 @@ module Make(Repr: Repr.PRINTER) = struct recent point *) let delay = ((Path.Point.get_stamp p0) -. (Path.Point.get_stamp p1)) - *. 20. + *. 30. in - for i = 0 to ((Int.of_float delay) -1) do + for i = 0 to ((Int.of_float delay) ) do let ratio = (Float.of_int i) /. delay in let bezier', _ = Shapes.Bezier.slice ratio bezier in diff --git a/layer/fillPrinter.ml b/layer/fillPrinter.ml index 2297d15..3093ada 100755 --- a/layer/fillPrinter.ml +++ b/layer/fillPrinter.ml @@ -1,6 +1,47 @@ module Point = Path.Point + + + module Make(Repr: Repr.PRINTER) = struct + (* Divide a curve in subelements *) + let rec divide level p0 ctrl0 ctrl1 p1 path = + + let bezier = + { Shapes.Bezier.p0 = Path.Point.get_coord p0 + ; ctrl0 + ; ctrl1 + ; p1 = Path.Point.get_coord p1 + } in + + let ratio = 0.5 in + let bezier0, bezier1 = Shapes.Bezier.slice ratio bezier in + let point = Path.Point.mix ratio bezier0.Shapes.Bezier.p1 p0 p1 in + + let ctrl0_0 = Point.copy p0 bezier0.Shapes.Bezier.ctrl0 + and ctrl0_1 = Point.copy point bezier0.Shapes.Bezier.ctrl1 + + and ctrl1_0 = Point.copy point bezier1.Shapes.Bezier.ctrl0 + and ctrl1_1 = Point.copy p1 bezier1.Shapes.Bezier.ctrl1 in + + + match level with + | 0 -> + path := + Repr.quadratic_to + (Point.get_coord' @@ ctrl1_1) + (Point.get_coord' @@ ctrl1_0) + (Point.get_coord' point) !path; + + path := + Repr.quadratic_to + (Point.get_coord' @@ ctrl0_1) + (Point.get_coord' @@ ctrl0_0) + (Point.get_coord' p0) !path; + | n -> + divide (n-1) point (Point.get_coord ctrl1_0) (Point.get_coord ctrl1_1) p1 path; + divide (n-1) p0 (Point.get_coord ctrl0_0) (Point.get_coord ctrl0_1) point path; + type t = Point.t type repr = @@ -44,19 +85,24 @@ module Make(Repr: Repr.PRINTER) = struct 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 + let path = Repr.move_to (Point.get_coord p1) t.path + |> Repr.line_to (Point.get_coord' p1) in + let path = ref path in + + (* Backward *) + divide 3 p0 ctrl0 ctrl1 p1 path ; + path := Repr.line_to (Point.get_coord p0) !path; + + (* Forward *) + path := Repr.quadratic_to (Point.get_coord ctrl0') (Point.get_coord ctrl1') - (Point.get_coord p1) - |> Repr.close in + (Point.get_coord p1) !path; + + let path = !path in + + let path = Repr.close path in + let path = t.close path in { t with path} diff --git a/layer/paths.ml b/layer/paths.ml index 59215df..927a5f9 100755 --- a/layer/paths.ml +++ b/layer/paths.ml @@ -85,9 +85,9 @@ let to_svg | `Ductus -> let svg_path = R.repr path - (module WireSVGRepr) - (WireSVGRepr.create_path (fun _ -> ())) - |> WireSVGRepr.get in + (module DuctusSVGRepr) + (DuctusSVGRepr.create_path (fun _ -> ())) + |> DuctusSVGRepr.get in Svg.path ~at:Brr.At.[ v (Jstr.v "fill") color |