[gtk/curve-ops: 4/5] Add gsk_curve_get_hull




commit 46900fd9883c8aae4c88c35d1ac1d109d30340b8
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 7 01:22:39 2020 -0500

    Add gsk_curve_get_hull
    
    A cheaper bounding box.

 gsk/gskcurve.c        | 37 +++++++++++++++++++++++++++++++++++++
 gsk/gskcurveprivate.h |  2 ++
 2 files changed, 39 insertions(+)
---
diff --git a/gsk/gskcurve.c b/gsk/gskcurve.c
index f3f81cd236..31b5f6da63 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);
+  void                          (* get_hull)            (const GskCurve         *curve,
+                                                         graphene_rect_t        *bounds);
   float                         (* get_start_angle)     (const GskCurve         *curve);
   float                         (* get_end_angle)       (const GskCurve         *curve);
 };
@@ -177,6 +179,7 @@ static const GskCurveClass GSK_LINE_CURVE_CLASS = {
   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
 };
@@ -392,6 +395,19 @@ get_cubic_extrema (float pa, float pb, float pc, float pd, float t[2])
   return n;
 }
 
+static void
+gsk_curve_curve_get_hull (const GskCurve  *curve,
+                          graphene_rect_t *bounds)
+{
+  const GskCurveCurve *self = &curve->curve;
+  const graphene_point_t *pts = self->points;
+
+  graphene_rect_init (bounds, pts[0].x, pts[0].y, 0, 0);
+  graphene_rect_expand (bounds, &pts[1], bounds);
+  graphene_rect_expand (bounds, &pts[2], bounds);
+  graphene_rect_expand (bounds, &pts[3], bounds);
+}
+
 static void
 gsk_curve_curve_get_bounds (const GskCurve  *curve,
                             graphene_rect_t *bounds)
@@ -442,6 +458,7 @@ static const GskCurveClass GSK_CURVE_CURVE_CLASS = {
   gsk_curve_curve_get_start_point,
   gsk_curve_curve_get_end_point,
   gsk_curve_curve_get_bounds,
+  gsk_curve_curve_get_hull,
   gsk_curve_curve_get_start_angle,
   gsk_curve_curve_get_end_angle
 };
@@ -787,6 +804,18 @@ get_conic_extrema (float a, float b, float c, float w, float t[4])
   return n;
 }
 
+static void
+gsk_conic_curve_get_hull (const GskCurve  *curve,
+                          graphene_rect_t *bounds)
+{
+  const GskCurveCurve *self = &curve->curve;
+  const graphene_point_t *pts = self->points;
+
+  graphene_rect_init (bounds, pts[0].x, pts[0].y, 0, 0);
+  graphene_rect_expand (bounds, &pts[1], bounds);
+  graphene_rect_expand (bounds, &pts[3], bounds);
+}
+
 static void
 gsk_conic_curve_get_bounds (const GskCurve  *curve,
                             graphene_rect_t *bounds)
@@ -838,6 +867,7 @@ static const GskCurveClass GSK_CONIC_CURVE_CLASS = {
   gsk_conic_curve_get_start_point,
   gsk_conic_curve_get_end_point,
   gsk_conic_curve_get_bounds,
+  gsk_conic_curve_get_hull,
   gsk_conic_curve_get_start_angle,
   gsk_conic_curve_get_end_angle
 };
@@ -918,6 +948,13 @@ gsk_curve_get_bounds (const GskCurve  *curve,
   get_class (curve->op)->get_bounds (curve, bounds);
 }
 
+void
+gsk_curve_get_hull (const GskCurve  *curve,
+                    graphene_rect_t *bounds)
+{
+  get_class (curve->op)->get_hull (curve, bounds);
+}
+
 /* Returns the angle between the tangent at the start
  * point and the x axis, in the range [-pi, pi]
  */
diff --git a/gsk/gskcurveprivate.h b/gsk/gskcurveprivate.h
index 5f1a951c11..ef01f3341e 100644
--- a/gsk/gskcurveprivate.h
+++ b/gsk/gskcurveprivate.h
@@ -101,6 +101,8 @@ const graphene_point_t *gsk_curve_get_end_point                 (const GskCurve
 
 void                    gsk_curve_get_bounds                    (const GskCurve         *curve,
                                                                  graphene_rect_t        *bounds);
+void                    gsk_curve_get_hull                      (const GskCurve         *curve,
+                                                                 graphene_rect_t        *bounds);
 
 int                     gsk_curve_intersect                     (const GskCurve         *curve1,
                                                                  const GskCurve         *curve2,


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