[gimp] app: add gimp_coords_interpolate_bezier_at()



commit ea34bbc92b50e8646c8034412e0dfedd31a74e04
Author: Ell <ell_se yahoo com>
Date:   Thu Feb 1 11:23:51 2018 -0500

    app: add gimp_coords_interpolate_bezier_at()
    
    ... which calculates the position and/or velocity of a Bezier curve
    at a given point.

 app/core/gimpcoords-interpolate.c |   45 +++++++++++++++++++++++++++++++++++++
 app/core/gimpcoords-interpolate.h |   25 ++++++++++++--------
 2 files changed, 60 insertions(+), 10 deletions(-)
---
diff --git a/app/core/gimpcoords-interpolate.c b/app/core/gimpcoords-interpolate.c
index d362b52..cd0af58 100644
--- a/app/core/gimpcoords-interpolate.c
+++ b/app/core/gimpcoords-interpolate.c
@@ -155,6 +155,51 @@ gimp_coords_interpolate_bezier_internal (const GimpCoords  bezier_pt[4],
 
 
 /*
+ * Returns the position and/or velocity of a Bezier curve at time 't'.
+ */
+
+void
+gimp_coords_interpolate_bezier_at (const GimpCoords  bezier_pt[4],
+                                   gdouble           t,
+                                   GimpCoords       *position,
+                                   GimpCoords       *velocity)
+{
+  gdouble u = 1.0 - t;
+
+  g_return_if_fail (bezier_pt != NULL);
+
+  if (position)
+    {
+      GimpCoords a;
+      GimpCoords b;
+
+      gimp_coords_mix (      u * u * u, &bezier_pt[0],
+                       3.0 * u * u * t, &bezier_pt[1],
+                                        &a);
+      gimp_coords_mix (3.0 * u * t * t, &bezier_pt[2],
+                             t * t * t, &bezier_pt[3],
+                                        &b);
+
+      gimp_coords_add (&a, &b, position);
+    }
+
+  if (velocity)
+    {
+      GimpCoords a;
+      GimpCoords b;
+
+      gimp_coords_mix (-3.0 * u * u,             &bezier_pt[0],
+                        3.0 * (u - 2.0 * t) * u, &bezier_pt[1],
+                                                 &a);
+      gimp_coords_mix (-3.0 * (t - 2.0 * u) * t, &bezier_pt[2],
+                        3.0 * t * t,             &bezier_pt[3],
+                                                 &b);
+
+      gimp_coords_add (&a, &b, velocity);
+    }
+}
+
+/*
  * a helper function that determines if a bezier segment is "straight
  * enough" to be approximated by a line.
  *
diff --git a/app/core/gimpcoords-interpolate.h b/app/core/gimpcoords-interpolate.h
index d77e346..2c58658 100644
--- a/app/core/gimpcoords-interpolate.h
+++ b/app/core/gimpcoords-interpolate.h
@@ -20,17 +20,22 @@
 #ifndef __GIMP_COORDS_INTERPOLATE_H__
 #define __GIMP_COORDS_INTERPOLATE_H__
 
-void       gimp_coords_interpolate_bezier  (const GimpCoords  bezier_pt[4],
-                                            gdouble           precision,
-                                            GArray           *ret_coords,
-                                            GArray           *ret_params);
+void       gimp_coords_interpolate_bezier    (const GimpCoords  bezier_pt[4],
+                                              gdouble           precision,
+                                              GArray           *ret_coords,
+                                              GArray           *ret_params);
 
-gboolean   gimp_coords_bezier_is_straight  (const GimpCoords  bezier_pt[4],
-                                            gdouble           precision);
+void       gimp_coords_interpolate_bezier_at (const GimpCoords  bezier_pt[4],
+                                              gdouble           t,
+                                              GimpCoords       *position,
+                                              GimpCoords       *velocity);
 
-void       gimp_coords_interpolate_catmull (const GimpCoords  catmull_pt[4],
-                                            gdouble           precision,
-                                            GArray           *ret_coords,
-                                            GArray           *ret_params);
+gboolean   gimp_coords_bezier_is_straight    (const GimpCoords  bezier_pt[4],
+                                              gdouble           precision);
+
+void       gimp_coords_interpolate_catmull   (const GimpCoords  catmull_pt[4],
+                                              gdouble           precision,
+                                              GArray           *ret_coords,
+                                              GArray           *ret_params);
 
 #endif /* __GIMP_COORDS_INTERPOLATE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]