aboutsummaryrefslogtreecommitdiff
path: root/path
diff options
context:
space:
mode:
Diffstat (limited to 'path')
-rwxr-xr-xpath/builder.ml17
-rwxr-xr-xpath/builder.mli3
-rwxr-xr-xpath/point.ml6
-rwxr-xr-xpath/point.mli4
4 files changed, 28 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
diff --git a/path/builder.mli b/path/builder.mli
index 557cdfa..ca496f7 100755
--- a/path/builder.mli
+++ b/path/builder.mli
@@ -74,4 +74,7 @@ module Make(P:P) : sig
val id
: fixedPath -> int
+
+ val map_point
+ : fixedPath -> (P.t -> P.t) -> fixedPath
end
diff --git a/path/point.ml b/path/point.ml
index abb9515..06eb635 100755
--- a/path/point.ml
+++ b/path/point.ml
@@ -19,6 +19,12 @@ let create ~angle ~width ~x ~y =
let copy point p =
{ point with p }
+let set_angle p angle =
+ { p with angle = Gg.Float.rad_of_deg (180. -. angle) }
+
+let set_width p size =
+ { p with size }
+
let (+) p1 p2 =
{ p1 with p = Gg.V2.(+) p1.p p2 }
diff --git a/path/point.mli b/path/point.mli
index 2c687ab..649a3be 100755
--- a/path/point.mli
+++ b/path/point.mli
@@ -10,5 +10,9 @@ val create: angle:float -> width:float -> x:float -> y:float -> t
val copy : t -> Gg.v2 -> t
+val set_angle : t -> float -> t
+
+val set_width: t -> float -> t
+
val get_coord'
: t -> Gg.v2