Skip to content

Commit 7ccb271

Browse files
Derive PartialEq for Stroke, common derives for StrokeOpts. (#379)
As discussed in https://xi.zulipchat.com/#narrow/stream/260979-kurbo/topic/PartialEq.20for.20Stroke.3F
1 parent d948d1e commit 7ccb271

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ You can find its changes [documented below](#0111-2024-09-12).
1515

1616
This release has an [MSRV][] of 1.65.
1717

18+
### Changed
19+
20+
- `Stroke` is now `PartialEq`, `StrokeOpts` is now `Clone`, `Copy`, `Debug`, `Eq`, `PartialEq`. ([#379] by [@waywardmonkeys])
21+
1822
## [0.11.1][] (2024-09-12)
1923

2024
This release has an [MSRV][] of 1.65.
@@ -75,6 +79,7 @@ Note: A changelog was not kept for or before this release
7579
[#370]: https://github.com/linebender/kurbo/pull/370
7680
[#375]: https://github.com/linebender/kurbo/pull/375
7781
[#376]: https://github.com/linebender/kurbo/pull/376
82+
[#379]: https://github.com/linebender/kurbo/pull/379
7883

7984
[Unreleased]: https://github.com/linebender/kurbo/compare/v0.11.1...HEAD
8085
[0.11.0]: https://github.com/linebender/kurbo/releases/tag/v0.11.0

src/stroke.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum Cap {
4242
}
4343

4444
/// Describes the visual style of a stroke.
45-
#[derive(Clone, Debug)]
45+
#[derive(Clone, Debug, PartialEq)]
4646
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4747
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4848
pub struct Stroke {
@@ -63,11 +63,13 @@ pub struct Stroke {
6363
}
6464

6565
/// Options for path stroking.
66+
#[derive(Clone, Copy, Debug, PartialEq)]
6667
pub struct StrokeOpts {
6768
opt_level: StrokeOptLevel,
6869
}
6970

7071
/// Optimization level for computing
72+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7173
pub enum StrokeOptLevel {
7274
/// Adaptively subdivide segments in half.
7375
Subdivide,
@@ -201,10 +203,10 @@ pub fn stroke(
201203
tolerance: f64,
202204
) -> BezPath {
203205
if style.dash_pattern.is_empty() {
204-
stroke_undashed(path, style, tolerance, opts)
206+
stroke_undashed(path, style, tolerance, *opts)
205207
} else {
206208
let dashed = dash(path.into_iter(), style.dash_offset, &style.dash_pattern);
207-
stroke_undashed(dashed, style, tolerance, opts)
209+
stroke_undashed(dashed, style, tolerance, *opts)
208210
}
209211
}
210212

@@ -213,7 +215,7 @@ fn stroke_undashed(
213215
path: impl IntoIterator<Item = PathEl>,
214216
style: &Stroke,
215217
tolerance: f64,
216-
opts: &StrokeOpts,
218+
opts: StrokeOpts,
217219
) -> BezPath {
218220
let mut ctx = StrokeCtx {
219221
join_thresh: 2.0 * tolerance / style.width,
@@ -307,7 +309,7 @@ fn extend_reversed(out: &mut BezPath, elements: &[PathEl]) {
307309
}
308310
}
309311

310-
fn fit_with_opts(co: &CubicOffset, tolerance: f64, opts: &StrokeOpts) -> BezPath {
312+
fn fit_with_opts(co: &CubicOffset, tolerance: f64, opts: StrokeOpts) -> BezPath {
311313
match opts.opt_level {
312314
StrokeOptLevel::Subdivide => fit_to_bezpath(co, tolerance),
313315
StrokeOptLevel::Optimized => fit_to_bezpath_opt(co, tolerance),
@@ -428,7 +430,7 @@ impl StrokeCtx {
428430
self.last_pt = p1;
429431
}
430432

431-
fn do_cubic(&mut self, style: &Stroke, c: CubicBez, tolerance: f64, opts: &StrokeOpts) {
433+
fn do_cubic(&mut self, style: &Stroke, c: CubicBez, tolerance: f64, opts: StrokeOpts) {
432434
// First, detect degenerate linear case
433435

434436
// Ordinarily, this is the direction of the chord, but if the chord is very

0 commit comments

Comments
 (0)