diff --git a/CHANGELOG.md b/CHANGELOG.md index 7810278..fb5cd72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ You can find its changes [documented below](#0111-2024-09-12). This release has an [MSRV][] of 1.65. +### Changed + +- `Stroke` is now `PartialEq`, `StrokeOpts` is now `Clone`, `Copy`, `Debug`, `Eq`, `PartialEq`. ([#379] by [@waywardmonkeys]) + ## [0.11.1][] (2024-09-12) This release has an [MSRV][] of 1.65. @@ -75,6 +79,7 @@ Note: A changelog was not kept for or before this release [#370]: https://github.com/linebender/kurbo/pull/370 [#375]: https://github.com/linebender/kurbo/pull/375 [#376]: https://github.com/linebender/kurbo/pull/376 +[#379]: https://github.com/linebender/kurbo/pull/379 [Unreleased]: https://github.com/linebender/kurbo/compare/v0.11.1...HEAD [0.11.0]: https://github.com/linebender/kurbo/releases/tag/v0.11.0 diff --git a/src/stroke.rs b/src/stroke.rs index ad8183c..40015f3 100644 --- a/src/stroke.rs +++ b/src/stroke.rs @@ -42,7 +42,7 @@ pub enum Cap { } /// Describes the visual style of a stroke. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Stroke { @@ -63,11 +63,13 @@ pub struct Stroke { } /// Options for path stroking. +#[derive(Clone, Copy, Debug, PartialEq)] pub struct StrokeOpts { opt_level: StrokeOptLevel, } /// Optimization level for computing +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum StrokeOptLevel { /// Adaptively subdivide segments in half. Subdivide, @@ -201,10 +203,10 @@ pub fn stroke( tolerance: f64, ) -> BezPath { if style.dash_pattern.is_empty() { - stroke_undashed(path, style, tolerance, opts) + stroke_undashed(path, style, tolerance, *opts) } else { let dashed = dash(path.into_iter(), style.dash_offset, &style.dash_pattern); - stroke_undashed(dashed, style, tolerance, opts) + stroke_undashed(dashed, style, tolerance, *opts) } } @@ -213,7 +215,7 @@ fn stroke_undashed( path: impl IntoIterator, style: &Stroke, tolerance: f64, - opts: &StrokeOpts, + opts: StrokeOpts, ) -> BezPath { let mut ctx = StrokeCtx { join_thresh: 2.0 * tolerance / style.width, @@ -307,7 +309,7 @@ fn extend_reversed(out: &mut BezPath, elements: &[PathEl]) { } } -fn fit_with_opts(co: &CubicOffset, tolerance: f64, opts: &StrokeOpts) -> BezPath { +fn fit_with_opts(co: &CubicOffset, tolerance: f64, opts: StrokeOpts) -> BezPath { match opts.opt_level { StrokeOptLevel::Subdivide => fit_to_bezpath(co, tolerance), StrokeOptLevel::Optimized => fit_to_bezpath_opt(co, tolerance), @@ -428,7 +430,7 @@ impl StrokeCtx { self.last_pt = p1; } - fn do_cubic(&mut self, style: &Stroke, c: CubicBez, tolerance: f64, opts: &StrokeOpts) { + fn do_cubic(&mut self, style: &Stroke, c: CubicBez, tolerance: f64, opts: StrokeOpts) { // First, detect degenerate linear case // Ordinarily, this is the direction of the chord, but if the chord is very