Skip to content

Commit

Permalink
fix: lsp warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
salam99823 committed Oct 20, 2024
1 parent 8f953d6 commit 91f4b86
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
31 changes: 20 additions & 11 deletions examples/bevy-image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use bevy::{prelude::Image, render::texture::ImageType};
use bevy::{
prelude::Image,
render::{
render_asset::RenderAssetUsages,
texture::{CompressedImageFormats, ImageSampler, ImageType},
},
};
use edges::Edges;
use raqote::*;
use raqote::{DrawOptions, DrawTarget, PathBuilder, SolidSource, Source, StrokeStyle};
// in an actual bevy app, you wouldn't need all this building an Image from scratch logic,
// it'd be something closer to this:
// `let image = image_assets.get(handle).unwrap();`
Expand All @@ -11,20 +17,20 @@ fn main() {
let boulders = Image::from_buffer(
include_bytes!("../assets/boulders.png"),
ImageType::Extension("png"),
Default::default(),
CompressedImageFormats::default(),
true,
Default::default(),
Default::default(),
ImageSampler::default(),
RenderAssetUsages::default(),
)
.unwrap();

let more_lines = Image::from_buffer(
include_bytes!("../assets/more-lines.png"),
ImageType::Extension("png"),
Default::default(),
CompressedImageFormats::default(),
true,
Default::default(),
Default::default(),
ImageSampler::default(),
RenderAssetUsages::default(),
)
.unwrap();

Expand All @@ -36,7 +42,10 @@ fn draw_png(image: Image, img_path: &str) {
// get the image's edges
let edges = Edges::from(image.clone());
let scale = 8;
let (width, height) = (image.width() as i32 * scale, image.height() as i32 * scale);
let (width, height) = (
i32::try_from(image.width()).expect("Image to wide.") * scale,
i32::try_from(image.height()).expect("Image to tall.") * scale,
);

// draw the edges to a png
let mut dt = DrawTarget::new(width, height);
Expand Down Expand Up @@ -71,6 +80,6 @@ fn draw_png(image: Image, img_path: &str) {
);
}

dt.write_png(format!("edges-{}", img_path)).unwrap();
_ = open::that(format!("edges-{}", img_path));
dt.write_png(format!("edges-{img_path}.png")).unwrap();
_ = open::that(format!("edges-{img_path}.png"));
}
13 changes: 8 additions & 5 deletions examples/dynamic-image.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use edges::Edges;
use raqote::*;
use raqote::{DrawOptions, DrawTarget, PathBuilder, SolidSource, Source, StrokeStyle};
use std::path::Path;

fn main() {
Expand All @@ -9,10 +9,13 @@ fn main() {
}

fn draw_png(img_path: &str) {
let image = &image::open(Path::new(&format!("assets/{}", img_path))).unwrap();
let image = &image::open(Path::new(&format!("assets/{img_path}"))).unwrap();
let edges = Edges::from(image);
let scale = 8;
let (width, height) = (image.width() as i32 * scale, image.height() as i32 * scale);
let (width, height) = (
i32::try_from(image.width()).expect("Image to wide.") * scale,
i32::try_from(image.height()).expect("Image to tall.") * scale,
);

// draw the edges to a png
let mut dt = DrawTarget::new(width, height);
Expand Down Expand Up @@ -41,6 +44,6 @@ fn draw_png(img_path: &str) {
&DrawOptions::new(),
);

dt.write_png(format!("edges-{}", img_path)).unwrap();
_ = open::that(format!("edges-{}", img_path));
dt.write_png(format!("edges-{img_path}")).unwrap();
_ = open::that(format!("edges-{img_path}"));
}

0 comments on commit 91f4b86

Please sign in to comment.