From 1bb608c39711da1e45cde17d1bb988076672b80d Mon Sep 17 00:00:00 2001 From: salam Date: Fri, 15 Nov 2024 07:49:22 +0900 Subject: [PATCH 01/11] refactor: removed translate flag and replaced with translate objects function --- examples/bevy-image.rs | 10 ++--- examples/dynamic-image.rs | 8 ++-- src/bin_image.rs | 8 ++-- src/lib.rs | 93 ++++++++++++++++++++++++++------------- src/tests.rs | 8 ++-- 5 files changed, 79 insertions(+), 48 deletions(-) diff --git a/examples/bevy-image.rs b/examples/bevy-image.rs index 1af434b..5ad77fb 100644 --- a/examples/bevy-image.rs +++ b/examples/bevy-image.rs @@ -53,23 +53,23 @@ fn draw_png(image: &Image, img_path: &str) { let scale = 8; let (width, height) = ( - i32::try_from(image.width()).expect("Image to wide.") * scale, - i32::try_from(image.height()).expect("Image to tall.") * scale, + i32::try_from(image.width() * scale).expect("Image to wide."), + i32::try_from(image.height() * scale).expect("Image to tall."), ); // draw the edges to a png let mut dt = DrawTarget::new(width, height); - let objects = edges.multi_image_edges_raw(); + let objects = edges.multi_image_edge_raw(); for object in objects { let mut pb = PathBuilder::new(); let mut edges_iter = object.into_iter(); if let Some(first_edge) = edges_iter.next() { - pb.move_to(first_edge.x * scale as f32, first_edge.y * scale as f32); + pb.move_to((first_edge.x * scale) as f32, (first_edge.y * scale) as f32); for edge in edges_iter { - pb.line_to(edge.x * scale as f32, edge.y * scale as f32); + pb.line_to((edge.x * scale) as f32, (edge.y * scale) as f32); } } diff --git a/examples/dynamic-image.rs b/examples/dynamic-image.rs index 3e1e544..6b4ee4d 100644 --- a/examples/dynamic-image.rs +++ b/examples/dynamic-image.rs @@ -15,8 +15,8 @@ fn draw_png(img_path: &str) { let scale = 8; let (width, height) = ( - i32::try_from(image.width()).expect("Image to wide.") * scale, - i32::try_from(image.height()).expect("Image to tall.") * scale, + i32::try_from(image.width() * scale).expect("Image to wide."), + i32::try_from(image.height() * scale).expect("Image to tall."), ); // draw the edges to a png @@ -25,9 +25,9 @@ fn draw_png(img_path: &str) { let mut edges_iter = edges.single_image_edge_raw().into_iter(); let first_edge = edges_iter.next().unwrap(); - pb.move_to(first_edge.x * scale as f32, first_edge.y * scale as f32); + pb.move_to((first_edge.x * scale) as f32, (first_edge.y * scale) as f32); for edge in edges_iter { - pb.line_to(edge.x * scale as f32, edge.y * scale as f32); + pb.line_to((edge.x * scale) as f32, (edge.y * scale) as f32); } let path = pb.finish(); diff --git a/src/bin_image.rs b/src/bin_image.rs index f2db458..e1b4c9c 100644 --- a/src/bin_image.rs +++ b/src/bin_image.rs @@ -131,10 +131,10 @@ impl BinImage { /// # Returns /// /// A new `Vec2` representing the translated coordinates - fn translate_point(&self, p: Vec2) -> Vec2 { + const fn translate_point(&self, p: UVec2) -> Vec2 { Vec2::new( - p.x - ((self.width / 2) as f32 - 1.0), - ((self.height / 2) as f32 - 1.0) - p.y, + (p.x - self.width / 2 - 1) as f32, + (self.height / 2 - p.y - 1) as f32, ) } @@ -147,7 +147,7 @@ impl BinImage { /// # Returns /// /// A vector of `Vec2` representing the translated coordinates. - pub fn translate(&self, v: Vec) -> Vec { + pub fn translate(&self, v: Vec) -> Vec { v.into_par_iter().map(|p| self.translate_point(p)).collect() } diff --git a/src/lib.rs b/src/lib.rs index 6abfdca..fe73bad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,15 @@ pub struct Edges { } impl Edges { + /// Creates a new `Edges` instance from the given dimensions and pixel data. + /// + /// # Arguments + /// + /// * `height` - The height of the image. + /// * `width` - The width of the image. + /// * `data` - A slice of bytes representing the pixel data of the image. + /// + #[inline] #[must_use] pub fn new(height: u32, width: u32, data: &[u8]) -> Self { Self { @@ -27,38 +36,54 @@ impl Edges { } } - /// If there's only one sprite / object in the image, this returns just one, with - /// coordinates translated to either side of (0, 0) + /// Translates the edges of a single image into a coordinate system centered at (0, 0). + /// + /// # Returns + /// + /// A vector of `Vec2` representing the translated edge points. + #[inline] #[must_use] pub fn single_image_edge_translated(&self) -> Vec { - self.image_edges(true).into_par_iter().flatten().collect() + self.translate(self.single_image_edge_raw()) } - /// If there's only one sprite / object in the image, this returns just one, with - /// coordinates left alone and all in positive x and y + /// Retrieves the raw edge points of a single image. + /// + /// # Returns + /// + /// A vector of `UVec2` representing the raw edge points. + #[inline] #[must_use] - pub fn single_image_edge_raw(&self) -> Vec { - self.image_edges(false).into_par_iter().flatten().collect() + pub fn single_image_edge_raw(&self) -> Vec { + self.image_edges().into_par_iter().flatten().collect() } - /// If there's more than one sprite / object in the image, this returns all it finds, with - /// coordinates translated to either side of (0, 0) + /// Translates the edges of multiple images into a coordinate system centered at (0, 0). + /// + /// # Returns + /// + /// A vector of vectors of `Vec2` representing the translated edge points of each image. + #[inline] #[must_use] pub fn multi_image_edge_translated(&self) -> Vec> { - self.image_edges(true) + self.translate_objects(self.multi_image_edge_raw()) } - /// If there's more than one sprite / object in the image, this returns all it finds, with - /// coordinates left alone and all in positive x and y + /// Retrieves the raw edge points of multiple images. + /// + /// # Returns + /// + /// A vector of vectors of `UVec2` representing the raw edge points of each image. + #[inline] #[must_use] - pub fn multi_image_edges_raw(&self) -> Vec> { - self.image_edges(false) + pub fn multi_image_edge_raw(&self) -> Vec> { + self.image_edges() } /// Takes `Edges` and a boolean to indicate whether to translate /// the points you get back to either side of (0, 0) instead of everything in positive x and y. #[must_use] - pub fn image_edges(&self, translate: bool) -> Vec> { + pub fn image_edges(&self) -> Vec> { let image = &self.image; // Marching squares adjacent, walks all the pixels in the provided data and keeps track of // any that have at least one transparent / zero value neighbor then, while sorting into drawing @@ -69,19 +94,7 @@ impl Edges { .filter(|p| image.get(*p) && image.is_corner(*p)) .collect(); - let objects: Vec<_> = self - .collect_objects(&corners) - .into_par_iter() - .map(|object| object.into_par_iter().map(|p| p.as_vec2()).collect()) - .collect(); - if translate { - objects - .into_par_iter() - .map(|object| self.translate(object)) - .collect() - } else { - objects - } + self.collect_objects(&corners) } fn collect_objects(&self, corners: &[UVec2]) -> Vec> { @@ -145,10 +158,28 @@ impl Edges { /// # Returns /// /// A vector of `Vec2` representing the translated coordinates. + #[inline] #[must_use] - pub fn translate(&self, v: Vec) -> Vec { + pub fn translate(&self, v: Vec) -> Vec { self.image.translate(v) } + + /// Translates an `Vec` of `Vec` of points in positive (x, y) coordinates to a coordinate system centered at (0, 0). + /// + /// # Arguments + /// + /// * `v` - An `Vec` of `Vec2` points to translate. + /// + /// # Returns + /// + /// A vector of vector of `Vec2` representing the translated objects. + #[inline] + #[must_use] + pub fn translate_objects(&self, v: Vec>) -> Vec> { + v.into_par_iter() + .map(|v| self.translate(v)) + .collect::>() + } } #[cfg(feature = "bevy")] @@ -184,8 +215,8 @@ impl fmt::Debug for Edges { "Edges {{{}\n}}", format!( "\nraw: {:#?},\ntranslated: {:#?}", - self.image_edges(false), - self.image_edges(true), + self.image_edges(), + self.translate_objects(self.image_edges()) ) .replace('\n', "\n "), ) diff --git a/src/tests.rs b/src/tests.rs index 4611555..d80cb9b 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -14,7 +14,7 @@ fn same_image_same_edges() { include_bytes!("../assets/car.png"), // buffer ImageType::Extension("png"), CompressedImageFormats::default(), - true, // + true, ImageSampler::default(), RenderAssetUsages::default(), ) @@ -40,7 +40,7 @@ fn same_images_same_edges() { include_bytes!("../assets/boulders.png"), // buffer ImageType::Extension("png"), CompressedImageFormats::default(), - true, // + true, ImageSampler::default(), RenderAssetUsages::default(), ) @@ -48,8 +48,8 @@ fn same_images_same_edges() { let bevy_edges = Edges::from(bevy_image); assert_eq!( - dynamic_edges.multi_image_edges_raw(), - bevy_edges.multi_image_edges_raw() + dynamic_edges.multi_image_edge_raw(), + bevy_edges.multi_image_edge_raw() ); assert_eq!( dynamic_edges.multi_image_edge_translated(), From 662f42c7e1d478a66b62555801bf6f85ad6f36d4 Mon Sep 17 00:00:00 2001 From: salam Date: Sat, 16 Nov 2024 04:28:58 +0900 Subject: [PATCH 02/11] add: impl trait for convert `Edges` into `Vec` --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index fe73bad..a0bdf12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -182,6 +182,12 @@ impl Edges { } } +impl From for Vec> { + fn from(value: Edges) -> Vec> { + value.image_edges() + } +} + #[cfg(feature = "bevy")] impl From for Edges { fn from(i: bevy_render::prelude::Image) -> Edges { From 6309010ff35e7101128b44f30db6960511fd4b76 Mon Sep 17 00:00:00 2001 From: salam Date: Sun, 17 Nov 2024 11:35:26 +0900 Subject: [PATCH 03/11] add: impl Debug and Display for BinImage --- src/bin_image.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/bin_image.rs b/src/bin_image.rs index e1b4c9c..76aa183 100644 --- a/src/bin_image.rs +++ b/src/bin_image.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use crate::{utils::is_corner, UVec2, Vec2}; use rayon::prelude::*; pub mod neighbors { @@ -11,6 +13,8 @@ pub mod neighbors { pub const SOUTHWEST: u8 = 0b0000_0001; } +/// A struct representing a binary image. +#[derive(Debug)] pub struct BinImage { data: Vec, height: u32, @@ -158,4 +162,21 @@ impl BinImage { pub const fn width(&self) -> u32 { self.width } + +} + +impl Display for BinImage { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for y in 0..self.height() { + for x in 0..self.width() { + if self.get(UVec2::new(x, y)) { + write!(f, "█")?; + } else { + write!(f, "-")?; + } + } + writeln!(f)?; + } + Ok(()) + } } From 283962988561df95d09342ba855b82f437eab5d4 Mon Sep 17 00:00:00 2001 From: salam Date: Sun, 17 Nov 2024 11:38:26 +0900 Subject: [PATCH 04/11] refactor: `is_corner` function --- src/bin_image.rs | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin_image.rs b/src/bin_image.rs index 76aa183..56e4a60 100644 --- a/src/bin_image.rs +++ b/src/bin_image.rs @@ -123,7 +123,7 @@ impl BinImage { } pub fn is_corner(&self, p: UVec2) -> bool { - is_corner(self.get_neighbors(p)) + self.get(p) && is_corner(self.get_neighbors(p)) } /// Translates a point in positive (x, y) coordinates to a coordinate system centered at (0, 0). diff --git a/src/lib.rs b/src/lib.rs index a0bdf12..103cf4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,7 @@ impl Edges { let corners: Vec<_> = (0..image.height() * image.width()) .into_par_iter() .map(|i| UVec2::new(i / image.height(), i % image.height())) - .filter(|p| image.get(*p) && image.is_corner(*p)) + .filter(|p| image.is_corner(*p)) .collect(); self.collect_objects(&corners) From 9c104201a1fd12a412dcb617309d27e381520bd2 Mon Sep 17 00:00:00 2001 From: salam Date: Sun, 17 Nov 2024 11:40:09 +0900 Subject: [PATCH 05/11] fix: impl Debug for Edges --- src/lib.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 103cf4d..cd38dd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -216,15 +216,9 @@ impl From<&image::DynamicImage> for Edges { impl fmt::Debug for Edges { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "Edges {{{}\n}}", - format!( - "\nraw: {:#?},\ntranslated: {:#?}", - self.image_edges(), - self.translate_objects(self.image_edges()) - ) - .replace('\n', "\n "), - ) + f.debug_struct("Edges") + .field("raw", &self.image_edges()) + .field("translated", &self.translate_objects(self.image_edges())) + .finish() } } From 0fdc7329ddf46bb4e4e60e16348c788c8de1b7e7 Mon Sep 17 00:00:00 2001 From: salam Date: Sun, 17 Nov 2024 13:52:14 +0900 Subject: [PATCH 06/11] add: impl Clone Trait for Edges and BinImage --- src/bin_image.rs | 2 +- src/lib.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin_image.rs b/src/bin_image.rs index 56e4a60..c55e000 100644 --- a/src/bin_image.rs +++ b/src/bin_image.rs @@ -14,7 +14,7 @@ pub mod neighbors { } /// A struct representing a binary image. -#[derive(Debug)] +#[derive(Clone, Debug, Default)] pub struct BinImage { data: Vec, height: u32, diff --git a/src/lib.rs b/src/lib.rs index cd38dd8..6dcdc8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ mod bin_image; mod tests; mod utils; +/// A struct representing the edges of a image. +#[derive(Clone)] pub struct Edges { image: BinImage, } From 16c10989d226d0941d7c42a4d9048b876b8af086 Mon Sep 17 00:00:00 2001 From: salam Date: Sun, 17 Nov 2024 15:57:35 +0900 Subject: [PATCH 07/11] changed translate alignment --- src/bin_image.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin_image.rs b/src/bin_image.rs index c55e000..a9006d0 100644 --- a/src/bin_image.rs +++ b/src/bin_image.rs @@ -137,8 +137,8 @@ impl BinImage { /// A new `Vec2` representing the translated coordinates const fn translate_point(&self, p: UVec2) -> Vec2 { Vec2::new( - (p.x - self.width / 2 - 1) as f32, - (self.height / 2 - p.y - 1) as f32, + p.x as f32 - (self.width / 2) as f32, + (self.height / 2) as f32 - p.y as f32, ) } From da3181ad933b82d9eeca3f39d4f77f84daeac3e7 Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 2 Dec 2024 16:40:10 +0900 Subject: [PATCH 08/11] refactor: assert replaced by debug_assert --- src/bin_image.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/bin_image.rs b/src/bin_image.rs index a9006d0..6cfd89e 100644 --- a/src/bin_image.rs +++ b/src/bin_image.rs @@ -35,7 +35,7 @@ impl BinImage { /// /// This function will panic if the length of `data` is less than `height * width`. pub fn new(height: u32, width: u32, data: &[u8]) -> Self { - assert!( + debug_assert!( data.len() >= (height * width) as usize, "data must not be smaller than image dimensions" ); @@ -68,18 +68,19 @@ impl BinImage { /// Returns `true` if the pixel is "on" (1), and `false` if it is "off" (0) or out of bounds. pub fn get(&self, p: UVec2) -> bool { if p.x >= self.width { - return false; - } - let index = p.y * self.width + p.x; - if let Some(mut byte) = self - .data - .get((index / 8) as usize) // index of byte - .copied() - { - byte >>= index % 8; // index of bit - byte & 1 > 0 - } else { false + } else { + let index = p.y * self.width + p.x; + if let Some(mut byte) = self + .data + .get((index / 8) as usize) // index of byte + .copied() + { + byte >>= index % 8; // index of bit + byte & 1 > 0 + } else { + false + } } } From 334386db54e164b13ba2541d7a107f3832fce650 Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 2 Dec 2024 16:42:08 +0900 Subject: [PATCH 09/11] removed superfluous doc --- src/bin_image.rs | 13 ------------- src/lib.rs | 15 --------------- 2 files changed, 28 deletions(-) diff --git a/src/bin_image.rs b/src/bin_image.rs index 6cfd89e..c7c2740 100644 --- a/src/bin_image.rs +++ b/src/bin_image.rs @@ -86,10 +86,6 @@ impl BinImage { /// Gets the values of the neighboring pixels (8-connectivity) around the given coordinate. /// - /// # Arguments - /// - /// * `p` - A `UVec2` representing the coordinates of the center pixel. - /// /// # Returns /// /// An byte representing the state of the neighboring pixels. @@ -129,10 +125,6 @@ impl BinImage { /// Translates a point in positive (x, y) coordinates to a coordinate system centered at (0, 0). /// - /// # Arguments - /// - /// * `p` - A `Vec2` representing the point to translate. - /// /// # Returns /// /// A new `Vec2` representing the translated coordinates @@ -145,10 +137,6 @@ impl BinImage { /// Translates an `Vec` of points in positive (x, y) coordinates to a coordinate system centered at (0, 0). /// - /// # Arguments - /// - /// * `v` - An `Vec` of `Vec2` points to translate. - /// /// # Returns /// /// A vector of `Vec2` representing the translated coordinates. @@ -163,7 +151,6 @@ impl BinImage { pub const fn width(&self) -> u32 { self.width } - } impl Display for BinImage { diff --git a/src/lib.rs b/src/lib.rs index 6dcdc8f..906588e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,13 +23,6 @@ pub struct Edges { impl Edges { /// Creates a new `Edges` instance from the given dimensions and pixel data. - /// - /// # Arguments - /// - /// * `height` - The height of the image. - /// * `width` - The width of the image. - /// * `data` - A slice of bytes representing the pixel data of the image. - /// #[inline] #[must_use] pub fn new(height: u32, width: u32, data: &[u8]) -> Self { @@ -153,10 +146,6 @@ impl Edges { /// Translates an `Vec` of points in positive (x, y) coordinates to a coordinate system centered at (0, 0). /// - /// # Arguments - /// - /// * `v` - An `Vec` of `Vec2` points to translate. - /// /// # Returns /// /// A vector of `Vec2` representing the translated coordinates. @@ -168,10 +157,6 @@ impl Edges { /// Translates an `Vec` of `Vec` of points in positive (x, y) coordinates to a coordinate system centered at (0, 0). /// - /// # Arguments - /// - /// * `v` - An `Vec` of `Vec2` points to translate. - /// /// # Returns /// /// A vector of vector of `Vec2` representing the translated objects. From ac1a5a5b7ed056723d4727bbb3a2bd11def3c70f Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 2 Dec 2024 16:51:24 +0900 Subject: [PATCH 10/11] upd: to bevy 0.15 --- Cargo.toml | 13 +++++++++---- examples/bevy-image.rs | 7 ++----- src/lib.rs | 8 ++++---- src/tests.rs | 6 ++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d209bdc..9120a09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ pedantic = { level = "warn", priority = 0 } [features] default = ["bevy"] glam-latest = ["dep:glam"] -bevy = ["dep:bevy_math", "dep:bevy_render"] +bevy = ["dep:bevy_math", "dep:bevy_image"] [dependencies] image = "0.25" @@ -32,19 +32,24 @@ version = "0.29" optional = true [dependencies.bevy_math] -version = "0.14" +version = "0.15" default-features = false optional = true -[dependencies.bevy_render] -version = "0.14" +[dependencies.bevy_image] +version = "0.15" default-features = false +features = ["png"] optional = true [dev-dependencies] raqote = "0.8" open = "5.1" +[dev-dependencies.bevy_render] +version = "0.15" +default-features = false + [[example]] name = "bevy-image" required-features = ["bevy"] diff --git a/examples/bevy-image.rs b/examples/bevy-image.rs index 5ad77fb..1970a93 100644 --- a/examples/bevy-image.rs +++ b/examples/bevy-image.rs @@ -1,8 +1,5 @@ -use bevy_render::{ - prelude::Image, - render_asset::RenderAssetUsages, - texture::{CompressedImageFormats, ImageSampler, ImageType}, -}; +use bevy_image::{prelude::Image, CompressedImageFormats, ImageSampler, ImageType}; +use bevy_render::render_asset::RenderAssetUsages; use edges::Edges; 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, diff --git a/src/lib.rs b/src/lib.rs index 906588e..cfe5d44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -176,8 +176,8 @@ impl From for Vec> { } #[cfg(feature = "bevy")] -impl From for Edges { - fn from(i: bevy_render::prelude::Image) -> Edges { +impl From for Edges { + fn from(i: bevy_image::prelude::Image) -> Edges { Self::new(i.height(), i.width(), &i.data) } } @@ -189,8 +189,8 @@ impl From for Edges { } #[cfg(feature = "bevy")] -impl From<&bevy_render::prelude::Image> for Edges { - fn from(i: &bevy_render::prelude::Image) -> Edges { +impl From<&bevy_image::prelude::Image> for Edges { + fn from(i: &bevy_image::prelude::Image) -> Edges { Self::new(i.height(), i.width(), &i.data) } } diff --git a/src/tests.rs b/src/tests.rs index d80cb9b..49f3520 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,8 +1,6 @@ use crate::Edges; -use bevy_render::{ - render_asset::RenderAssetUsages, - texture::{CompressedImageFormats, Image, ImageSampler, ImageType}, -}; +use bevy_image::{prelude::Image, CompressedImageFormats, ImageSampler, ImageType}; +use bevy_render::render_asset::RenderAssetUsages; use std::path::Path; #[test] From 702d7eff3f9bbcedeaa4855dbbfb391e4a2d54a2 Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 2 Dec 2024 16:52:23 +0900 Subject: [PATCH 11/11] fix: line transparency --- examples/bevy-image.rs | 2 +- examples/dynamic-image.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/bevy-image.rs b/examples/bevy-image.rs index 1970a93..604a415 100644 --- a/examples/bevy-image.rs +++ b/examples/bevy-image.rs @@ -80,7 +80,7 @@ fn draw_png(image: &Image, img_path: &str) { a: 0xff, }), &StrokeStyle { - width: 1., + width: scale as f32, ..StrokeStyle::default() }, &DrawOptions::new(), diff --git a/examples/dynamic-image.rs b/examples/dynamic-image.rs index 6b4ee4d..803399c 100644 --- a/examples/dynamic-image.rs +++ b/examples/dynamic-image.rs @@ -40,7 +40,7 @@ fn draw_png(img_path: &str) { a: 0xff, }), &StrokeStyle { - width: 1., + width: scale as f32, ..StrokeStyle::default() }, &DrawOptions::new(),