Skip to content

Commit

Permalink
Clean up pico_svg lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
xorgy committed Mar 11, 2024
1 parent f24f15a commit 65bd3b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
44 changes: 20 additions & 24 deletions examples/scenes/src/pico_svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,23 @@ impl PicoSvg {
},
),
}
} else if let Some((width, height)) = root.attribute("width").zip(root.attribute("height"))
{
(
Point::ZERO,
Size {
width: f64::from_str(width).unwrap(),
height: f64::from_str(height).unwrap(),
},
)
} else {
let maybe_width = root.attribute("width");
let maybe_height = root.attribute("height");
if maybe_width.is_some() && maybe_height.is_some() {
(
Point::ZERO,
Size {
width: f64::from_str(maybe_width.unwrap()).unwrap(),
height: f64::from_str(maybe_height.unwrap()).unwrap(),
},
)
} else {
(
Point::ZERO,
Size {
width: 300.0,
height: 150.0,
},
)
}
(
Point::ZERO,
Size {
width: 300.0,
height: 150.0,
},
)
};
let transform = Affine::translate(origin.to_vec2() * -1.0)
* if scale >= 0.0 {
Expand Down Expand Up @@ -127,8 +124,7 @@ impl<'a> Parser<'a> {
}
}
if let Some(transform) = node.attribute("transform") {
let new_transform = parse_transform(transform);
properties.transform = properties.transform * new_transform;
properties.transform *= parse_transform(transform);
}
match node.tag_name().name() {
"g" => {
Expand Down Expand Up @@ -243,12 +239,12 @@ fn parse_color(color: &str) -> Color {

fn modify_opacity(mut color: Color, attr_name: &str, node: Node) -> Color {
if let Some(opacity) = node.attribute(attr_name) {
let alpha = if opacity.ends_with("%") {
let pctg = opacity[..opacity.len() - 1].parse().unwrap_or(100.0);
let alpha: f64 = if let Some(o) = opacity.strip_suffix("%") {
let pctg = o.parse().unwrap_or(100.0);
pctg * 0.01
} else {
opacity.parse().unwrap_or(1.0)
} as f64;
};
color.a = (alpha.min(1.0).max(0.0) * 255.0).round() as u8;
color
} else {
Expand Down
14 changes: 6 additions & 8 deletions examples/scenes/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ pub fn svg_function_of<R: AsRef<str>>(
) -> impl FnMut(&mut Scene, &mut SceneParams) {
fn render_svg_contents(name: &str, contents: &str) -> (Scene, Vec2) {
use crate::pico_svg::*;
let mut start = Instant::now();
let mut new_scene = Scene::new();
let mut resolution = Vec2::new(420 as f64, 420 as f64);
let start = Instant::now();
match PicoSvg::load(contents, 1.0) {
std::result::Result::Ok(PicoSvg { items, size }) => {
eprintln!("Parsed svg {name} in {:?}", start.elapsed());
start = Instant::now();
resolution = size.to_vec2();
let start = Instant::now();
let mut new_scene = Scene::new();
for item in items {
match item {
Item::Fill(fill) => {
Expand All @@ -127,14 +125,14 @@ pub fn svg_function_of<R: AsRef<str>>(
}
}
}
eprintln!("Encoded svg {name} in {:?}", start.elapsed());
(new_scene, size.to_vec2())
}
std::result::Result::Err(e) => {
eprintln!("{:?}", e);
(Scene::new(), Vec2::ZERO)
}
}

eprintln!("Encoded svg {name} in {:?}", start.elapsed());
(new_scene, resolution)
}
let mut cached_scene = None;
#[cfg(not(target_arch = "wasm32"))]
Expand Down

0 comments on commit 65bd3b9

Please sign in to comment.