[librsvg: 3/12] Polygon / Polyline: extract a make_path_builder function



commit 6d168b414874fa631a05815bccbe43df0367a95c
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Dec 10 10:08:04 2019 -0600

    Polygon / Polyline: extract a make_path_builder function

 rsvg_internals/src/shapes.rs | 61 ++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 31 deletions(-)
---
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index e5fc1f20..77090639 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -180,19 +180,10 @@ impl Parse for Points {
     }
 }
 
-fn render_poly(
-    points: Option<&Points>,
-    closed: bool,
-    node: &RsvgNode,
-    cascaded: &CascadedValues<'_>,
-    draw_ctx: &mut DrawingCtx,
-    clipping: bool,
-) -> Result<BoundingBox, RenderingError> {
-    let values = cascaded.get();
+fn make_poly(points: Option<&Points>, closed: bool) -> PathBuilder {
+    let mut builder = PathBuilder::new();
 
     if let Some(points) = points {
-        let mut builder = PathBuilder::new();
-
         for (i, &(x, y)) in points.iter().enumerate() {
             if i == 0 {
                 builder.move_to(x, y);
@@ -204,11 +195,9 @@ fn render_poly(
         if closed {
             builder.close_path();
         }
-
-        render_path_builder(&builder, draw_ctx, node, values, true, clipping)
-    } else {
-        Ok(draw_ctx.empty_bbox())
     }
+
+    builder
 }
 
 #[derive(Default)]
@@ -234,14 +223,19 @@ impl NodeTrait for Polygon {
         draw_ctx: &mut DrawingCtx,
         clipping: bool,
     ) -> Result<BoundingBox, RenderingError> {
-        render_poly(
-            self.points.as_ref(),
-            true,
-            node,
-            cascaded,
-            draw_ctx,
-            clipping,
-        )
+        let values = cascaded.get();
+        let builder = self.make_path_builder(values, draw_ctx);
+        render_path_builder(&builder, draw_ctx, node, values, true, clipping)
+    }
+}
+
+impl Polygon {
+    fn make_path_builder(
+        &self,
+        _values: &ComputedValues,
+        _draw_ctx: &mut DrawingCtx,
+    ) -> PathBuilder {
+        make_poly(self.points.as_ref(), true)
     }
 }
 
@@ -268,14 +262,19 @@ impl NodeTrait for Polyline {
         draw_ctx: &mut DrawingCtx,
         clipping: bool,
     ) -> Result<BoundingBox, RenderingError> {
-        render_poly(
-            self.points.as_ref(),
-            false,
-            node,
-            cascaded,
-            draw_ctx,
-            clipping,
-        )
+        let values = cascaded.get();
+        let builder = self.make_path_builder(values, draw_ctx);
+        render_path_builder(&builder, draw_ctx, node, values, true, clipping)
+    }
+}
+
+impl Polyline {
+    fn make_path_builder(
+        &self,
+        _values: &ComputedValues,
+        _draw_ctx: &mut DrawingCtx,
+    ) -> PathBuilder {
+        make_poly(self.points.as_ref(), false)
     }
 }
 


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