[librsvg: 5/12] Return Cow<PathBuilder> from all the make_path_builder functions
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/12] Return Cow<PathBuilder> from all the make_path_builder functions
- Date: Tue, 10 Dec 2019 19:44:57 +0000 (UTC)
commit ffdbe70b05f30d0e1897e2402c1db47de1393111
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 10 10:16:42 2019 -0600
Return Cow<PathBuilder> from all the make_path_builder functions
This will let us reduce everything to a trait.
rsvg_internals/src/path_builder.rs | 4 ++--
rsvg_internals/src/shapes.rs | 29 +++++++++++++++--------------
2 files changed, 17 insertions(+), 16 deletions(-)
---
diff --git a/rsvg_internals/src/path_builder.rs b/rsvg_internals/src/path_builder.rs
index 8c733725..819365d5 100644
--- a/rsvg_internals/src/path_builder.rs
+++ b/rsvg_internals/src/path_builder.rs
@@ -269,7 +269,7 @@ pub(crate) fn arc_segment(
}
}
-#[derive(Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq)]
pub enum PathCommand {
MoveTo(f64, f64),
LineTo(f64, f64),
@@ -290,7 +290,7 @@ impl PathCommand {
}
}
-#[derive(Default)]
+#[derive(Clone, Default)]
pub struct PathBuilder {
path_commands: Vec<PathCommand>,
}
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index a5c702f9..f8fe03e1 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -1,6 +1,7 @@
use cairo;
use markup5ever::{expanded_name, local_name, namespace_url, ns};
use std::ops::Deref;
+use std::borrow::Cow;
use crate::bbox::BoundingBox;
use crate::drawing_ctx::DrawingCtx;
@@ -234,8 +235,8 @@ impl Polygon {
&self,
_values: &ComputedValues,
_draw_ctx: &mut DrawingCtx,
- ) -> PathBuilder {
- make_poly(self.points.as_ref(), true)
+ ) -> Cow<PathBuilder> {
+ Cow::Owned(make_poly(self.points.as_ref(), true))
}
}
@@ -273,8 +274,8 @@ impl Polyline {
&self,
_values: &ComputedValues,
_draw_ctx: &mut DrawingCtx,
- ) -> PathBuilder {
- make_poly(self.points.as_ref(), false)
+ ) -> Cow<PathBuilder> {
+ Cow::Owned(make_poly(self.points.as_ref(), false))
}
}
@@ -319,7 +320,7 @@ impl Line {
&self,
values: &ComputedValues,
draw_ctx: &mut DrawingCtx,
- ) -> PathBuilder {
+ ) -> Cow<PathBuilder> {
let mut builder = PathBuilder::new();
let params = draw_ctx.get_view_params();
@@ -332,7 +333,7 @@ impl Line {
builder.move_to(x1, y1);
builder.line_to(x2, y2);
- builder
+ Cow::Owned(builder)
}
}
@@ -395,7 +396,7 @@ impl Rect {
&self,
values: &ComputedValues,
draw_ctx: &mut DrawingCtx,
- ) -> PathBuilder {
+ ) -> Cow<PathBuilder> {
let params = draw_ctx.get_view_params();
let x = self.x.normalize(values, ¶ms);
@@ -432,12 +433,12 @@ impl Rect {
// Per the spec, w,h must be >= 0
if w <= 0.0 || h <= 0.0 {
- return builder;
+ return Cow::Owned(builder);
}
// ... and rx,ry must be nonnegative
if rx < 0.0 || ry < 0.0 {
- return builder;
+ return Cow::Owned(builder);
}
let half_w = w / 2.0;
@@ -563,7 +564,7 @@ impl Rect {
builder.close_path();
}
- builder
+ Cow::Owned(builder)
}
}
@@ -608,14 +609,14 @@ impl Circle {
&self,
values: &ComputedValues,
draw_ctx: &mut DrawingCtx,
- ) -> PathBuilder {
+ ) -> Cow<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);
- make_ellipse(cx, cy, r, r)
+ Cow::Owned(make_ellipse(cx, cy, r, r))
}
}
@@ -664,7 +665,7 @@ impl Ellipse {
&self,
values: &ComputedValues,
draw_ctx: &mut DrawingCtx,
- ) -> PathBuilder {
+ ) -> Cow<PathBuilder> {
let params = draw_ctx.get_view_params();
let cx = self.cx.normalize(values, ¶ms);
@@ -672,7 +673,7 @@ impl Ellipse {
let rx = self.rx.normalize(values, ¶ms);
let ry = self.ry.normalize(values, ¶ms);
- make_ellipse(cx, cy, rx, ry)
+ Cow::Owned(make_ellipse(cx, cy, rx, ry))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]