Commits

Barry Schwartz  committed 807dd0e

More functions.

  • Participants
  • Parent commits 008ba37

Comments (0)

Files changed (3)

File caml2geom.ml

 struct
   type t
   external default : unit -> t = "new_default_rect_wrapper"
+  external min : t -> Point.t = "rect_min_wrapper"
+  external max : t -> Point.t = "rect_max_wrapper"
+  external corner : t -> int -> Point.t = "rect_corner_wrapper"
 end
 
 module Bezier =
   external point_and_derivatives : t -> Coord.t -> int -> Point.t array = "curve_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "curve_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "curve_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "curve_bounds_fast_wrapper"
+  external bounds_exact : t -> Rect.t = "curve_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "curve_portion_wrapper"
   external reverse : t -> t = "curve_reverse_wrapper"
   external derivative : t -> t = "curve_derivative_wrapper"
   external point_and_derivatives : t -> Coord.t -> int -> Point.t array = "bezier_curve_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "bezier_curve_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "bezier_curve_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "bezier_curve_bounds_fast_wrapper"
+  external bounds_exact : t -> Rect.t = "bezier_curve_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "bezier_curve_portion_wrapper"
   external reverse : t -> t = "bezier_curve_reverse_wrapper"
   external derivative : t -> t = "bezier_curve_derivative_wrapper"
   external point_and_derivatives : t -> Coord.t -> int -> Point.t array = "line_segment_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "line_segment_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "line_segment_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "line_segment_bounds_fast_wrapper"
+  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 point_and_derivatives : t -> Coord.t -> int -> Point.t array = "quadratic_bezier_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "quadratic_bezier_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "quadratic_bezier_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "quadratic_bezier_bounds_fast_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 point_and_derivatives : t -> Coord.t -> int -> Point.t array = "cubic_bezier_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "cubic_bezier_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "cubic_bezier_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "cubic_bezier_bounds_fast_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 empty : t -> bool = "path_empty_wrapper"
   external closed : t -> bool = "path_closed_wrapper"
   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"
 end
 
   external empty : t -> bool = "path_empty_wrapper"
   external closed : t -> bool = "path_closed_wrapper"
   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"
 end

File caml2geom.mli

 sig
   type t
   external default : unit -> t = "new_default_rect_wrapper"
+  external min : t -> Point.t = "rect_min_wrapper"
+  external max : t -> Point.t = "rect_max_wrapper"
+  external corner : t -> int -> Point.t = "rect_corner_wrapper"
 end
 
 module Bezier :
   external point_and_derivatives : t -> Coord.t -> int -> Point.t array = "curve_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "curve_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "curve_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "curve_bounds_fast_wrapper"
+  external bounds_exact : t -> Rect.t = "curve_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "curve_portion_wrapper"
   external reverse : t -> t = "curve_reverse_wrapper"
   external derivative : t -> t = "curve_derivative_wrapper"
   external point_and_derivatives : t -> Coord.t -> int -> Point.t array = "bezier_curve_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "bezier_curve_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "bezier_curve_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "bezier_curve_bounds_fast_wrapper"
+  external bounds_exact : t -> Rect.t = "bezier_curve_bounds_exact_wrapper"
   external portion : t -> Coord.t -> Coord.t -> t = "bezier_curve_portion_wrapper"
   external reverse : t -> t = "bezier_curve_reverse_wrapper"
   external derivative : t -> t = "bezier_curve_derivative_wrapper"
   external point_and_derivatives : t -> Coord.t -> int -> Point.t array = "line_segment_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "line_segment_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "line_segment_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "line_segment_bounds_fast_wrapper"
+  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 point_and_derivatives : t -> Coord.t -> int -> Point.t array = "quadratic_bezier_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "quadratic_bezier_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "quadratic_bezier_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "quadratic_bezier_bounds_fast_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 point_and_derivatives : t -> Coord.t -> int -> Point.t array = "cubic_bezier_point_and_derivatives_wrapper"
   external set_initial : t -> Point.t -> unit = "cubic_bezier_set_initial_wrapper"
   external set_final : t -> Point.t -> unit = "cubic_bezier_set_final_wrapper"
+  external bounds_fast : t -> Rect.t = "cubic_bezier_bounds_fast_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 empty : t -> bool = "path_empty_wrapper"
   external closed : t -> bool = "path_closed_wrapper"
   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"
 end
 

File caml2geom_stubs.c

         CAMLreturn(Val_unit);                                           \
     }                                                                   \
                                                                         \
+    extern "C" CAMLprim value name##_bounds_fast_wrapper(value _curve)  \
+    {                                                                   \
+        CAMLparam1(_curve);                                             \
+        CAMLlocal1(_rect);                                              \
+        t *curve = OPAQUE_P(t, _curve);                                 \
+        Geom::Rect rect = curve->boundsFast();                          \
+        _rect = OPAQUE_P_ALLOC(Geom::Rect, rect_ops);                   \
+        OPAQUE_P(Geom::Rect, _rect) = new Geom::Rect(rect);             \
+        CAMLreturn(_rect);                                              \
+    }                                                                   \
+                                                                        \
+    extern "C" CAMLprim value name##_bounds_exact_wrapper(value _curve) \
+    {                                                                   \
+        CAMLparam1(_curve);                                             \
+        CAMLlocal1(_rect);                                              \
+        t *curve = OPAQUE_P(t, _curve);                                 \
+        Geom::Rect rect = curve->boundsExact();                         \
+        _rect = OPAQUE_P_ALLOC(Geom::Rect, rect_ops);                   \
+        OPAQUE_P(Geom::Rect, _rect) = new Geom::Rect(rect);             \
+        CAMLreturn(_rect);                                              \
+    }                                                                   \
+                                                                        \
     extern "C" CAMLprim value name##_portion_wrapper(value _curve, value _a, value _b) \
     {                                                                   \
         CAMLparam3(_curve, _a, _b);                                     \
     CAMLreturn(_rect);
 }
 
+extern "C" CAMLprim value rect_min_wrapper(value _rect)
+{
+    CAMLparam1(_rect);
+    CAMLlocal1(_point);
+    Geom::Rect *rect = OPAQUE_P(Geom::Rect, _rect);
+    Geom::Point pt = rect->min();
+    _point = OPAQUE_P_ALLOC(Geom::Point, point_ops);
+    OPAQUE_P(Geom::Point, _point) = new Geom::Point(pt);
+    CAMLreturn(_point);
+}
+
+extern "C" CAMLprim value rect_max_wrapper(value _rect)
+{
+    CAMLparam1(_rect);
+    CAMLlocal1(_point);
+    Geom::Rect *rect = OPAQUE_P(Geom::Rect, _rect);
+    Geom::Point pt = rect->max();
+    _point = OPAQUE_P_ALLOC(Geom::Point, point_ops);
+    OPAQUE_P(Geom::Point, _point) = new Geom::Point(pt);
+    CAMLreturn(_point);
+}
+
+extern "C" CAMLprim value rect_corner_wrapper(value _rect, value _i)
+{
+    CAMLparam2(_rect, _i);
+    CAMLlocal1(_point);
+    Geom::Rect *rect = OPAQUE_P(Geom::Rect, _rect);
+    Geom::Point pt = rect->corner(Int_val(_i));
+    _point = OPAQUE_P_ALLOC(Geom::Point, point_ops);
+    OPAQUE_P(Geom::Point, _point) = new Geom::Point(pt);
+    CAMLreturn(_point);
+}
+
 //-------------------------------------------------------------------------
 
 fragment_wrappers(Geom::Bezier, bezier);
 getval_wrapper(Geom::Path, path_closed_wrapper, closed, Val_bool);
 setval_wrapper(Geom::Path, path_close_wrapper, close, Bool_val);
 
+extern "C" CAMLprim value path_bounds_fast_wrapper(value _path)
+{
+    CAMLparam1(_path);
+    CAMLlocal2(_opt_rect, _rect);
+    Geom::Path *path = OPAQUE_P(Geom::Path, _path);
+    Geom::OptRect opt_rect = path->boundsFast();
+    if (opt_rect.isEmpty()) {
+        _opt_rect = Val_int(0);
+    } else {
+        _opt_rect = caml_alloc(1, 0);
+        _rect = OPAQUE_P_ALLOC(Geom::Rect, rect_ops);
+        OPAQUE_P(Geom::Rect, _rect) = new Geom::Rect(opt_rect.get());
+        Store_field(_opt_rect, 0, _rect);
+    }
+    CAMLreturn(_opt_rect);
+}
+
+extern "C" CAMLprim value path_bounds_exact_wrapper(value _path)
+{
+    CAMLparam1(_path);
+    CAMLlocal2(_opt_rect, _rect);
+    Geom::Path *path = OPAQUE_P(Geom::Path, _path);
+    Geom::OptRect opt_rect = path->boundsExact();
+    if (opt_rect.isEmpty()) {
+        _opt_rect = Val_int(0);
+    } else {
+        _opt_rect = caml_alloc(1, 0);
+        _rect = OPAQUE_P_ALLOC(Geom::Rect, rect_ops);
+        OPAQUE_P(Geom::Rect, _rect) = new Geom::Rect(*(Geom::Rect*)&opt_rect);
+        Store_field(_opt_rect, 0, _rect);
+    }
+    CAMLreturn(_opt_rect);
+}
+
 extern "C" CAMLprim value path_to_cubic_bezier_curves_wrapper(value _path, value _tol)
 {
     CAMLparam2(_path, _tol);