[gtk/curve-ops: 2/5] Add gsk_curve_get_{start,end}_angle
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/curve-ops: 2/5] Add gsk_curve_get_{start,end}_angle
- Date: Mon, 7 Dec 2020 07:33:54 +0000 (UTC)
commit 131a77d11fbea44bb600759d6cced0055fed2f83
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Dec 6 23:13:56 2020 -0500
Add gsk_curve_get_{start,end}_angle
Add a way to get the tangent angles at the start
and end of the curve. This will be used in stroking.
gsk/gskcurve.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++--
gsk/gskcurveprivate.h | 2 ++
2 files changed, 78 insertions(+), 3 deletions(-)
---
diff --git a/gsk/gskcurve.c b/gsk/gskcurve.c
index c0c36c0c7f..f3f81cd236 100644
--- a/gsk/gskcurve.c
+++ b/gsk/gskcurve.c
@@ -46,6 +46,8 @@ struct _GskCurveClass
const graphene_point_t * (* get_end_point) (const GskCurve *curve);
void (* get_bounds) (const GskCurve *curve,
graphene_rect_t *bounds);
+ float (* get_start_angle) (const GskCurve *curve);
+ float (* get_end_angle) (const GskCurve *curve);
};
/** LINE **/
@@ -151,6 +153,21 @@ gsk_line_curve_get_bounds (const GskCurve *curve,
graphene_rect_expand (bounds, &self->points[1], bounds);
}
+static inline float
+get_angle (const graphene_point_t *a,
+ const graphene_point_t *b)
+{
+ return atan2 (b->y - a->y, b->x - a->x);
+}
+
+static float
+gsk_line_curve_get_angle (const GskCurve *curve)
+{
+ const GskLineCurve *self = &curve->line;
+
+ return get_angle (&self->points[0], &self->points[1]);
+}
+
static const GskCurveClass GSK_LINE_CURVE_CLASS = {
gsk_line_curve_init,
gsk_line_curve_eval,
@@ -159,7 +176,9 @@ 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_bounds
+ gsk_line_curve_get_bounds,
+ gsk_line_curve_get_angle,
+ gsk_line_curve_get_angle
};
/** CURVE **/
@@ -398,6 +417,22 @@ gsk_curve_curve_get_bounds (const GskCurve *curve,
}
}
+static float
+gsk_curve_curve_get_start_angle (const GskCurve *curve)
+{
+ const GskCurveCurve *self = &curve->curve;
+
+ return get_angle (&self->points[0], &self->points[1]);
+}
+
+static float
+gsk_curve_curve_get_end_angle (const GskCurve *curve)
+{
+ const GskCurveCurve *self = &curve->curve;
+
+ return get_angle (&self->points[2], &self->points[3]);
+}
+
static const GskCurveClass GSK_CURVE_CURVE_CLASS = {
gsk_curve_curve_init,
gsk_curve_curve_eval,
@@ -406,7 +441,9 @@ 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_bounds
+ gsk_curve_curve_get_bounds,
+ gsk_curve_curve_get_start_angle,
+ gsk_curve_curve_get_end_angle
};
/** CONIC **/
@@ -776,6 +813,22 @@ gsk_conic_curve_get_bounds (const GskCurve *curve,
}
}
+static float
+gsk_conic_curve_get_start_angle (const GskCurve *curve)
+{
+ const GskCurveCurve *self = &curve->curve;
+
+ return get_angle (&self->points[0], &self->points[1]);
+}
+
+static float
+gsk_conic_curve_get_end_angle (const GskCurve *curve)
+{
+ const GskCurveCurve *self = &curve->curve;
+
+ return get_angle (&self->points[1], &self->points[3]);
+}
+
static const GskCurveClass GSK_CONIC_CURVE_CLASS = {
gsk_conic_curve_init,
gsk_conic_curve_eval,
@@ -784,7 +837,9 @@ 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_bounds
+ gsk_conic_curve_get_bounds,
+ gsk_conic_curve_get_start_angle,
+ gsk_conic_curve_get_end_angle
};
/** API **/
@@ -863,6 +918,24 @@ gsk_curve_get_bounds (const GskCurve *curve,
get_class (curve->op)->get_bounds (curve, bounds);
}
+/* Returns the angle between the tangent at the start
+ * point and the x axis, in the range [-pi, pi]
+ */
+float
+gsk_curve_get_start_angle (const GskCurve *curve)
+{
+ return get_class (curve->op)->get_start_angle (curve);
+}
+
+/* Returns the angle between the tangent at the end
+ * point and the x axis, in the range [-pi, pi]
+ */
+float
+gsk_curve_get_end_angle (const GskCurve *curve)
+{
+ return get_class (curve->op)->get_end_angle (curve);
+}
+
/** Intersections **/
static int
diff --git a/gsk/gskcurveprivate.h b/gsk/gskcurveprivate.h
index dfdd45b034..5f1a951c11 100644
--- a/gsk/gskcurveprivate.h
+++ b/gsk/gskcurveprivate.h
@@ -108,6 +108,8 @@ int gsk_curve_intersect (const GskCurve
float *t2,
graphene_point_t *p,
int n);
+float gsk_curve_get_start_angle (const GskCurve *curve);
+float gsk_curve_get_end_angle (const GskCurve *curve);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]