Commits

Barry Schwartz committed 9003133

Bezier curve subdivision.

  • Participants
  • Parent commits 8341161

Comments (0)

Files changed (3)

File caml2geom.ml

   external of_three_points : Point.t -> Point.t -> Point.t -> t = "bezier_curve_of_three_points_wrapper"
   external of_four_points : Point.t -> Point.t -> Point.t -> Point.t -> t = "bezier_curve_of_four_points_wrapper"
   external order : t -> int = "bezier_curve_order_wrapper"
+  external subdivide : t -> float -> t * t = "bezier_curve_subdivide_wrapper"
   external initial_point : t -> Point.t = "bezier_curve_initial_point_wrapper"
   external final_point : t -> Point.t = "bezier_curve_final_point_wrapper"
   external is_degenerate : t -> bool = "bezier_curve_is_degenerate_wrapper"
   external to_bezier_curve : t -> Bezier_curve.t = "%identity"
   external of_two_points : Point.t -> Point.t -> t = "line_segment_of_two_points_wrapper"
   external order : t -> int = "line_segment_order_wrapper"
+  external subdivide : t -> float -> Bezier_curve.t * Bezier_curve.t = "line_segment_subdivide_wrapper"
   external initial_point : t -> Point.t = "line_segment_initial_point_wrapper"
   external final_point : t -> Point.t = "line_segment_final_point_wrapper"
   external is_degenerate : t -> bool = "line_segment_is_degenerate_wrapper"
   external to_bezier_curve : t -> Bezier_curve.t = "%identity"
   external of_three_points : Point.t -> Point.t -> Point.t -> t = "quadratic_bezier_of_three_points_wrapper"
   external order : t -> int = "quadratic_bezier_order_wrapper"
+  external subdivide : t -> float -> Bezier_curve.t * Bezier_curve.t = "quadratic_bezier_subdivide_wrapper"
   external initial_point : t -> Point.t = "quadratic_bezier_initial_point_wrapper"
   external final_point : t -> Point.t = "quadratic_bezier_final_point_wrapper"
   external is_degenerate : t -> bool = "quadratic_bezier_is_degenerate_wrapper"
   external to_bezier_curve : t -> Bezier_curve.t = "%identity"
   external of_four_points : Point.t -> Point.t -> Point.t -> Point.t -> t = "cubic_bezier_of_four_points_wrapper"
   external order : t -> int = "cubic_bezier_order_wrapper"
+  external subdivide : t -> float -> Bezier_curve.t * Bezier_curve.t = "cubic_bezier_subdivide_wrapper"
   external initial_point : t -> Point.t = "cubic_bezier_initial_point_wrapper"
   external final_point : t -> Point.t = "cubic_bezier_final_point_wrapper"
   external is_degenerate : t -> bool = "cubic_bezier_is_degenerate_wrapper"

File caml2geom.mli

   external of_three_points : Point.t -> Point.t -> Point.t -> t = "bezier_curve_of_three_points_wrapper"
   external of_four_points : Point.t -> Point.t -> Point.t -> Point.t -> t = "bezier_curve_of_four_points_wrapper"
   external order : t -> int = "bezier_curve_order_wrapper"
+  external subdivide : t -> float -> t * t = "bezier_curve_subdivide_wrapper"
   external initial_point : t -> Point.t = "bezier_curve_initial_point_wrapper"
   external final_point : t -> Point.t = "bezier_curve_final_point_wrapper"
   external is_degenerate : t -> bool = "bezier_curve_is_degenerate_wrapper"
   external to_bezier_curve : t -> Bezier_curve.t = "%identity"
   external of_two_points : Point.t -> Point.t -> t = "line_segment_of_two_points_wrapper"
   external order : t -> int = "line_segment_order_wrapper"
+  external subdivide : t -> float -> Bezier_curve.t * Bezier_curve.t = "line_segment_subdivide_wrapper"
   external initial_point : t -> Point.t = "line_segment_initial_point_wrapper"
   external final_point : t -> Point.t = "line_segment_final_point_wrapper"
   external is_degenerate : t -> bool = "line_segment_is_degenerate_wrapper"
   external to_bezier_curve : t -> Bezier_curve.t = "%identity"
   external of_three_points : Point.t -> Point.t -> Point.t -> t = "quadratic_bezier_of_three_points_wrapper"
   external order : t -> int = "quadratic_bezier_order_wrapper"
+  external subdivide : t -> float -> Bezier_curve.t * Bezier_curve.t = "quadratic_bezier_subdivide_wrapper"
   external initial_point : t -> Point.t = "quadratic_bezier_initial_point_wrapper"
   external final_point : t -> Point.t = "quadratic_bezier_final_point_wrapper"
   external is_degenerate : t -> bool = "quadratic_bezier_is_degenerate_wrapper"
   external to_bezier_curve : t -> Bezier_curve.t = "%identity"
   external of_four_points : Point.t -> Point.t -> Point.t -> Point.t -> t = "cubic_bezier_of_four_points_wrapper"
   external order : t -> int = "cubic_bezier_order_wrapper"
+  external subdivide : t -> float -> Bezier_curve.t * Bezier_curve.t = "cubic_bezier_subdivide_wrapper"
   external initial_point : t -> Point.t = "cubic_bezier_initial_point_wrapper"
   external final_point : t -> Point.t = "cubic_bezier_final_point_wrapper"
   external is_degenerate : t -> bool = "cubic_bezier_is_degenerate_wrapper"

File caml2geom_stubs.c

             Store_field(_result, i, _point);                            \
         }                                                               \
         CAMLreturn(_result);                                            \
+    }                                                                   \
+                                                                        \
+    extern "C" CAMLprim value name##_subdivide_wrapper(value _bezcurve, value _t) \
+    {                                                                   \
+        CAMLparam2(_bezcurve, _t);                                      \
+        CAMLlocal3(_bc1, _bc2, _pair);                                  \
+        t *bc = OPAQUE_P(t, _bezcurve);                                 \
+        std::pair<Geom::BezierCurve,Geom::BezierCurve> bez_pair =       \
+            bc->subdivide(Double_val(_t));                              \
+        Geom::BezierCurve *bc1 = new Geom::BezierCurve(bez_pair.first); \
+        _bc1 = OPAQUE_P_ALLOC(Geom::BezierCurve, bezier_curve_ops);     \
+        OPAQUE_P(Geom::BezierCurve, _bc1) = bc1;                        \
+        Geom::BezierCurve *bc2 = new Geom::BezierCurve(bez_pair.second); \
+        _bc2 = OPAQUE_P_ALLOC(Geom::BezierCurve, bezier_curve_ops);     \
+        OPAQUE_P(Geom::BezierCurve, _bc2) = bc2;                        \
+        _pair = caml_alloc(2, 0);                                       \
+        Store_field(_pair, 0, _bc1);                                    \
+        Store_field(_pair, 1, _bc2);                                    \
+        CAMLreturn(_pair);                                              \
     }
+    
 
 //-------------------------------------------------------------------------