[gtk/wip/otte/lottie: 59/86] Add gsk_curve_get_{start,end}_tangent




commit cf881975f796454bd4b0505345d85d6cd75f5a53
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Dec 6 23:13:56 2020 -0500

    Add gsk_curve_get_{start,end}_tangent
    
    Add a way to get the tangents at the start and end of the curve.
    This will be used in stroking.

 gsk/gskcurve.c        | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 gsk/gskcurveprivate.h |  4 +++
 2 files changed, 81 insertions(+)
---
diff --git a/gsk/gskcurve.c b/gsk/gskcurve.c
index 2ecd3be146..c5ec9d4ded 100644
--- a/gsk/gskcurve.c
+++ b/gsk/gskcurve.c
@@ -44,8 +44,21 @@ struct _GskCurveClass
   gskpathop                     (* pathop)              (const GskCurve         *curve);
   const graphene_point_t *      (* get_start_point)     (const GskCurve         *curve);
   const graphene_point_t *      (* get_end_point)       (const GskCurve         *curve);
+  void                          (* get_start_tangent)   (const GskCurve         *curve,
+                                                         graphene_vec2_t        *tangent);
+  void                          (* get_end_tangent)     (const GskCurve         *curve,
+                                                         graphene_vec2_t        *tangent);
 };
 
+static void
+get_tangent (const graphene_point_t *p0,
+             const graphene_point_t *p1,
+             graphene_vec2_t        *t)
+{
+  graphene_vec2_init (t, p1->x - p0->x, p1->y - p0->y);
+  graphene_vec2_normalize (t, t);
+}
+
 /** LINE **/
 
 static void
@@ -139,6 +152,15 @@ gsk_line_curve_get_end_point (const GskCurve *curve)
   return &self->points[1];
 }
 
+static void
+gsk_line_curve_get_tangent (const GskCurve  *curve,
+                            graphene_vec2_t *tangent)
+{
+  const GskLineCurve *self = &curve->line;
+
+  get_tangent (&self->points[0], &self->points[1], tangent);
+}
+
 static const GskCurveClass GSK_LINE_CURVE_CLASS = {
   gsk_line_curve_init,
   gsk_line_curve_eval,
@@ -147,6 +169,8 @@ static const GskCurveClass GSK_LINE_CURVE_CLASS = {
   gsk_line_curve_pathop,
   gsk_line_curve_get_start_point,
   gsk_line_curve_get_end_point,
+  gsk_line_curve_get_tangent,
+  gsk_line_curve_get_tangent
 };
 
 /** CURVE **/
@@ -311,6 +335,24 @@ gsk_curve_curve_get_end_point (const GskCurve *curve)
   return &self->points[3];
 }
 
+static void
+gsk_curve_curve_get_start_tangent (const GskCurve  *curve,
+                                   graphene_vec2_t *tangent)
+{
+  const GskCurveCurve *self = &curve->curve;
+
+  get_tangent (&self->points[0], &self->points[1], tangent);
+}
+
+static void
+gsk_curve_curve_get_end_tangent (const GskCurve  *curve,
+                                 graphene_vec2_t *tangent)
+{
+  const GskCurveCurve *self = &curve->curve;
+
+  get_tangent (&self->points[2], &self->points[3], tangent);
+}
+
 static const GskCurveClass GSK_CURVE_CURVE_CLASS = {
   gsk_curve_curve_init,
   gsk_curve_curve_eval,
@@ -319,6 +361,8 @@ static const GskCurveClass GSK_CURVE_CURVE_CLASS = {
   gsk_curve_curve_pathop,
   gsk_curve_curve_get_start_point,
   gsk_curve_curve_get_end_point,
+  gsk_curve_curve_get_start_tangent,
+  gsk_curve_curve_get_end_tangent
 };
 
 /** CONIC **/
@@ -624,6 +668,24 @@ gsk_conic_curve_get_end_point (const GskCurve *curve)
   return &self->points[3];
 }
 
+static void
+gsk_conic_curve_get_start_tangent (const GskCurve  *curve,
+                                   graphene_vec2_t *tangent)
+{
+  const GskConicCurve *self = &curve->conic;
+
+  get_tangent (&self->points[0], &self->points[1], tangent);
+}
+
+static void
+gsk_conic_curve_get_end_tangent (const GskCurve  *curve,
+                                 graphene_vec2_t *tangent)
+{
+  const GskConicCurve *self = &curve->conic;
+
+  get_tangent (&self->points[1], &self->points[3], tangent);
+}
+
 static const GskCurveClass GSK_CONIC_CURVE_CLASS = {
   gsk_conic_curve_init,
   gsk_conic_curve_eval,
@@ -632,6 +694,8 @@ static const GskCurveClass GSK_CONIC_CURVE_CLASS = {
   gsk_conic_curve_pathop,
   gsk_conic_curve_get_start_point,
   gsk_conic_curve_get_end_point,
+  gsk_conic_curve_get_start_tangent,
+  gsk_conic_curve_get_end_tangent
 };
 
 /** API **/
@@ -703,3 +767,16 @@ gsk_curve_get_end_point (const GskCurve *curve)
   return get_class (curve->op)->get_end_point (curve);
 }
 
+void
+gsk_curve_get_start_tangent (const GskCurve  *curve,
+                             graphene_vec2_t *tangent)
+{
+  get_class (curve->op)->get_start_tangent (curve, tangent);
+}
+
+void
+gsk_curve_get_end_tangent (const GskCurve  *curve,
+                           graphene_vec2_t *tangent)
+{
+  get_class (curve->op)->get_end_tangent (curve, tangent);
+}
diff --git a/gsk/gskcurveprivate.h b/gsk/gskcurveprivate.h
index 720ee71f1c..0f4e89d2c5 100644
--- a/gsk/gskcurveprivate.h
+++ b/gsk/gskcurveprivate.h
@@ -98,6 +98,10 @@ gskpathop               gsk_curve_pathop                        (const GskCurve
 #define gsk_curve_builder_to(curve, builder) gsk_path_builder_pathop_to ((builder), gsk_curve_pathop (curve))
 const graphene_point_t *gsk_curve_get_start_point               (const GskCurve         *curve);
 const graphene_point_t *gsk_curve_get_end_point                 (const GskCurve         *curve);
+void                    gsk_curve_get_start_tangent             (const GskCurve         *curve,
+                                                                 graphene_vec2_t        *tangent);
+void                    gsk_curve_get_end_tangent               (const GskCurve         *curve,
+                                                                 graphene_vec2_t        *tangent);
 
 
 


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