aboutsummaryrefslogtreecommitdiff
path: root/path/builder.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2020-12-29 21:41:47 +0100
committerSébastien Dailly <sebastien@chimrod.com>2020-12-29 21:41:47 +0100
commitfae31bdb659b4b14322136e045ea565d38bbd04f (patch)
treeb08636d488b85e0532e84135f39da33f5e47af91 /path/builder.ml
parent9d65e5e6a5bd8666baf0d7d3e0474c721cafc683 (diff)
Dynamic width
Diffstat (limited to 'path/builder.ml')
-rwxr-xr-xpath/builder.ml17
1 files changed, 15 insertions, 2 deletions
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