[gtk/matthiasc/lottie2: 19/24] path: Implement gsk_circle_contour_get_bounds




commit b96dedd4316f766ca8262a29d9c924c3fb3fce66
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Nov 25 23:00:58 2020 -0500

    path: Implement gsk_circle_contour_get_bounds
    
    Add tight bounding boxes for arcs.

 gsk/gskpath.c | 47 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 41 insertions(+), 6 deletions(-)
---
diff --git a/gsk/gskpath.c b/gsk/gskpath.c
index b20ad2528c..c5bd85d8bb 100644
--- a/gsk/gskpath.c
+++ b/gsk/gskpath.c
@@ -531,12 +531,47 @@ gsk_circle_contour_get_bounds (const GskContour *contour,
 {
   const GskCircleContour *self = (const GskCircleContour *) contour;
 
-  /* XXX: handle partial circles */
-  graphene_rect_init (rect,
-                      self->center.x - self->radius,
-                      self->center.y - self->radius,
-                      2 * self->radius,
-                      2 * self->radius);
+  if (fabs (self->start_angle - self->end_angle) >= 360)
+    graphene_rect_init (rect,
+                        self->center.x - self->radius,
+                        self->center.y - self->radius,
+                        2 * self->radius,
+                        2 * self->radius);
+  else
+    {
+      graphene_point_t p;
+
+      p = GRAPHENE_POINT_INIT (self->center.x + cos (DEG_TO_RAD (self->start_angle)) * self->radius,
+                               self->center.y + sin (DEG_TO_RAD (self->start_angle)) * self->radius);
+
+      graphene_rect_init (rect, p.x, p.y, 0, 0);
+
+      p = GRAPHENE_POINT_INIT (self->center.x + cos (DEG_TO_RAD (self->end_angle)) * self->radius,
+                               self->center.y + sin (DEG_TO_RAD (self->end_angle)) * self->radius);
+
+      graphene_rect_expand (rect, &p, rect);
+
+      if (self->start_angle <= 0 && self->end_angle >= 0)
+        {
+          p = GRAPHENE_POINT_INIT (self->center.x + self->radius, self->center.y);
+          graphene_rect_expand (rect, &p, rect);
+        }
+      if (self->start_angle <= 90 && self->end_angle >= 90)
+        {
+          p = GRAPHENE_POINT_INIT (self->center.x, self->center.y + self->radius);
+          graphene_rect_expand (rect, &p, rect);
+        }
+      if (self->start_angle <= 180 && self->end_angle >= 180)
+        {
+          p = GRAPHENE_POINT_INIT (self->center.x - self->radius, self->center.y);
+          graphene_rect_expand (rect, &p, rect);
+        }
+      if (self->start_angle <= 270 && self->end_angle >= 270)
+        {
+          p = GRAPHENE_POINT_INIT (self->center.x, self->center.y - self->radius);
+          graphene_rect_expand (rect, &p, rect);
+        }
+    }
 
   return TRUE;
 }


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