[librsvg: 2/12] Circle, Ellipse: extract a make_path_builder function
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/12] Circle, Ellipse: extract a make_path_builder function
- Date: Tue, 10 Dec 2019 19:44:42 +0000 (UTC)
commit 72911e2a8865802e13271fba6a7f72398ac91152
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 10 10:01:14 2019 -0600
Circle, Ellipse: extract a make_path_builder function
rsvg_internals/src/shapes.rs | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
---
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index a5dcf926..e5fc1f20 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -48,26 +48,23 @@ fn render_path_builder(
}
}
-fn render_ellipse(
+fn make_ellipse(
cx: f64,
cy: f64,
rx: f64,
ry: f64,
- draw_ctx: &mut DrawingCtx,
- node: &RsvgNode,
- values: &ComputedValues,
- clipping: bool,
-) -> Result<BoundingBox, RenderingError> {
+) -> PathBuilder {
+ let mut builder = PathBuilder::new();
+
// Per the spec, rx and ry must be nonnegative
if rx <= 0.0 || ry <= 0.0 {
- return Ok(draw_ctx.empty_bbox());
+ return builder;
}
// 4/3 * (1-cos 45°)/sin 45° = 4/3 * sqrt(2) - 1
let arc_magic: f64 = 0.5522847498;
// approximate an ellipse using 4 Bézier curves
- let mut builder = PathBuilder::new();
builder.move_to(cx + rx, cy);
@@ -109,7 +106,7 @@ fn render_ellipse(
builder.close_path();
- render_path_builder(&builder, draw_ctx, node, values, false, clipping)
+ builder
}
#[derive(Default)]
@@ -592,14 +589,24 @@ impl NodeTrait for Circle {
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 Circle {
+ fn make_path_builder(
+ &self,
+ values: &ComputedValues,
+ draw_ctx: &mut DrawingCtx,
+ ) -> PathBuilder {
let params = draw_ctx.get_view_params();
let cx = self.cx.normalize(values, ¶ms);
let cy = self.cy.normalize(values, ¶ms);
let r = self.r.normalize(values, ¶ms);
- render_ellipse(cx, cy, r, r, draw_ctx, node, values, clipping)
+ make_ellipse(cx, cy, r, r)
}
}
@@ -638,7 +645,17 @@ impl NodeTrait for Ellipse {
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 Ellipse {
+ fn make_path_builder(
+ &self,
+ values: &ComputedValues,
+ draw_ctx: &mut DrawingCtx,
+ ) -> PathBuilder {
let params = draw_ctx.get_view_params();
let cx = self.cx.normalize(values, ¶ms);
@@ -646,7 +663,7 @@ impl NodeTrait for Ellipse {
let rx = self.rx.normalize(values, ¶ms);
let ry = self.ry.normalize(values, ¶ms);
- render_ellipse(cx, cy, rx, ry, draw_ctx, node, values, clipping)
+ make_ellipse(cx, cy, rx, ry)
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]