From fae31bdb659b4b14322136e045ea565d38bbd04f Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 29 Dec 2020 21:41:47 +0100 Subject: Dynamic width --- path/builder.ml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'path/builder.ml') diff --git a/path/builder.ml b/path/builder.ml index 3ccad9c..39ff75e 100755 --- a/path/builder.ml +++ b/path/builder.ml @@ -337,14 +337,15 @@ module Make(Point:P) = struct |> (fun b -> Gg.Box2.add_pt b bezier.ctrl0) |> (fun b -> Gg.Box2.add_pt b bezier.ctrl1) + (** Return the distance between a given point and the curve. May return + None if the point is out of the curve *) let distance : Gg.v2 -> fixedPath -> float option = fun point beziers -> Array.fold_left beziers.path ~init:None - ~f:(fun res path -> - match path with + ~f:(fun res -> function | Empty -> None | Line (p0, p1) -> let box = Gg.Box2.of_pts (Point.get_coord p0) (Point.get_coord p1) in @@ -377,4 +378,16 @@ module Make(Point:P) = struct let id : fixedPath -> int = fun {id; _} -> id + + let map_point + : fixedPath -> (Point.t -> Point.t) -> fixedPath + = fun {id; path} f -> + let path = Array.map path + ~f:(function + | Empty -> Empty + | Line (p1, p2) -> Line (f p1, f p2) + | Curve bezier -> Curve {bezier with p0 = f bezier.p0 ; p1 = f bezier.p1} + ) in + {id; path} + end -- cgit v1.2.3