From 5ee27e786a3f1ed3eecc1e5c36f6e1e551388451 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 10 Jan 2021 21:28:35 +0100 Subject: Correction in the bezier drawing --- layer/paths.ml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'layer/paths.ml') diff --git a/layer/paths.ml b/layer/paths.ml index 927a5f9..e170767 100755 --- a/layer/paths.ml +++ b/layer/paths.ml @@ -1,3 +1,4 @@ +open StdLabels (** Common module for ensuring that the function is evaluated only once *) module type REPRESENTABLE = sig @@ -13,7 +14,6 @@ end module FillCanvaRepr = FillPrinter.Make(CanvaPrinter) module DuctusCanvaRepr = DuctusPrinter.Make(CanvaPrinter) module LineCanvaRepr = LinePrinter.Make(CanvaPrinter) -module WireCanvaRepr = WireFramePrinter.Make(CanvaPrinter) (* SVG representation *) @@ -21,7 +21,6 @@ module FillSVGRepr = FillPrinter.Make(Svg) module DuctusSVGRepr = DuctusPrinter.Make(Svg) module WireSVGRepr = WireFramePrinter.Make(Svg) - type printer = [ `Fill | `Line @@ -96,3 +95,50 @@ let to_svg [] | `Line -> raise Not_found + +(** Transform the two fixed path, into a single one. *) +module ReprFixed = struct + + type t = Path.Fixed.t * Path.Fixed.t + + module R = struct + type t = Path.Point.t + + type repr' = + | Move of (Path.Point.t) + | Line_to of (Path.Point.t * Path.Point.t) + | Quadratic of (t * Gg.v2 * Gg.v2 * t) + + type repr = repr' list + + let start t actions = + (Move t)::actions + + let line_to p0 p1 actions = + Line_to (p0, p1)::actions + + let quadratic_to + : (t * Gg.v2 * Gg.v2 * t) -> repr -> repr + = fun q actions -> + (Quadratic q)::actions + + let stop + : repr -> repr + = fun v -> List.rev v + + end + + let repr + : t -> (module Path.Repr.M with type t = Path.Point.t and type repr = 's) -> 's -> 's + = fun (type s) (path, _) (module Repr:Path.Repr.M with type t = Path.Point.t and type repr = s) state -> + let elems = Path.Fixed.repr path (module R) [] in + + let state = List.fold_left elems + ~init:state + ~f:(fun state -> function + | R.Move pt -> Repr.start pt state + | R.Line_to (p0, p1) -> Repr.line_to p0 p1 state + | R.Quadratic t -> Repr.quadratic_to t state + ) + in Repr.stop state +end -- cgit v1.2.3