mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-30 04:57:54 -06:00
Merge main into feat/wiggle-paths-spatial-phase
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
//! MIT OR Apache-2.0), reworked to take and return kurbo paths directly.
|
||||
//!
|
||||
//! Inputs are closed implicitly (a filled open path is painted as if closed). The sweep splits
|
||||
//! curves at intersections and y-extrema; [`tidy_segments`] re-joins pieces that came from one
|
||||
//! curves at intersections and y-extrema; `tidy_segments` re-joins pieces that came from one
|
||||
//! input curve (exactly) or one smooth run (by least-squares refit), so results carry roughly as
|
||||
//! few vertices as the inputs. Output contours are simple and consistently oriented (holes wind
|
||||
//! opposite to their outer contour), so they fill the same under either fill rule.
|
||||
|
||||
+15
-2
@@ -144,7 +144,20 @@ pub fn ellipse(size: [f64; 2], pos: [f64; 2]) -> BezPath {
|
||||
}
|
||||
|
||||
/// Polystar: a star (`inner` radius used) or polygon, rotation in degrees, roundness in percent.
|
||||
pub fn polystar(star: bool, points: f64, pos: [f64; 2], rotation: f64, inner: f64, outer: f64, inner_round: f64, outer_round: f64) -> BezPath {
|
||||
pub struct Polystar {
|
||||
pub star: bool,
|
||||
pub points: f64,
|
||||
pub pos: [f64; 2],
|
||||
pub rotation: f64,
|
||||
pub inner: f64,
|
||||
pub outer: f64,
|
||||
pub inner_round: f64,
|
||||
pub outer_round: f64,
|
||||
}
|
||||
|
||||
/// Build the path described by the polystar's geometry.
|
||||
pub fn polystar(spec: Polystar) -> BezPath {
|
||||
let Polystar { star, points, pos, rotation, inner, outer, inner_round, outer_round } = spec;
|
||||
let n = points.max(3.0).round() as usize;
|
||||
let verts = if star { n * 2 } else { n };
|
||||
let mut path = BezPath::new();
|
||||
@@ -398,7 +411,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn star_has_right_vertex_count() {
|
||||
let p = polystar(true, 5.0, [0.0, 0.0], 0.0, 20.0, 50.0, 0.0, 0.0);
|
||||
let p = polystar(Polystar { star: true, points: 5.0, pos: [0.0, 0.0], rotation: 0.0, inner: 20.0, outer: 50.0, inner_round: 0.0, outer_round: 0.0 });
|
||||
let v = from_kurbo(&p);
|
||||
assert_eq!(v[0].vertices.len(), 10);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//! with "outside" so every contour closes.
|
||||
//! 2. **Douglas–Peucker** simplification of each closed loop to the Tolerance (pixels).
|
||||
//! 3. **Bezier fitting**: each simplified span is fitted with one cubic (least squares with fixed
|
||||
//! end tangents, Newton reparameterisation; [`crate::fit`]). The tangent at each vertex is the
|
||||
//! end tangents, Newton reparameterisation; `crate::fit`). The tangent at each vertex is the
|
||||
//! chord direction at Corner Roundness 0 (straight segments, sharp corners) and the smooth
|
||||
//! (Catmull–Rom) direction at 100 %, blended between.
|
||||
//!
|
||||
|
||||
Reference in New Issue
Block a user