[gtk/curve-ops: 3/10] Add gsk_curve_get_{start,end}_tangent
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/curve-ops: 3/10] Add gsk_curve_get_{start,end}_tangent
- Date: Mon, 7 Dec 2020 23:46:26 +0000 (UTC)
commit 843b38019e801690339f3b7084885fa6ea9a3682
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 fa1f1295ba..ceaeafc1ae 100644
--- a/gsk/gskcurve.c
+++ b/gsk/gskcurve.c
@@ -44,6 +44,10 @@ 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);
};
/** LINE **/
@@ -139,6 +143,24 @@ gsk_line_curve_get_end_point (const GskCurve *curve)
return &self->points[1];
}
+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);
+}
+
+static void
+gsk_line_curve_get_tangent (const GskCurve *curve,
+ graphene_vec2_t *tangent)
+{
+ const GskLineCurve *self = &curve->line;
+
+ return 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;
+
+ return 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;
+
+ return 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 **/
@@ -532,6 +576,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 GskCurveCurve *self = &curve->curve;
+
+ return 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 GskCurveCurve *self = &curve->curve;
+
+ return get_tangent (&self->points[1], &self->points[3], tangent);
+}
+
static const GskCurveClass GSK_CONIC_CURVE_CLASS = {
gsk_conic_curve_init,
gsk_conic_curve_eval,
@@ -540,6 +602,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 **/
@@ -611,3 +675,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]