diff --git a/CHANGELOG.md b/CHANGELOG.md index 839d33fb..1de3c6cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This release has an [MSRV][] of 1.65. - Move `Self: Sized` bound from `Shape` to methods. ([#340] by [@waywardmonkeys]) - Enable partial SVG path support in `no_std` builds. ([#356] by [@waywardmonkeys]) +- Deprecate `BezPath::flatten`, prefer `flatten`. ([#361] by [@waywardmonkeys]) ### Fixed @@ -51,6 +52,7 @@ Note: A changelog was not kept for or before this release [#347]: https://github.com/linebender/kurbo/pull/347 [#354]: https://github.com/linebender/kurbo/pull/354 [#356]: https://github.com/linebender/kurbo/pull/356 +[#361]: https://github.com/linebender/kurbo/pull/361 [Unreleased]: https://github.com/linebender/kurbo/compare/v0.11.0...HEAD [0.11.0]: https://github.com/linebender/kurbo/releases/tag/v0.11.0 diff --git a/src/bezpath.rs b/src/bezpath.rs index baa943d8..c5139bf9 100644 --- a/src/bezpath.rs +++ b/src/bezpath.rs @@ -95,7 +95,7 @@ use crate::common::FloatFuncs; /// [A Primer on Bézier Curves]: https://pomax.github.io/bezierinfo/ /// [`iter`]: BezPath::iter /// [`segments`]: BezPath::segments -/// [`flatten`]: BezPath::flatten +/// [`flatten`]: flatten /// [`intersect_line`]: PathSeg::intersect_line /// [`segments` free function]: segments /// [`FromIterator`]: std::iter::FromIterator @@ -290,72 +290,8 @@ impl BezPath { /// Flatten the path, invoking the callback repeatedly. /// - /// Flattening is the action of approximating a curve with a succession of line segments. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// The tolerance value controls the maximum distance between the curved input - /// segments and their polyline approximations. (In technical terms, this is the - /// Hausdorff distance). The algorithm attempts to bound this distance between - /// by `tolerance` but this is not absolutely guaranteed. The appropriate value - /// depends on the use, but for antialiased rendering, a value of 0.25 has been - /// determined to give good results. The number of segments tends to scale as the - /// inverse square root of tolerance. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// The callback will be called in order with each element of the generated - /// path. Because the result is made of polylines, these will be straight-line - /// path elements only, no curves. - /// - /// This algorithm is based on the blog post [Flattening quadratic Béziers] - /// but with some refinements. For one, there is a more careful approximation - /// at cusps. For two, the algorithm is extended to work with cubic Béziers - /// as well, by first subdividing into quadratics and then computing the - /// subdivision of each quadratic. However, as a clever trick, these quadratics - /// are subdivided fractionally, and their endpoints are not included. - /// - /// TODO: write a paper explaining this in more detail. - /// - /// Note: the [`flatten`] function provides the same - /// functionality but works with slices and other [`PathEl`] iterators. - /// - /// [Flattening quadratic Béziers]: https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html + /// See [`flatten`] for more discussion. + #[deprecated(since = "0.11.1", note = "use the free function flatten instead")] pub fn flatten(&self, tolerance: f64, callback: impl FnMut(PathEl)) { flatten(self, tolerance, callback); } @@ -551,9 +487,69 @@ const TO_QUAD_TOL: f64 = 0.1; /// Flatten the path, invoking the callback repeatedly. /// -/// See [`BezPath::flatten`] for more discussion. -/// This signature is a bit more general, allowing flattening of `&[PathEl]` slices -/// and other iterators yielding `PathEl`. +/// Flattening is the action of approximating a curve with a succession of line segments. +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// The tolerance value controls the maximum distance between the curved input +/// segments and their polyline approximations. (In technical terms, this is the +/// Hausdorff distance). The algorithm attempts to bound this distance between +/// by `tolerance` but this is not absolutely guaranteed. The appropriate value +/// depends on the use, but for antialiased rendering, a value of 0.25 has been +/// determined to give good results. The number of segments tends to scale as the +/// inverse square root of tolerance. +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// The callback will be called in order with each element of the generated +/// path. Because the result is made of polylines, these will be straight-line +/// path elements only, no curves. +/// +/// This algorithm is based on the blog post [Flattening quadratic Béziers] +/// but with some refinements. For one, there is a more careful approximation +/// at cusps. For two, the algorithm is extended to work with cubic Béziers +/// as well, by first subdividing into quadratics and then computing the +/// subdivision of each quadratic. However, as a clever trick, these quadratics +/// are subdivided fractionally, and their endpoints are not included. +/// +/// TODO: write a paper explaining this in more detail. +/// +/// [Flattening quadratic Béziers]: https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html pub fn flatten( path: impl IntoIterator, tolerance: f64,