Skip to content

Commit

Permalink
Updated some deps + API improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Sep 19, 2023
1 parent 35c3838 commit 3c88cac
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 172 deletions.
382 changes: 222 additions & 160 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ rosvgtree = { git = "https://github.com/abey79/resvg", branch="vsvg" }


[workspace.dependencies]
egui = "0.21.0"
eframe = { version = "0.21.3", default-features = false, features = [
egui = "0.22.0"
eframe = { version = "0.22.0", default-features = false, features = [
"accesskit",
"default_fonts",
"wgpu",
] }
wgpu = "0.16.3" # same a egui
serde = { version = "1", features = ["derive", "rc"] }
kurbo = "0.9.1"
rand = "0.8.5"
Expand Down
2 changes: 2 additions & 0 deletions vsvg-sketch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ pub mod prelude;
pub mod sketch;

pub type Result = anyhow::Result<()>;

pub use sketch::Sketch;
2 changes: 1 addition & 1 deletion vsvg-viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ kurbo.workspace = true
egui.workspace = true
eframe.workspace = true
serde.workspace = true
wgpu = "0.15.1"
wgpu.workspace = true
bytemuck = {version = "1.13.1", features = [ "derive" ]}
cgmath = "0.18.0"
anyhow.workspace = true
Expand Down
12 changes: 6 additions & 6 deletions vsvg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ arrayvec = "0.7.2"
lyon_geom = "1.0.4"
regex = "1.7.1"
lazy_static = "1.4.0"
indexmap = {version = "1.9.2", features = ["rayon"]}
indexmap = { version = "1.9.2", features = ["rayon"] }
kdtree = "0.7.0"
bitvec = "1.0.1"
time = {version="0.3.20", features = ["formatting"]}
time = { version = "0.3.20", features = ["formatting"] }

geo = { version="0.26.0", optional = true }
geo = { version = "0.26.0", optional = true }

# optional dependencies, mainly for Point interop.
egui = { workspace=true, optional = true }
glam = { version="0", optional = true }
bevy = { version="0", optional = true, default-features = false }
egui = { workspace = true, optional = true }
glam = { version = "0", optional = true }
bevy = { version = "0", optional = true, default-features = false }

[dev-dependencies]
approx = "0.5.1"
Expand Down
9 changes: 9 additions & 0 deletions vsvg/src/path/flattened_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ impl Polyline {
pub fn points_mut(&mut self) -> &mut Vec<Point> {
&mut self.0
}

#[must_use]
pub fn into_points(self) -> Vec<Point> {
self.0
}
}

impl Transforms for Polyline {
Expand Down Expand Up @@ -88,6 +93,10 @@ impl PathTrait<Polyline> for FlattenedPath {
&mut self.data
}

fn into_data(self) -> Polyline {
self.data
}

fn bounds(&self) -> kurbo::Rect {
self.data.bounds()
}
Expand Down
12 changes: 10 additions & 2 deletions vsvg/src/path/into_bezpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ impl<const N: usize> IntoBezPathTolerance for [Point; N] {
}
}

impl IntoBezPathTolerance for &Vec<Point> {
fn into_bezpath_with_tolerance(self, _tolerance: f64) -> BezPath {
points_to_bezpath(self.iter().copied())
}
}

impl IntoBezPathTolerance for &[(Point, Point)] {
fn into_bezpath_with_tolerance(self, _tolerance: f64) -> BezPath {
line_segment_to_bezpath(self.iter().copied())
Expand Down Expand Up @@ -194,7 +200,9 @@ pub mod geo_impl {
}
}

fn points_to_bezpath(points: impl IntoIterator<Item = impl Into<Point>>) -> kurbo::BezPath {
pub(crate) fn points_to_bezpath(
points: impl IntoIterator<Item = impl Into<Point>>,
) -> kurbo::BezPath {
let mut bezpath = kurbo::BezPath::new();

let mut points = points.into_iter().map(Into::into);
Expand All @@ -210,7 +218,7 @@ fn points_to_bezpath(points: impl IntoIterator<Item = impl Into<Point>>) -> kurb
bezpath
}

fn line_segment_to_bezpath(
pub(crate) fn line_segment_to_bezpath(
segments: impl IntoIterator<Item = impl Into<(Point, Point)>>,
) -> BezPath {
let segments = segments
Expand Down
2 changes: 2 additions & 0 deletions vsvg/src/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub trait PathTrait<D: PathDataTrait>: Transforms + Clone + PartialEq + std::fmt

fn data_mut(&mut self) -> &mut D;

fn into_data(self) -> D;

fn bounds(&self) -> kurbo::Rect;

fn start(&self) -> Option<Point> {
Expand Down
18 changes: 17 additions & 1 deletion vsvg/src/path/path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::{FlattenedPath, PathDataTrait, PathMetadata, PathTrait, Point, Polyline};
use crate::crop::Crop;
use crate::path::into_bezpath::{IntoBezPath, IntoBezPathTolerance};
use crate::path::into_bezpath::{
line_segment_to_bezpath, points_to_bezpath, IntoBezPath, IntoBezPathTolerance,
};
use crate::Transforms;
use kurbo::{Affine, BezPath, PathEl};
use std::cell::RefCell;
Expand Down Expand Up @@ -84,6 +86,10 @@ impl PathTrait<BezPath> for Path {
&mut self.data
}

fn into_data(self) -> BezPath {
self.data
}

fn bounds(&self) -> kurbo::Rect {
self.data.bounds()
}
Expand Down Expand Up @@ -125,6 +131,16 @@ impl Path {
}
}

#[must_use]
pub fn from_points(points: impl IntoIterator<Item = impl Into<Point>>) -> Self {
Self::from(points_to_bezpath(points))
}

#[must_use]
pub fn from_segments(points: impl IntoIterator<Item = impl Into<(Point, Point)>>) -> Self {
Self::from(line_segment_to_bezpath(points))
}

pub fn from_svg(path: &str) -> Result<Self, Box<dyn Error>> {
Ok(Self {
data: BezPath::from_svg(path)?,
Expand Down

0 comments on commit 3c88cac

Please sign in to comment.