Commits

Barry Schwartz  committed 508331c

nearest_point for curves.

  • Participants
  • Parent commits a0adb7a

Comments (0)

Files changed (3)

File caml2geom.ml

   external reverse : t -> t = "curve_reverse_wrapper"
   external derivative : t -> t = "curve_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "curve_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "curve_nearest_point_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "curve_roots_wrapper"
   external winding : t -> Point.t -> int = "curve_winding_wrapper"
   external unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t = "curve_unit_tangent_at_wrapper"
   external reverse : t -> t = "bezier_curve_reverse_wrapper"
   external derivative : t -> t = "bezier_curve_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "bezier_curve_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "bezier_curve_nearest_point_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "bezier_curve_roots_wrapper"
   external winding : t -> Point.t -> int = "bezier_curve_winding_wrapper"
   external unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t = "bezier_curve_unit_tangent_at_wrapper"
   external reverse : t -> t = "line_segment_reverse_wrapper"
   external derivative : t -> Bezier_curve.t = "line_segment_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "line_segment_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "line_segment_nearest_point_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 unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t = "line_segment_unit_tangent_at_wrapper"
   external reverse : t -> t = "quadratic_bezier_reverse_wrapper"
   external derivative : t -> Bezier_curve.t = "quadratic_bezier_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "quadratic_bezier_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "quadratic_bezier_nearest_point_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 unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t = "quadratic_bezier_unit_tangent_at_wrapper"
   external reverse : t -> t = "cubic_bezier_reverse_wrapper"
   external derivative : t -> Bezier_curve.t = "cubic_bezier_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "cubic_bezier_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "cubic_bezier_nearest_point_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"
   external unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t = "cubic_bezier_unit_tangent_at_wrapper"

File caml2geom.mli

   external reverse : t -> t = "curve_reverse_wrapper"
   external derivative : t -> t = "curve_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "curve_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "curve_nearest_point_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "curve_roots_wrapper"
   external winding : t -> Point.t -> int = "curve_winding_wrapper"
   external unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t = "curve_unit_tangent_at_wrapper"
   external reverse : t -> t = "bezier_curve_reverse_wrapper"
   external derivative : t -> t = "bezier_curve_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "bezier_curve_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "bezier_curve_nearest_point_wrapper"
   external roots : t -> Coord.t -> Coord.dim2 -> Coord.t array = "bezier_curve_roots_wrapper"
   external winding : t -> Point.t -> int = "bezier_curve_winding_wrapper"
   external unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t = "bezier_curve_unit_tangent_at_wrapper"
   external reverse : t -> t = "line_segment_reverse_wrapper"
   external derivative : t -> Bezier_curve.t = "line_segment_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "line_segment_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "line_segment_nearest_point_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"
   val unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t
   external reverse : t -> t = "quadratic_bezier_reverse_wrapper"
   external derivative : t -> Bezier_curve.t = "quadratic_bezier_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "quadratic_bezier_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t  = "quadratic_bezier_nearest_point_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"
   val unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t
   external reverse : t -> t = "cubic_bezier_reverse_wrapper"
   external derivative : t -> Bezier_curve.t = "cubic_bezier_derivative_wrapper"
   external length : t -> Coord.t -> Coord.t = "cubic_bezier_length_wrapper"
+  external nearest_point : t -> ?t1:Coord.t -> ?t2:Coord.t -> Point.t -> Coord.t = "cubic_bezier_nearest_point_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"
   val unit_tangent_at : ?num_derivs:int -> t -> Coord.t -> Point.t

File caml2geom_stubs.c

         CAMLreturn(_reverse);                                           \
     }                                                                   \
                                                                         \
+    extern "C" CAMLprim value name##_nearest_point_wrapper(value _curve, value _t1, value _t2, value _point) \
+    {                                                                   \
+        CAMLparam4(_curve, _t1, _t2, _point);                           \
+        t *curve = OPAQUE_P(t, _curve);                                 \
+        Geom::Point *point = OPAQUE_P(Geom::Point, _point);             \
+        Geom::Coord t1 = (_t1 == Val_int(0)) ? 0. : Double_val(Field(_t1, 0)); \
+        Geom::Coord t2 = (_t2 == Val_int(0)) ? 1. : Double_val(Field(_t2, 0)); \
+        Geom::Coord np = curve->nearestPoint(*point, t1, t2);           \
+        CAMLreturn(caml_copy_double(np));                               \
+    }                                                                   \
+                                                                        \
     extern "C" CAMLprim value name##_length_wrapper(value _curve, value _tolerance) \
     {                                                                   \
         CAMLparam2(_curve, _tolerance);                                 \
     CAMLreturn(Val_unit);
 }
 
+#include <stdio.h>
 extern "C" CAMLprim value path_nearest_point_wrapper(value _from_t, value _to_t, value _path, value _point)
 {
     CAMLparam4(_from_t, _to_t, _path, _point);
     double to_t = _to_t == Val_int(0) ? path->size_default() : Double_val(Field(_to_t, 0));
     double time;
     double distance_squared;
+//////////////////        std::vector<double> foo = path->nearestPointPerCurve(*point);
+//////////////////        //    std::vector<double> foo = path->allNearestPoints(*point);
+//////////////////        for (int k=0;k<foo.size();k++)fprintf(stderr, "~~~~ %d: %lf\n", k, foo[k]);
+//////////////////    fprintf(stderr,"++++++++++++++++++++++++++++++++++++++++++++++++++\n");
     try {
         time = path->nearestPoint(*point, from_t, to_t, &distance_squared);
     }