aboutsummaryrefslogtreecommitdiff
path: root/layer/paths.ml
diff options
context:
space:
mode:
Diffstat (limited to 'layer/paths.ml')
-rwxr-xr-xlayer/paths.ml50
1 files changed, 48 insertions, 2 deletions
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