Commits

Barry Schwartz committed 1f15cce

Split the to_cubic_beziers into three different versions for different open,closed,default.

  • Participants
  • Parent commits cccef6d

Comments (0)

Files changed (4)

File caml2geom.ml

   external close : t -> bool -> unit = "path_close_wrapper"
   external bounds_fast : t -> Rect.t option = "path_bounds_fast_wrapper"
   external bounds_exact : t -> Rect.t option = "path_bounds_exact_wrapper"
-  external to_cubic_beziers : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_wrapper"
+  external to_cubic_beziers_open : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_open_wrapper"
+  external to_cubic_beziers_closed : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_closed_wrapper"
+  external to_cubic_beziers_default : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_default_wrapper"
 end
 
 module Path : Path_type =
   external close : t -> bool -> unit = "path_close_wrapper"
   external bounds_fast : t -> Rect.t option = "path_bounds_fast_wrapper"
   external bounds_exact : t -> Rect.t option = "path_bounds_exact_wrapper"
-  external to_cubic_beziers : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_wrapper"
+  external to_cubic_beziers_open : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_open_wrapper"
+  external to_cubic_beziers_closed : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_closed_wrapper"
+  external to_cubic_beziers_default : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_default_wrapper"
 end

File caml2geom.mli

   external close : t -> bool -> unit = "path_close_wrapper"
   external bounds_fast : t -> Rect.t option = "path_bounds_fast_wrapper"
   external bounds_exact : t -> Rect.t option = "path_bounds_exact_wrapper"
-  external to_cubic_beziers : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_wrapper"
+  external to_cubic_beziers_open : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_open_wrapper"
+  external to_cubic_beziers_closed : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_closed_wrapper"
+  external to_cubic_beziers_default : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_default_wrapper"
 end
 
 module Path : Path_type

File caml2geom_stubs.c

     CAMLreturn(_opt_rect);
 }
 
-extern "C" CAMLprim value path_to_cubic_bezier_curves_wrapper(value _path, value _tol)
+Geom::Path::const_iterator end_iter(Geom::Path *path, int end_method)
+{
+    Geom::Path::const_iterator i;
+    switch (end_method) {
+        case 0:
+            i = path->end_open();
+            break;
+        case 1:
+            i = path->end_closed();
+            break;
+        default:
+            i = path->end_default();
+            break;
+    }
+    return i;
+}
+
+value path_to_cubic_bezier_curves_wrapper(value _path, value _tol, int end_method)
 {
     CAMLparam2(_path, _tol);
     CAMLlocal3(_list, _node, _curve);
     Geom::Path *path = OPAQUE_P(Geom::Path, _path);
     _list = Val_emptylist;
-    // Geom::Path::const_iterator i = path->end_default(); // FIXME: What is the situation with these end_* methods?
-    Geom::Path::const_iterator i = path->end_open();
+    Geom::Path::const_iterator i = end_iter(path, end_method);
     while (i != path->begin()) {
         i--;
         Geom::Curve *curve = i->duplicate();
             _list = _node;
         } else {
             Geom::Path p = cubicbezierpath_from_sbasis(curve->toSBasis(), Double_val(_tol));
-            // Geom::Path::const_iterator j = p.end_default(); // FIXME: What is the situation with these end_* methods?
-            Geom::Path::const_iterator j = p.end_open();
+            Geom::Path::const_iterator j = end_iter(&p, end_method);
             while (j != p.begin()) {
                 j--;
                 bc = dynamic_cast<Geom::BezierCurve*>(j->duplicate());
     CAMLreturn(_list);
 }
 
+extern "C" CAMLprim value path_to_cubic_bezier_curves_open_wrapper(value _path, value _tol)
+{
+    return path_to_cubic_bezier_curves_wrapper(_path, _tol, 0);
+}
+
+extern "C" CAMLprim value path_to_cubic_bezier_curves_closed_wrapper(value _path, value _tol)
+{
+    return path_to_cubic_bezier_curves_wrapper(_path, _tol, 1);
+}
+
+extern "C" CAMLprim value path_to_cubic_bezier_curves_default_wrapper(value _path, value _tol)
+{
+    return path_to_cubic_bezier_curves_wrapper(_path, _tol, 2);
+}
+
 //-------------------------------------------------------------------------
 let (t,d_squared) = Path.nearest_point ~from_t:0.4 ~to_t:0.9 path_a (Point.make 0. 0.) ;;
 let _ = printf "path_a nearest_point to (0.,0.) = %f %f\n" t d_squared ;;
 
-let beziers = Path.to_cubic_beziers path5 0.001 ;;
+print_newline () ;;
+let beziers = Path.to_cubic_beziers_open path5 0.001 ;;
+List.iter
+  (fun bez ->
+    let tuples = Bezier_curve.to_tuple_array bez in
+    print_string "[|";
+    Array.iter (fun (x,y) -> printf "(%f,%f);" x y) tuples;
+    print_endline "|]")
+beziers ;;
+
+print_newline () ;;
+let beziers = Path.to_cubic_beziers_closed path5 0.001 ;;
+List.iter
+  (fun bez ->
+    let tuples = Bezier_curve.to_tuple_array bez in
+    print_string "[|";
+    Array.iter (fun (x,y) -> printf "(%f,%f);" x y) tuples;
+    print_endline "|]")
+beziers ;;
+
+print_newline () ;;
+let beziers = Path.to_cubic_beziers_default path5 0.001 ;;
 List.iter
   (fun bez ->
     let tuples = Bezier_curve.to_tuple_array bez in