Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive PartialEq for Stroke, common derives for StrokeOpts. #379

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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