Skip to content

Commit

Permalink
Derive PartialEq for Stroke, common derives for StrokeOpts. (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored Sep 22, 2024
1 parent d948d1e commit 7ccb271
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/stroke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -213,7 +215,7 @@ fn stroke_undashed(
path: impl IntoIterator<Item = PathEl>,
style: &Stroke,
tolerance: f64,
opts: &StrokeOpts,
opts: StrokeOpts,
) -> BezPath {
let mut ctx = StrokeCtx {
join_thresh: 2.0 * tolerance / style.width,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7ccb271

Please sign in to comment.