Skip to content

Commit

Permalink
Merge pull request #9 from shnewto/dev
Browse files Browse the repository at this point in the history
Migration to binary_image crate and algorithm fix
  • Loading branch information
shnewto authored Dec 14, 2024
2 parents 5e5e805 + 8357b51 commit 3f5ece4
Show file tree
Hide file tree
Showing 14 changed files with 655 additions and 669 deletions.
72 changes: 61 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,45 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.0](https://github.com/shnewto/edges/compare/0.5.1...0.6.0) - 2024-12-04

### Added

- Feature `parallel`, which depends on [`rayon`]
([6dab192](https://github.com/shnewto/edges/commit/6dab192ee37572bcd6d35fa14421d401f574f47b)).
- External public crate [`binary_image`]
([076d53b](https://github.com/shnewto/edges/commit/076d53b636d31583d41f34b4fdc55267478de085)).
- Iterator `iter::Edges` for `Edges`
([10397be](https://github.com/shnewto/edges/commit/10397beb6557fb239be9f254c31fa227389d47c2)).

### Changed

- [`rayon`] marked as optional dependencies
([6dab192](https://github.com/shnewto/edges/commit/6dab192ee37572bcd6d35fa14421d401f574f47b)).
- Functions factored out.
- `translate`
- `translate_objects`
- Now `UVec2`, `Vec2` is inner
([ba68b6c](https://github.com/shnewto/edges/commit/ba68b6c1fc8fb49c04697c6e20694f1deaea4fcc)).
- Function names have been shortened
([0266d7e](https://github.com/shnewto/edges/commit/0266d7e0c6a0c9b99ab5eac69e20eccfb9b25276)):
- `single_image_edge_translated` to `single_translated`.
- `single_image_edge_raw` to `single_raw`.
- `multi_image_edge_translated` to `multi_translated`.
- `multi_image_edge_raw` to `multi_raw`.
- Now `Edges` is unit
([10397be](https://github.com/shnewto/edges/commit/10397beb6557fb239be9f254c31fa227389d47c2)).

### Fixed

- Work with channels of pixels
([10397be](https://github.com/shnewto/edges/commit/10397beb6557fb239be9f254c31fa227389d47c2)).

### Removed

- Functions `image_edges`, `new`
([10397be](https://github.com/shnewto/edges/commit/10397beb6557fb239be9f254c31fa227389d47c2)).

## [0.5.1](https://github.com/shnewto/edges/compare/0.5.0...0.5.1) - 2024-12-04

### Added
Expand Down Expand Up @@ -64,7 +103,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Method `translate_vec` renamed to `translate`
([5573751](https://github.com/shnewto/edges/commit/55737517a246b207e87c8abf99d6fbe3d3786e0a)).
- Dependency on [`bevy`](https://crates.io/crates/bevy) replaced with
[`bevy_math`](https://crates.io/crates/bevy_math) and [`bevy_render`](https://crates.io/crates/bevy_render)
[`bevy_math`] and [`bevy_render`]
([e7ab40a](https://github.com/shnewto/edges/commit/e7ab40a25e933bce24380bc090dea503b0bc93d4)).

### Fixed
Expand All @@ -77,26 +116,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Crates from dependencies
([334361c](https://github.com/shnewto/edges/commit/334361c7c1acca3e3e548b679046c5117f087de2))
([e7ab40a](https://github.com/shnewto/edges/commit/e7ab40a25e933bce24380bc090dea503b0bc93d4)):
- [`hashbrown`](https://crates.io/crates/hashbrown)
- [`mashmap`](https://crates.io/crates/mashmap)
- [`ordered-float`](https://crates.io/crates/ordered-float)
- [`thiserror`](https://crates.io/crates/thiserror)
- [`hashbrown`]
- [`mashmap`]
- [`ordered-float`]
- [`thiserror`]
- Method `march_edges` replaced by `new`
([3f5052f](https://github.com/shnewto/edges/commit/3f5052fbe720eee8011e26e617b737f4577a28d7)).

## [0.3.4](https://github.com/shnewto/edges/compare/0.3.3...0.3.4) - 2024-08-13

### Changed

- Upgrade dependencies: [`glam`](https://crates.io/crates/glam) 0.27.0 ([1912e24](https://github.com/shnewto/edges/commit/1912e24647e885c9340c7667f0f8967bca670456)).
- Upgrade dependencies: [`glam`] 0.27.0 ([1912e24](https://github.com/shnewto/edges/commit/1912e24647e885c9340c7667f0f8967bca670456)).

## [0.3.3](https://github.com/shnewto/edges/compare/0.3.2...0.3.3) - 2024-07-08

### Changed

- Upgrade dependencies:
[`image`](https://crates.io/crates/image) 0.25,
[`bevy`](https://crates.io/crates/bevy) 0.14
[`image`] 0.25,
[`bevy`] 0.14
([92acaa1](https://github.com/shnewto/edges/commit/92acaa1a3be42b085bf2fe9c4e258662254edcf5)).

## [0.3.2](https://github.com/shnewto/edges/compare/0.3.1...0.3.2) - 2024-05-13
Expand All @@ -105,9 +144,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Crates to dependencies
([c508c2a](https://github.com/shnewto/edges/commit/c508c2a6816593efbeaf807e5af1e06c9f165376)):
- [`hashbrown`](https://crates.io/crates/hashbrown)
- [`mashmap`](https://crates.io/crates/mashmap)
- [`ordered-float`](https://crates.io/crates/ordered-float)
- [`hashbrown`]
- [`mashmap`]
- [`ordered-float`]

### Changed

Expand Down Expand Up @@ -151,3 +190,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Implementation of
`TryFrom<bevy::prelude::Image>`, `TryFrom<image::DynamicImage>` etc.
traits for `Edges` ([006b40c](https://github.com/shnewto/edges/commit/006b40c7ff9557dac4166b04aa8e2fee7ce1bedc)).

[`bevy`]: https://crates.io/crates/bevy
[`bevy_math`]: https://crates.io/crates/bevy_math
[`bevy_render`]: https://crates.io/crates/bevy_render
[`image`]: https://crates.io/crates/image
[`rayon`]: https://crates.io/crates/rayon
[`binary_image`]: https://crates.io/crates/binary_image
[`thiserror`]: https://crates.io/crates/thiserror
[`hashbrown`]: https://crates.io/crates/hashbrown
[`mashmap`]: https://crates.io/crates/mashmap
[`ordered-float`]: https://crates.io/crates/ordered-float
22 changes: 13 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ cast_precision_loss = { level = "allow", priority = 1 }
pedantic = { level = "warn", priority = 0 }

[features]
default = ["bevy"]
default = ["bevy", "parallel"]
glam-latest = ["dep:glam"]
bevy = ["dep:bevy_math", "dep:bevy_image"]
bevy = ["dep:bevy_math", "dep:bevy_image", "binary_image/bevy"]
parallel = ["dep:rayon"]

[dependencies]
image = "0.25"
rayon = "1"

[dependencies.glam]
version = "0.29"
optional = true
[dependencies]
binary_image = "0.5"
image = { version = "0.25", default-features = false }
rayon = { version = "1", optional = true }
glam = { version = "0.29", optional = true }

[dependencies.bevy_math]
version = "0.15"
Expand All @@ -42,13 +42,17 @@ optional = true
[dependencies.bevy_image]
version = "0.15"
default-features = false
features = ["png"]
optional = true

[dev-dependencies]
raqote = "0.8"
open = "5.1"

[dev-dependencies.bevy_image]
version = "0.15"
default-features = false
features = ["png"]

[dev-dependencies.bevy_render]
version = "0.15"
default-features = false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::path::Path;

let image = image::open(Path::new("assets/car.png"));
let edges = Edges::from(image.unwrap());
println!("{:#?}", edges.single_image_edge_translated());
println!("{:#?}", edges.single_translated());
```

## How it works
Expand Down
4 changes: 2 additions & 2 deletions examples/bevy-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main() {

fn draw_png(image: &Image, img_path: &str) {
// get the image's edges
let edges = Edges::from(image);
let edges = Edges::try_from(image).unwrap();

let scale = 8;
let (width, height) = (
Expand All @@ -57,7 +57,7 @@ fn draw_png(image: &Image, img_path: &str) {
// draw the edges to a png
let mut dt = DrawTarget::new(width, height);

let objects = edges.multi_image_edge_raw();
let objects = edges.multi_raw();

for object in objects {
let mut pb = PathBuilder::new();
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn draw_png(img_path: &str) {
let mut dt = DrawTarget::new(width, height);
let mut pb = PathBuilder::new();

let mut edges_iter = edges.single_image_edge_raw().into_iter();
let mut edges_iter = edges.single_raw().unwrap().into_iter();
let first_edge = edges_iter.next().unwrap();
pb.move_to((first_edge.x * scale) as f32, (first_edge.y * scale) as f32);
for edge in edges_iter {
Expand Down
9 changes: 9 additions & 0 deletions neighbors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def display(dir: int) -> str:
def display(expr) -> str:
return "1" if expr else "_"

return (
f"{display(dir & 1)}{display(dir & 64)}{display(dir & 2)}\n"
f"{display(dir & 16)}1{display(dir & 32)}\n"
f"{display(dir & 4)}{display(dir & 128)}{display(dir & 8)}"
)
18 changes: 18 additions & 0 deletions src/bevy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::Edges;

use bevy_image::prelude::Image as BevyImage;
use binary_image::BinaryImage;

impl TryFrom<BevyImage> for Edges<BinaryImage> {
type Error = binary_image::bevy::IntoBinaryImageError;
fn try_from(image: BevyImage) -> Result<Edges<BinaryImage>, Self::Error> {
Ok(Self(BinaryImage::try_from(image)?))
}
}

impl TryFrom<&BevyImage> for Edges<BinaryImage> {
type Error = binary_image::bevy::IntoBinaryImageError;
fn try_from(image: &BevyImage) -> Result<Edges<BinaryImage>, Self::Error> {
Ok(Edges(BinaryImage::try_from(image)?))
}
}
170 changes: 0 additions & 170 deletions src/bin_image.rs

This file was deleted.

Loading

0 comments on commit 3f5ece4

Please sign in to comment.