Source

caml2geom / test1.ml

Full commit
open Caml2geom
open Printf

(*-----------------------------------------------------------------------*)

let _ = printf "Coord.epsilon = %f\n" (Coord.epsilon) ;;
let _ = printf "Coord.infinity () = %f\n" (Coord.infinity ()) ;;
let _ = printf "Coord.are_near 4.00 4.09 = %B\n" (Coord.are_near 4.00 4.09) ;;
let _ = printf "Coord.are_near_eps 0.1 4.00 4.09 = %B\n" (Coord.are_near_eps 0.1 4.00 4.09);;
let _ = printf "Coord.rel_error_bound 4.00 4.09 = %B\n" (Coord.rel_error_bound 4.00 4.09) ;;
let _ = printf "Coord.rel_error_bound_eps 0.1 4.00 4.09 = %B\n" (Coord.rel_error_bound_eps 0.1 4.00 4.09);;

(*-----------------------------------------------------------------------*)

let c = Coord.epsilon

let p = Point.copy (Point.make 0. 0.) ;;
Point.set_coord p 1 50. ;;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
Point.set_coord p 0 10. ;;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
Point.normalize p ;;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
let p = Point.ccw p ;;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
let p = Point.cw p ;;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
let p = Point.neg p ;;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
Point.add_to p (Point.make 100. 100.);;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
Point.sub_from p (Point.make 100. 100.);;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
Point.mul_by p 1000.;;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;
Point.div_by p 1000.;;
let _ = printf "(%f,%f) %f\n" (Point.coord p 0) (Point.coord (Point.copy p) 1) (Point.length p);;

let q = Point.make 0. 0.;;
let _ = printf "(%f,%f) %f\n" (Point.coord q 0) (Point.coord q 1) (Point.length q);;
let q = Point.default ();;
let _ = printf "(%f,%f) %f\n" (Point.coord q 0) (Point.coord q 1) (Point.length q);;
Point.set q (Point.make (-50.) 50.);;
let _ = printf "(%f,%f) %f\n" (Point.coord q 0) (Point.coord q 1) (Point.length q);;

(*-----------------------------------------------------------------------*)

let bez = Bezier.make_order3 0. 10. 15. 1. ;;
let _ = printf "at0 -> %f\n" (Bezier.at0 bez) ;;
let _ = printf "at1 -> %f\n" (Bezier.at1 bez) ;;
let _ = printf "at 0.25 -> %f\n" (Bezier.value_at bez 0.25) ;;
let _ = printf "at 1/3 -> %f\n" (Bezier.value_at bez (1./.3.)) ;;
let _ = printf "at 0.5 -> %f\n" (Bezier.value_at bez 0.5) ;;
let _ = printf "at 2/3 -> %f\n" (Bezier.value_at bez (2./.3.)) ;;
let _ = printf "at 0.75 -> %f\n" (Bezier.value_at bez 0.75) ;;

(*-----------------------------------------------------------------------*)

let bc1 =
  Bezier_curve.of_four_points (Point.make (-1.) (-3.)) (Point.make 10. 10.) (Point.make 15. 5.) (Point.make 20. 1.) ;;
let _ =
  printf "initial_point = (%f,%f)\n" (Point.coord (Bezier_curve.initial_point bc1) 0)
    (Point.coord (Bezier_curve.initial_point bc1) 1) ;;
let _ =
  printf "final_point = (%f,%f)\n" (Point.coord (Bezier_curve.final_point bc1) 0)
    (Point.coord (Bezier_curve.final_point bc1) 1) ;;
let _ =
  printf "point_at 0.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc1 0.0) 0)
    (Point.coord (Bezier_curve.point_at bc1 0.0) 1) ;;
let _ =
  printf "point_at 0.4 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc1 0.4) 0)
    (Point.coord (Bezier_curve.point_at bc1 0.4) 1) ;;
let _ =
  printf "point_at 1.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc1 1.0) 0)
    (Point.coord (Bezier_curve.point_at bc1 1.0) 1) ;;
let _ =
  printf "value_at 0.0 = (%f,%f)\n" (Bezier_curve.value_at bc1 0.0 Coord.X)
    (Bezier_curve.value_at bc1 0.0 Coord.Y) ;;
let _ =
  printf "value_at 0.4 = (%f,%f)\n" (Bezier_curve.value_at bc1 0.4 Coord.X)
    (Bezier_curve.value_at bc1 0.4 Coord.Y) ;;
let _ =
  printf "value_at 1.0 = (%f,%f)\n" (Bezier_curve.value_at bc1 1.0 Coord.X)
    (Bezier_curve.value_at bc1 1.0 Coord.Y) ;;
let _ =
  printf "value_at 0.0 = (%f,%f)\n" (Bezier_curve.value_at (Bezier_curve.reverse bc1) 0.0 Coord.X)
    (Bezier_curve.value_at (Bezier_curve.reverse bc1) 0.0 Coord.Y) ;;
let _ =
  printf "value_at 0.4 = (%f,%f)\n" (Bezier_curve.value_at (Bezier_curve.reverse bc1) 0.4 Coord.X)
    (Bezier_curve.value_at (Bezier_curve.reverse bc1) 0.4 Coord.Y) ;;
let _ =
  printf "value_at 1.0 = (%f,%f)\n" (Bezier_curve.value_at (Bezier_curve.reverse bc1) 1.0 Coord.X)
    (Bezier_curve.value_at (Bezier_curve.reverse bc1) 1.0 Coord.Y) ;;
let _ =
  printf "point_at 0.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at (Bezier_curve.portion bc1 0. 0.4) 0.0) 0)
    (Point.coord (Bezier_curve.point_at (Bezier_curve.portion bc1 0. 0.4) 0.0) 1) ;;
let _ =
  printf "point_at 0.4 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at (Bezier_curve.portion bc1 0. 0.4) 0.4) 0)
    (Point.coord (Bezier_curve.point_at (Bezier_curve.portion bc1 0. 0.4) 0.4) 1) ;;
let _ =
  printf "point_at 1.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at (Bezier_curve.portion bc1 0. 0.4) 1.0) 0)
    (Point.coord (Bezier_curve.point_at (Bezier_curve.portion bc1 0. 0.4) 1.0) 1) ;;
let _ =
  printf "value_at 0.0 = (%f,%f)\n" (Bezier_curve.value_at (Bezier_curve.derivative bc1) 0.0 Coord.X)
    (Bezier_curve.value_at (Bezier_curve.derivative bc1) 0.0 Coord.Y) ;;
let _ =
  printf "value_at 0.4 = (%f,%f)\n" (Bezier_curve.value_at (Bezier_curve.derivative bc1) 0.4 Coord.X)
    (Bezier_curve.value_at (Bezier_curve.derivative bc1) 0.4 Coord.Y) ;;
let _ =
  printf "value_at 1.0 = (%f,%f)\n" (Bezier_curve.value_at (Bezier_curve.derivative bc1) 1.0 Coord.X)
    (Bezier_curve.value_at (Bezier_curve.derivative bc1) 1.0 Coord.Y) ;;
let bc2 =
  Bezier_curve.of_four_points (Point.make (1.) (1.)) (Point.make 10. 10.) (Point.make 15. 15.) (Point.make 20. 20.) ;;
let bc3 = Bezier_curve.of_two_points (Point.make (1.) (1.)) (Point.make 10. 10.) ;;
let bc4 =
  Bezier_curve.of_four_points (Point.make (1.) (1.)) (Point.make 1. 1.) (Point.make 1. 1.) (Point.make 1. 1.) ;;
let _ = printf "bc1 is_degenerate = %B\n" (Bezier_curve.is_degenerate bc1) ;;
let _ = printf "bc2 is_degenerate = %B\n" (Bezier_curve.is_degenerate bc2) ;;
let _ = printf "bc3 is_degenerate = %B\n" (Bezier_curve.is_degenerate bc3) ;;
let _ = printf "bc4 is_degenerate = %B\n" (Bezier_curve.is_degenerate bc4) ;;
let p_array = Bezier_curve.point_and_derivatives bc1 1.0 3 ;;
Array.iteri (fun i p -> printf "deriv %d (%f,%f)\n" i (Point.coord p 0) (Point.coord p 1)) p_array ;;
let p_array = Bezier_curve.point_and_derivatives bc2 1.0 3 ;;
Array.iteri (fun i p -> printf "deriv %d (%f,%f)\n" i (Point.coord p 0) (Point.coord p 1)) p_array ;;
let p_array = Bezier_curve.point_and_derivatives bc3 1.0 3 ;;
Array.iteri (fun i p -> printf "deriv %d (%f,%f)\n" i (Point.coord p 0) (Point.coord p 1)) p_array ;;
let p_array = Bezier_curve.point_and_derivatives bc4 1.0 3 ;;
Array.iteri (fun i p -> printf "deriv %d (%f,%f)\n" i (Point.coord p 0) (Point.coord p 1)) p_array ;;
let _ = printf "bc1 length = %f\n" (Bezier_curve.length bc1 0.01) ;;
let _ = printf "bc2 length = %f\n" (Bezier_curve.length bc2 0.01) ;;
let _ = printf "bc3 length = %f\n" (Bezier_curve.length bc3 0.01) ;;
let _ = printf "bc4 length = %f\n" (Bezier_curve.length bc4 0.01) ;;
let p1 = Point.make (-400.) (-200.) ;;
Bezier_curve.set_initial bc4 p1 ;;
let _ = printf "point_at 0.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc4 0.0) 0)
  (Point.coord (Bezier_curve.point_at bc4 0.0) 1) ;;
Point.set_coord p1 1 200. ;;
let _ = printf "point_at 0.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc4 0.0) 0)
  (Point.coord (Bezier_curve.point_at bc4 0.0) 1) ;;
Bezier_curve.set_initial bc4 p1 ;;
let _ = printf "point_at 0.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc4 0.0) 0)
  (Point.coord (Bezier_curve.point_at bc4 0.0) 1) ;;
let p1 = Point.make (500.) (300.) ;;
Bezier_curve.set_final bc4 p1 ;;
let _ = printf "point_at 1.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc4 1.0) 0)
  (Point.coord (Bezier_curve.point_at bc4 1.0) 1) ;;
Point.set_coord p1 1 (-300.) ;;
let _ = printf "point_at 1.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc4 1.0) 0)
  (Point.coord (Bezier_curve.point_at bc4 1.0) 1) ;;
Bezier_curve.set_final bc4 p1 ;;
let _ = printf "point_at 1.0 = (%f,%f)\n" (Point.coord (Bezier_curve.point_at bc4 1.0) 0)
  (Point.coord (Bezier_curve.point_at bc4 1.0) 1) ;;

let _ = printf "bc1 degrees_of_freedom = %d\n" (Bezier_curve.degrees_of_freedom bc1) ;;
let _ = printf "bc2 degrees_of_freedom = %d\n" (Bezier_curve.degrees_of_freedom bc2) ;;
let _ = printf "bc3 degrees_of_freedom = %d\n" (Bezier_curve.degrees_of_freedom bc3) ;;
let _ = printf "bc4 degrees_of_freedom = %d\n" (Bezier_curve.degrees_of_freedom bc4) ;;

(*-----------------------------------------------------------------------*)