From c734c1b30fd1c58a0d42020859be31d89b92bcd0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sat, 9 Jan 2021 11:35:02 +0100 Subject: Moved tools library inside the shapes one --- shapes/tools/dune | 6 +++++ shapes/tools/utils.ml | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ shapes/tools/utils.mli | 21 +++++++++++++++++ tools/dune | 6 ----- tools/utils.ml | 63 -------------------------------------------------- tools/utils.mli | 21 ----------------- 6 files changed, 90 insertions(+), 90 deletions(-) create mode 100755 shapes/tools/dune create mode 100755 shapes/tools/utils.ml create mode 100755 shapes/tools/utils.mli delete mode 100755 tools/dune delete mode 100755 tools/utils.ml delete mode 100755 tools/utils.mli diff --git a/shapes/tools/dune b/shapes/tools/dune new file mode 100755 index 0000000..a2c3fdb --- /dev/null +++ b/shapes/tools/dune @@ -0,0 +1,6 @@ +(library + (name tools) + (libraries + gg + ) + ) diff --git a/shapes/tools/utils.ml b/shapes/tools/utils.ml new file mode 100755 index 0000000..b8a473f --- /dev/null +++ b/shapes/tools/utils.ml @@ -0,0 +1,63 @@ +open Gg.V2 + +let norm_angle vect = + mod_float + ((angle vect) +. Gg.Float.two_pi) + Gg.Float.two_pi + + +let intersection + : (Gg.v2 * Gg.v2) -> (Gg.v2 * Gg.v2) -> Gg.v2 option + = fun (p0, p1) (p2, p3) -> + let i = p1 - p0 + and j = p3 - p2 in + + let d = (x i *. y j) -. (y i *. x j) in + if Float.( (abs d) <= 0.01 ) then + None + else + let m = ((x i) *. (y p0) + -. (x i) *. (y p2) + -. (y i) *. (x p0) + +. (y i) *. (x p2)) /. d in + Some (p2 + m * j) + (* + let k = ((x j) *. (y p0) + -. (x j) *. (y p2) + -. (y j) *. (x p0) + +. (y j) *. (x p2)) /. d in + Some (p0 + k * i) + *) + + +let center + : Gg.v2 -> Gg.v2 -> Gg.v2 -> Gg.v2 option + = fun p0 p1 p2 -> + (* deltas *) + let d1 = p1 - p0 + and d2 = p2 - p1 in + + (* perpendiculars *) + let d1p = ortho d1 + and d2p = ortho d2 in + + (* Chord midpoints *) + let m1 = half (p0 + p1) + and m2 = half (p1 + p2) in + + (* midpoint offsets *) + let m1n = m1 + d1p + and m2n = m2 + d2p in + + intersection (m1, m1n) (m2, m2n) + +let rotate + : Gg.v2 -> float -> Gg.v2 + = fun p0 theta -> + let r = x (to_polar p0) in + of_polar (v r theta) + +let equal_point + : float -> Gg.v2 -> Gg.v2 -> bool + = fun eps p0 p1 -> + Gg.V2.equal_f (fun v0 v1 -> (Float.abs (v1 -. v0)) <= eps ) p0 p1 diff --git a/shapes/tools/utils.mli b/shapes/tools/utils.mli new file mode 100755 index 0000000..4e12906 --- /dev/null +++ b/shapes/tools/utils.mli @@ -0,0 +1,21 @@ +(** Return a normalize angle *) +val norm_angle + : Gg.v2 -> float + +(** return the interesction for two segments *) +val intersection + : (Gg.v2 * Gg.v2) -> (Gg.v2 * Gg.v2) -> Gg.v2 option + +(** Return the center of the cercle for three points + None if the point cannot be evaluated +*) +val center + : Gg.v2 -> Gg.v2 -> Gg.v2 -> Gg.v2 option + +(** Rotate the vector by the given angle *) +val rotate + : Gg.v2 -> float -> Gg.v2 + +(** Test equality between two points *) +val equal_point + : float -> Gg.v2 -> Gg.v2 -> bool diff --git a/tools/dune b/tools/dune deleted file mode 100755 index a2c3fdb..0000000 --- a/tools/dune +++ /dev/null @@ -1,6 +0,0 @@ -(library - (name tools) - (libraries - gg - ) - ) diff --git a/tools/utils.ml b/tools/utils.ml deleted file mode 100755 index b8a473f..0000000 --- a/tools/utils.ml +++ /dev/null @@ -1,63 +0,0 @@ -open Gg.V2 - -let norm_angle vect = - mod_float - ((angle vect) +. Gg.Float.two_pi) - Gg.Float.two_pi - - -let intersection - : (Gg.v2 * Gg.v2) -> (Gg.v2 * Gg.v2) -> Gg.v2 option - = fun (p0, p1) (p2, p3) -> - let i = p1 - p0 - and j = p3 - p2 in - - let d = (x i *. y j) -. (y i *. x j) in - if Float.( (abs d) <= 0.01 ) then - None - else - let m = ((x i) *. (y p0) - -. (x i) *. (y p2) - -. (y i) *. (x p0) - +. (y i) *. (x p2)) /. d in - Some (p2 + m * j) - (* - let k = ((x j) *. (y p0) - -. (x j) *. (y p2) - -. (y j) *. (x p0) - +. (y j) *. (x p2)) /. d in - Some (p0 + k * i) - *) - - -let center - : Gg.v2 -> Gg.v2 -> Gg.v2 -> Gg.v2 option - = fun p0 p1 p2 -> - (* deltas *) - let d1 = p1 - p0 - and d2 = p2 - p1 in - - (* perpendiculars *) - let d1p = ortho d1 - and d2p = ortho d2 in - - (* Chord midpoints *) - let m1 = half (p0 + p1) - and m2 = half (p1 + p2) in - - (* midpoint offsets *) - let m1n = m1 + d1p - and m2n = m2 + d2p in - - intersection (m1, m1n) (m2, m2n) - -let rotate - : Gg.v2 -> float -> Gg.v2 - = fun p0 theta -> - let r = x (to_polar p0) in - of_polar (v r theta) - -let equal_point - : float -> Gg.v2 -> Gg.v2 -> bool - = fun eps p0 p1 -> - Gg.V2.equal_f (fun v0 v1 -> (Float.abs (v1 -. v0)) <= eps ) p0 p1 diff --git a/tools/utils.mli b/tools/utils.mli deleted file mode 100755 index 4e12906..0000000 --- a/tools/utils.mli +++ /dev/null @@ -1,21 +0,0 @@ -(** Return a normalize angle *) -val norm_angle - : Gg.v2 -> float - -(** return the interesction for two segments *) -val intersection - : (Gg.v2 * Gg.v2) -> (Gg.v2 * Gg.v2) -> Gg.v2 option - -(** Return the center of the cercle for three points - None if the point cannot be evaluated -*) -val center - : Gg.v2 -> Gg.v2 -> Gg.v2 -> Gg.v2 option - -(** Rotate the vector by the given angle *) -val rotate - : Gg.v2 -> float -> Gg.v2 - -(** Test equality between two points *) -val equal_point - : float -> Gg.v2 -> Gg.v2 -> bool -- cgit v1.2.3