Commits

Barry Schwartz committed 3637243

Rewrote path_to_cubic_bezier_curves_wrapper to avoid conversion of curve type when it is unnecessary (linear or cubic bezier). Fixed signatures of the Caml functions.

Comments (0)

Files changed (4)

   external empty : t -> bool = "path_empty_wrapper"
   external closed : t -> bool = "path_closed_wrapper"
   external close : t -> bool -> unit = "path_close_wrapper"
-  external to_cubic_beziers : t -> float -> Cubic_bezier.t list = "path_to_cubic_bezier_curves_wrapper"
+  external to_cubic_beziers : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_wrapper"
 end
 
 module Path : Path_type =
   external empty : t -> bool = "path_empty_wrapper"
   external closed : t -> bool = "path_closed_wrapper"
   external close : t -> bool -> unit = "path_close_wrapper"
-  external to_cubic_beziers : t -> float -> Cubic_bezier.t list = "path_to_cubic_bezier_curves_wrapper"
+  external to_cubic_beziers : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_wrapper"
 end
   external empty : t -> bool = "path_empty_wrapper"
   external closed : t -> bool = "path_closed_wrapper"
   external close : t -> bool -> unit = "path_close_wrapper"
-  external to_cubic_beziers : t -> float -> Cubic_bezier.t list = "path_to_cubic_bezier_curves_wrapper"
+  external to_cubic_beziers : t -> float -> Bezier_curve.t list = "path_to_cubic_bezier_curves_wrapper"
 end
 
 module Path : Path_type

caml2geom_stubs.c

     CAMLparam2(_path, _tol);
     CAMLlocal3(_list, _node, _curve);
     Geom::Path *path = OPAQUE_P(Geom::Path, _path);
-    Geom::Piecewise<Geom::D2<Geom::SBasis> > sb = path->toPwSb();
-    std::vector<Geom::Path> cubic_paths = path_from_piecewise(sb, Double_val(_tol), true);
     _list = Val_emptylist;
-    for (int i = (int)cubic_paths.size() - 1; 0 <= i; i--) {
-        Geom::Path *p = &cubic_paths[i];
-        for (Geom::Path::const_iterator j = p->end_default(); j != p->begin(); j--) {
-            Geom::Path::const_iterator k = j;
-            k--;
-            Geom::BezierCurve *curve = dynamic_cast<Geom::BezierCurve*>(k->duplicate());
+    Geom::Path::const_iterator i = path->end_default();
+    while (i != path->begin()) {
+        i--;
+        Geom::Curve *curve = i->duplicate();
+        Geom::BezierCurve *bc = dynamic_cast<Geom::BezierCurve*>(curve);
+        if (bc != NULL && (bc->order() == 1 || bc->order() == 3)) {
             _curve = OPAQUE_P_ALLOC(Geom::BezierCurve, cubic_bezier_ops);
-            OPAQUE_P(Geom::BezierCurve, _curve) = curve;
+            OPAQUE_P(Geom::BezierCurve, _curve) = bc;
             _node = caml_alloc(2, 0);
             Store_field(_node, 0, _curve);
             Store_field(_node, 1, _list);
             _list = _node;
+        } else {
+            Geom::Path p = cubicbezierpath_from_sbasis(curve->toSBasis(), Double_val(_tol));
+            Geom::Path::const_iterator j = p.end_default();
+            while (j != p.begin()) {
+                j--;
+                bc = dynamic_cast<Geom::BezierCurve*>(j->duplicate());
+                _curve = OPAQUE_P_ALLOC(Geom::BezierCurve, cubic_bezier_ops);
+                OPAQUE_P(Geom::BezierCurve, _curve) = bc;
+                _node = caml_alloc(2, 0);
+                Store_field(_node, 0, _curve);
+                Store_field(_node, 1, _list);
+                _list = _node;
+            }
         }
     }
     CAMLreturn(_list);
 let beziers = Path.to_cubic_beziers path5 0.001 ;;
 List.iter
   (fun bez ->
-    let tuples = Cubic_bezier.to_tuple_array bez in
+    let tuples = Bezier_curve.to_tuple_array bez in
     print_string "[|";
     Array.iter (fun (x,y) -> printf "(%f,%f);" x y) tuples;
     print_endline "|]")