From 83d3680243df382faf0b5cf605b499e204ce4249 Mon Sep 17 00:00:00 2001 From: shnewto Date: Sun, 3 Mar 2024 18:51:17 -0700 Subject: [PATCH] a little cleanup --- README.md | 13 +++++++++++++ examples/bevy-image.rs | 2 +- examples/dynamic-image.rs | 4 +--- src/edges.rs | 14 +++++++------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index edc7fcf..82e8c32 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,19 @@ get the edges of objects in images with transparency +# using + +```rust +use edges::Edges; +use std::path::Path; + +fn main() { + let image = image::open(Path::new("assets/car.png")); + let edges = Edges::from(image.unwrap()); + println!("{:#?}", edges.single_image_edge_translated()); +} +``` + ## disclaimer this existed first as implementation over in a crate called [bevy_collider_gen](). at the time, that's what it seemed most useful for. this crate represents me starting to wonder whether it's useful for something else. diff --git a/examples/bevy-image.rs b/examples/bevy-image.rs index 22d8a49..fde09fa 100644 --- a/examples/bevy-image.rs +++ b/examples/bevy-image.rs @@ -18,5 +18,5 @@ fn main() { // get the image's edges let edges = Edges::from(image.unwrap()); - println!("{:#?}", edges); + println!("{:#?}", edges.single_image_edge_translated()); } diff --git a/examples/dynamic-image.rs b/examples/dynamic-image.rs index 140404f..3386f85 100644 --- a/examples/dynamic-image.rs +++ b/examples/dynamic-image.rs @@ -3,8 +3,6 @@ use std::path::Path; fn main() { let image = image::open(Path::new("assets/car.png")); - - // get the image's edges let edges = Edges::from(image.unwrap()); - println!("{:#?}", edges); + println!("{:#?}", edges.single_image_edge_translated()); } diff --git a/src/edges.rs b/src/edges.rs index eabfe68..45f38c4 100644 --- a/src/edges.rs +++ b/src/edges.rs @@ -12,30 +12,30 @@ 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) pub fn single_image_edge_translated(&self) -> Vec { - self.image_to_edges(true).into_iter().flatten().collect() + self.image_edges(true).into_iter().flatten().collect() } /// 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 pub fn single_image_edge_raw(&self) -> Vec { - self.image_to_edges(false).into_iter().flatten().collect() + self.image_edges(false).into_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) pub fn multi_image_edge_translated(&self) -> Vec> { - self.image_to_edges(true) + self.image_edges(true) } /// 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 pub fn multi_image_edges_raw(&self) -> Vec> { - self.image_to_edges(false) + self.image_edges(false) } /// Takes a Bevy DynamicImage type and an 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 - pub fn image_to_edges(&self, translate: bool) -> Vec> { + pub fn image_edges(&self, translate: bool) -> Vec> { let rows = self.height(); let cols = self.width(); let data: &[u8] = self.bytes(); @@ -253,8 +253,8 @@ impl fmt::Debug for Edges { } let edges_display = EdgesDisplay { - raw: self.image_to_edges(false), - translated: self.image_to_edges(false), + raw: self.image_edges(false), + translated: self.image_edges(false), }; write!(f, "{:#?}", edges_display) }