[librsvg: 1/12] Rect: extract a make_path_builder() function



commit b7e65f1913be0a35c2934a39a00cac9789e60cc1
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Dec 10 09:46:01 2019 -0600

    Rect: extract a make_path_builder() function

 rsvg_internals/src/shapes.rs | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index 9352cd61..a5dcf926 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -379,7 +379,17 @@ impl NodeTrait for Rect {
         clipping: bool,
     ) -> Result<BoundingBox, RenderingError> {
         let values = cascaded.get();
+        let builder = self.make_path_builder(values, draw_ctx);
+        render_path_builder(&builder, draw_ctx, node, values, false, clipping)
+    }
+}
 
+impl Rect {
+    fn make_path_builder(
+        &self,
+        values: &ComputedValues,
+        draw_ctx: &mut DrawingCtx,
+    ) -> PathBuilder {
         let params = draw_ctx.get_view_params();
 
         let x = self.x.normalize(values, &params);
@@ -412,14 +422,16 @@ impl NodeTrait for Rect {
             }
         }
 
+        let mut builder = PathBuilder::new();
+
         // Per the spec, w,h must be >= 0
         if w <= 0.0 || h <= 0.0 {
-            return Ok(draw_ctx.empty_bbox());
+            return builder;
         }
 
         // ... and rx,ry must be nonnegative
         if rx < 0.0 || ry < 0.0 {
-            return Ok(draw_ctx.empty_bbox());
+            return builder;
         }
 
         let half_w = w / 2.0;
@@ -439,8 +451,6 @@ impl NodeTrait for Rect {
             rx = 0.0;
         }
 
-        let mut builder = PathBuilder::new();
-
         if rx == 0.0 {
             // Easy case, no rounded corners
             builder.move_to(x, y);
@@ -547,7 +557,7 @@ impl NodeTrait for Rect {
             builder.close_path();
         }
 
-        render_path_builder(&builder, draw_ctx, node, values, false, clipping)
+        builder
     }
 }
 


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