Commits

Barry Schwartz  committed a0adb7a

Better return types for curve derivatives.

  • Participants
  • Parent commits ce5b7dd

Comments (0)

Files changed (3)

File caml2geom.ml

   external bounds_exact : t -> Rect.t = "line_segment_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "line_segment_portion_wrapper"
   external reverse : t -> t = "line_segment_reverse_wrapper"
-  external derivative : t -> t = "line_segment_derivative_wrapper"
+  external derivative : t -> Bezier_curve.t = "line_segment_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "line_segment_length_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "line_segment_roots_wrapper"
   external winding : t -> Point.t -> int = "line_segment_winding_wrapper"
   external bounds_exact : t -> Rect.t = "quadratic_bezier_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "quadratic_bezier_portion_wrapper"
   external reverse : t -> t = "quadratic_bezier_reverse_wrapper"
-  external derivative : t -> t = "quadratic_bezier_derivative_wrapper"
+  external derivative : t -> Bezier_curve.t = "quadratic_bezier_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "quadratic_bezier_length_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "quadratic_bezier_roots_wrapper"
   external winding : t -> Point.t -> int = "quadratic_bezier_winding_wrapper"
   external bounds_exact : t -> Rect.t = "cubic_bezier_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "cubic_bezier_portion_wrapper"
   external reverse : t -> t = "cubic_bezier_reverse_wrapper"
-  external derivative : t -> t = "cubic_bezier_derivative_wrapper"
+  external derivative : t -> Bezier_curve.t = "cubic_bezier_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "cubic_bezier_length_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "cubic_bezier_roots_wrapper"
   external winding : t -> Point.t -> int = "cubic_bezier_winding_wrapper"

File caml2geom.mli

   external bounds_exact : t -> Rect.t = "line_segment_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "line_segment_portion_wrapper"
   external reverse : t -> t = "line_segment_reverse_wrapper"
-  external derivative : t -> t = "line_segment_derivative_wrapper"
+  external derivative : t -> Bezier_curve.t = "line_segment_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "line_segment_length_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "line_segment_roots_wrapper"
   external winding : t -> Point.t -> int = "line_segment_winding_wrapper"
   external bounds_exact : t -> Rect.t = "quadratic_bezier_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "quadratic_bezier_portion_wrapper"
   external reverse : t -> t = "quadratic_bezier_reverse_wrapper"
-  external derivative : t -> t = "quadratic_bezier_derivative_wrapper"
+  external derivative : t -> Bezier_curve.t = "quadratic_bezier_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "quadratic_bezier_length_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "quadratic_bezier_roots_wrapper"
   external winding : t -> Point.t -> int = "quadratic_bezier_winding_wrapper"
   external bounds_exact : t -> Rect.t = "cubic_bezier_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "cubic_bezier_portion_wrapper"
   external reverse : t -> t = "cubic_bezier_reverse_wrapper"
-  external derivative : t -> t = "cubic_bezier_derivative_wrapper"
+  external derivative : t -> Bezier_curve.t = "cubic_bezier_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "cubic_bezier_length_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "cubic_bezier_roots_wrapper"
   external winding : t -> Point.t -> int = "cubic_bezier_winding_wrapper"

File caml2geom_stubs.c

         CAMLreturn(_reverse);                                           \
     }                                                                   \
                                                                         \
-    extern "C" CAMLprim value name##_derivative_wrapper(value _curve)   \
-    {                                                                   \
-        CAMLparam1(_curve);                                             \
-        CAMLlocal1(_derivative);                                        \
-        t *curve = OPAQUE_P(t, _curve);                                 \
-        _derivative = OPAQUE_P_ALLOC(t, name##_ops);                    \
-        OPAQUE_P(t, _derivative) = (t*)curve->derivative();             \
-        CAMLreturn(_derivative);                                        \
-    }                                                                   \
-                                                                        \
     extern "C" CAMLprim value name##_length_wrapper(value _curve, value _tolerance) \
     {                                                                   \
         CAMLparam2(_curve, _tolerance);                                 \
     curve_wrappers(t, name);                                            \
     getval_wrapper(t, name##_order_wrapper, order, Val_int);            \
                                                                         \
+    extern "C" CAMLprim value name##_derivative_wrapper(value _curve)   \
+    {                                                                   \
+        CAMLparam1(_curve);                                             \
+        CAMLlocal1(_derivative);                                        \
+        t *curve = OPAQUE_P(t, _curve);                                 \
+        _derivative = OPAQUE_P_ALLOC(Geom::BezierCurve, bezier_curve_ops); \
+        OPAQUE_P(Geom::BezierCurve, _derivative) = (Geom::BezierCurve*)curve->derivative(); \
+        CAMLreturn(_derivative);                                        \
+    }                                                                   \
+                                                                        \
     extern "C" CAMLprim value name##_points_wrapper(value _bezcurve)    \
     {                                                                   \
         CAMLparam1(_bezcurve);                                          \
 
 curve_wrappers(Geom::Curve, curve);
 
+extern "C" CAMLprim value curve_derivative_wrapper(value _curve)
+{
+    CAMLparam1(_curve);
+    CAMLlocal1(_derivative);
+    Geom::Curve *curve = OPAQUE_P(Geom::Curve, _curve);
+    _derivative = OPAQUE_P_ALLOC(Geom::Curve, curve_ops);
+    OPAQUE_P(Geom::Curve, _derivative) = curve->derivative();
+    CAMLreturn(_derivative);
+}
+
 //-------------------------------------------------------------------------
 
 bezier_curve_wrappers(Geom::BezierCurve, bezier_curve);