mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-12 13:33:19 +00:00
#3145: fit width-profile outlines to cut export size
This commit is contained in:
@@ -12,6 +12,7 @@ use std::f64::consts::PI;
|
||||
|
||||
use kurbo::{BezPath, ParamCurve, ParamCurveNearest, PathEl, PathSeg, Point, Vec2};
|
||||
use vectorcraft_doc::{LineCap, LineJoin, StrokeLayer, WidthProfile};
|
||||
use vectorcraft_pathops::fit_cubics;
|
||||
|
||||
use super::{kink, segments, subpaths, tangent, unit};
|
||||
|
||||
@@ -504,11 +505,10 @@ fn cap_points(ring: &mut Vec<(Point, bool)>, c: Point, u: Vec2, v: Vec2, r0: f64
|
||||
|
||||
/// Append `pts` as a closed contour (a width outline's ring or loop), through a smooth run's
|
||||
/// points as cubic curves. Sampled as line segments, a curved, wide stroke shows the facets of
|
||||
/// its offset whenever it is magnified; the cubics keep it smooth. Every point is interpolated
|
||||
/// (so the sampled width is kept), a run whose points are collinear stays a line, and the points
|
||||
/// marked sharp — caps, miter joins, width steps and path corners — stay sharp. A rapid width
|
||||
/// change turns the offset sharply without being a corner: marking corners here rather than
|
||||
/// measuring turns keeps that turn smooth.
|
||||
/// its offset whenever it is magnified; the cubics keep it smooth. A run whose points are
|
||||
/// collinear stays a line, and the points marked sharp — caps, miter joins, width steps and path
|
||||
/// corners — stay sharp. A rapid width change turns the offset sharply without being a corner:
|
||||
/// marking corners here rather than measuring turns keeps that turn smooth.
|
||||
fn polygon(out: &mut BezPath, pts: impl Iterator<Item = (Point, bool)>, tol: f64) {
|
||||
let mut ring: Vec<(Point, bool)> = Vec::new();
|
||||
for (p, sharp) in pts {
|
||||
@@ -656,7 +656,14 @@ fn tangents(run: &[Point], cyclic: bool) -> Vec<Vec2> {
|
||||
out
|
||||
}
|
||||
|
||||
/// Append a run of points as cubics through them (or one line when they are collinear).
|
||||
/// Append a run of points as a fitted chain of cubics (or one line when they are collinear).
|
||||
///
|
||||
/// A cubic through every flattened point, as this used to emit, keeps the outline smooth but puts
|
||||
/// three coordinates per point into the file; a small, thin stroke then exports several times the
|
||||
/// path data of the same stroke without a profile. Fit a chain within the outline tolerance
|
||||
/// instead: the result is still G1 continuous and stays within `tol` of the sampled edge, but a
|
||||
/// smooth side is a few cubics rather than one per flatten step. Profile bends that need finer
|
||||
/// detail produce more cubics; straight runs stay lines.
|
||||
fn smooth_run(out: &mut BezPath, run: &[Point], cyclic: bool, tol: f64) {
|
||||
let n = run.len();
|
||||
if n < 2 {
|
||||
@@ -666,17 +673,55 @@ fn smooth_run(out: &mut BezPath, run: &[Point], cyclic: bool, tol: f64) {
|
||||
out.line_to(run[n - 1]);
|
||||
return;
|
||||
}
|
||||
let segs = if cyclic { n } else { n - 1 };
|
||||
let tans = tangents(run, cyclic);
|
||||
for i in 0..segs {
|
||||
let j = (i + 1) % n;
|
||||
let h = run[i].distance(run[j]);
|
||||
let (m0, m1) = (tans[i] * (h / 3.0), tans[j] * (h / 3.0));
|
||||
if m0.hypot() <= 1e-12 || m1.hypot() <= 1e-12 {
|
||||
out.line_to(run[j]);
|
||||
} else {
|
||||
out.curve_to(run[i] + m0, run[j] - m1, run[j]);
|
||||
let tol = tol.max(1e-6);
|
||||
// A short run is one or two profile features, not flattened path detail. Fitting it loosely
|
||||
// enough to save path data can let a handle cross the narrow side of a V; keep the
|
||||
// shape-preserving per-point cubics there.
|
||||
let segs = if cyclic { n } else { n - 1 };
|
||||
if n <= 3 {
|
||||
for i in 0..segs {
|
||||
let j = (i + 1) % n;
|
||||
let h = run[i].distance(run[j]);
|
||||
let (m0, m1) = (tans[i] * (h / 3.0), tans[j] * (h / 3.0));
|
||||
if m0.hypot() <= 1e-12 || m1.hypot() <= 1e-12 {
|
||||
out.line_to(run[j]);
|
||||
} else {
|
||||
out.curve_to(run[i] + m0, run[j] - m1, run[j]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
let unit_or = |v: Vec2, fallback: Vec2| {
|
||||
let len = v.hypot();
|
||||
if len > 1e-12 {
|
||||
v / len
|
||||
} else {
|
||||
let len = fallback.hypot();
|
||||
if len > 1e-12 { fallback / len } else { Vec2::new(1.0, 0.0) }
|
||||
}
|
||||
};
|
||||
let t0 = unit_or(tans[0], run[1] - run[0]);
|
||||
let (pts, t0, t1) = if cyclic {
|
||||
// Fit the seam too: the fit starts and arrives with the same tangent, so closing the
|
||||
// contour adds no kink.
|
||||
let mut pts = Vec::with_capacity(n + 1);
|
||||
pts.extend_from_slice(run);
|
||||
pts.push(run[0]);
|
||||
(pts, t0, t0)
|
||||
} else {
|
||||
(run.to_vec(), t0, unit_or(tans[n - 1], run[n - 1] - run[n - 2]))
|
||||
};
|
||||
// Fit tighter than the flattening tolerance: the fit's error is the whole outline's error,
|
||||
// and a least-squares fit may sit on one side of the sampled edge, which would otherwise
|
||||
// shift a profile's area visibly.
|
||||
let cubics = fit_cubics(&pts, t0, t1, tol * 0.1);
|
||||
if cubics.is_empty() {
|
||||
out.line_to(run[n - 1]);
|
||||
return;
|
||||
}
|
||||
for c in cubics {
|
||||
out.curve_to(c.p1, c.p2, c.p3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ pub(crate) fn end_tangent(c: &CubicBez) -> Vec2 {
|
||||
///
|
||||
/// `t0` is the unit tangent leaving `pts[0]`; `t1` is the unit tangent arriving at the last point
|
||||
/// (forward direction). Consecutive output cubics are G1 continuous.
|
||||
pub(crate) fn fit_cubics(pts: &[Point], t0: Vec2, t1: Vec2, tol: f64) -> Vec<CubicBez> {
|
||||
pub fn fit_cubics(pts: &[Point], t0: Vec2, t1: Vec2, tol: f64) -> Vec<CubicBez> {
|
||||
let mut out = Vec::new();
|
||||
let pts = dedup(pts);
|
||||
if pts.len() < 2 {
|
||||
|
||||
@@ -18,6 +18,7 @@ pub use edit::{
|
||||
AverageAxis, SIMPLIFY_LEVEL, SimplifyOptions, add_anchor_points, auto_simplify_level, average, join, remove_anchor, remove_redundant_points,
|
||||
simplify, simplify_level_tolerance, simplify_with, smooth, split_into_grid,
|
||||
};
|
||||
pub use fit::fit_cubics;
|
||||
pub use offset::{Cap, Join, offset_path, outline_stroke, stroke_region};
|
||||
pub use pathfinder::{FaceMerger, PathfinderOp, Region, Shape, merge_regions, pathfinder, region_at, regions};
|
||||
pub use planar::{
|
||||
|
||||
@@ -787,7 +787,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Gradients:** lossless, validated gradient params; gradients follow rotate, reflect, shear, non-uniform scale and distortions; the Gradient tool edits the fill or stroke of the active proxy, type included; an interactive on-canvas annotator (move, length/angle, rotate, add/move/delete/duplicate stops, midpoints, a stop popover, Delete and arrow keys). The Gradient panel has the Fill/Stroke proxy, a gradient-swatch dropdown with Save to Swatches, midpoint locations, Alt-drag to copy or swap stops, swatch drops on the ramp and a stop eyedropper; copied appearances and graphic styles place gradients on each target's own bounds; gradient handles snap and honour Constrain Angle. Gradient stops stay linked to global and spot swatches. Freeform gradients (points and lines) are edited on the canvas; radial gradients have an extent ellipse, an aspect handle and an off-centre focal point (SVG `fx`/`fy`, PDF two-point radials). A stroke's gradient runs within, along or across it. Object ▸ Expand turns gradients into N objects or a gradient mesh.
|
||||
With a gradient stop or a freeform gradient point selected, Alt-clicking a color swatch in the Swatches panel recolors it instead of the inactive Fill or Stroke.
|
||||
- **Freeform gradient colors in their own model:** Object ▸ Expand and Object ▸ Create Gradient Mesh (`object.mesh.create`) mix a freeform gradient's points in the color model they share: points of C50 M20 Y0 K10 give mesh points of C50 M20 Y0 K10, and RGB points keep their values in a working RGB space other than sRGB. Points in different models mix in display RGB, and a CMYK document stores the result as CMYK through the color settings. Points colored along CMYK stops (`paint.editGradient {stops}`, or a CMYK gradient switched to freeform) are CMYK, and so are a point `paint.freeform.splitLine` adds between CMYK points and a point `paint.freeform.addPoint` adds without `color` to CMYK points. Public reference: [Gradients](https://web.archive.org/web/20250714042311/https://helpx.adobe.com/illustrator/using/gradients.html) and [Meshes](https://web.archive.org/web/20250812201019/https://helpx.adobe.com/illustrator/using/meshes.html), which do not state how colors in different models mix; the rule is VectorCraft's own.
|
||||
- **Strokes:** one stroke-geometry module shared by the canvas, SVG, PDF and Outline Stroke; dotted lines (zero-length dashes draw dots or squares); arrowheads with hollow outlines, tip-on-end or extend-past-end alignment and one opacity for line and head. SVG and PDF export arrowheads, width profiles, brushes and aligned strokes exactly as the canvas draws them; Outline Stroke and the live Outline Stroke effect outline every stroke item as drawn (dashes, heads, profiles, alignment); dashes can be fitted to corners and path ends; width profiles carry through dashes, and their corners take the join. The Stroke panel edits type's character strokes, follows the stroke units (its weight presets are round values in that unit: `0.25 mm`, `0.0625 in`, `1 px`, #426; fields show four decimals in mm, cm and inches, three in points), shows mixed values blank and opens from the Control bar. A width profile library, thirty more arrowheads, and Width Point Edit with multi-select and discontinuous points. Visual bounds and clicks cover the whole painted stroke. Scale Strokes & Effects, Scale Corners and Use Preview Bounds work everywhere, and new art inherits stroke options, a graphic style or the whole last appearance. A width profile's sides run as a smooth C1 curve between the width points (a monotone cubic Hermite, Fritsch–Carlson, with the one-sided three-point PCHIP slope at the profile's ends and flat either side of a step), sampled adaptively along the path (two samples per profile segment, refined where the width bends, and leaning on dense path flattening) so straight runs draw it too; added samples offset along the source curve's exact tangent, not the flattened chord, so high zoom follows the true width; a point reshapes the curve as far as its neighbours' neighbours (their slopes depend on it), and coincident points still step.
|
||||
- **Strokes:** one stroke-geometry module shared by the canvas, SVG, PDF and Outline Stroke; dotted lines (zero-length dashes draw dots or squares); arrowheads with hollow outlines, tip-on-end or extend-past-end alignment and one opacity for line and head. SVG and PDF export arrowheads, width profiles, brushes and aligned strokes exactly as the canvas draws them; Outline Stroke and the live Outline Stroke effect outline every stroke item as drawn (dashes, heads, profiles, alignment); dashes can be fitted to corners and path ends; width profiles carry through dashes, and their corners take the join. The Stroke panel edits type's character strokes, follows the stroke units (its weight presets are round values in that unit: `0.25 mm`, `0.0625 in`, `1 px`, #426; fields show four decimals in mm, cm and inches, three in points), shows mixed values blank and opens from the Control bar. A width profile library, thirty more arrowheads, and Width Point Edit with multi-select and discontinuous points. Visual bounds and clicks cover the whole painted stroke. Scale Strokes & Effects, Scale Corners and Use Preview Bounds work everywhere, and new art inherits stroke options, a graphic style or the whole last appearance. A width profile's sides run as a smooth C1 curve between the width points (a monotone cubic Hermite, Fritsch–Carlson, with the one-sided three-point PCHIP slope at the profile's ends and flat either side of a step), sampled adaptively along the path (two samples per profile segment, refined where the width bends, and leaning on dense path flattening) so straight runs draw it too; added samples offset along the source curve's exact tangent, not the flattened chord, so high zoom follows the true width; the sampled edges are fitted with G1 cubics within a tenth of the flattening tolerance (0.001 pt at the default 0.01 pt) rather than one cubic per flatten step, so exports stay close to a uniform stroke's path data; a point reshapes the curve as far as its neighbours' neighbours (their slopes depend on it), and coincident points still step.
|
||||
- **Brushes (part of #852):** double-clicking a brush in the Brushes panel (or the panel menu's Brush Options…) opens Calligraphic Brush Options (Name; Angle, Roundness and Size, each Fixed, Random or Pressure with its Variation; live previews of the nib and of a light–heavy–light stroke) or Bristle Brush Options (Shape and the bristle sliders); OK edits the brush and every stroke painted with it. The Paintbrush records the pen pressure along each stroke (kept with the path, saved, and joined when a stroke continues a path); a Calligraphic value on Pressure goes from value − variation at the lightest pressure to value + variation at the heaviest, on the canvas and in SVG, PDF and the other exports. Brushes saved before keep their look. Scatter Brush Options (Size, Spacing, Scatter and Rotation, each Fixed, Random between two values or Pressure from the first at the lightest pressure to the second at the heaviest; Rotation relative to Page or Path), Art Brush Options (Width, Scale Proportionately, Stretch to Fit Stroke Length or Stretch Between Guides with the guides' start and end, the four Directions, Flip Along and Across) and Pattern Brush Options (Scale, Spacing, the five tiles shown, Flip Along and Across, Stretch to fit, Add space to fit or Approximate path) each have Colorization (None, Tints, Tints and Shades, Hue Shift with its Key Color picked from the art's colours) and a live stroke preview; values from files and commands are clamped to their ranges. Still to come: the Art brush's Overlap, auto-generated Pattern brush corners, new tile art picked in Pattern Brush Options, Stylus Wheel, Tilt, Bearing and Rotation, and pen pressure on macOS.
|
||||
Type in a scatter brush's art takes the brush's colorization as its paths do: Tints, Tints and Shades and Hue Shift recolor the characters' solid fills and strokes in each copy the brush draws, and Brush Options' Key Color list, whose first color is Hue Shift's default key, counts the characters' fills and their strokes wider than 0. The Brushes page states that "The colors that a scatter, art, or pattern brush paints depend on the current stroke color and the colorization method of the brush" (<https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html>) and does not mention type there; recoloring the characters' paints like the art's fills and strokes is VectorCraft's own rule. The Symbol Stainer mixes the characters' strokes of type toward the stain as it mixes their fills. Evidence: `tests::scatter_colorization_recolors_type`, `tests::art_colors_list_the_most_used_first`, `tests::stain_mixes_type_strokes_too` (vectorcraft-brush).
|
||||
Art Brush Options' Width (1% to 1000%) and Pattern Brush Options' Scale (1% to 10000%) each have a slider beside the field, over the same range in whole percents; screen readers name the slider as its row and read the field's value.
|
||||
@@ -1074,7 +1074,7 @@ applies to fills). Tests: `color::gradient::tests` (perceptual midpoint, expansi
|
||||
| 2026-10-21 | minor | Snap to Glyph (#3124) removed from View navigation missing lists and menu stubs; scores and hours unchanged at this rounding |
|
||||
| 2026-10-21 | minor | Type core: System Layout (Character panel menu, whole document, off by default) is done; scores and hours unchanged |
|
||||
| 2026-10-22 | minor | Ruby (ふりがな) for live text: `type.ruby` sets/removes a reading over a byte range, above or below (right of the column in vertical type), aligned, sized and overhanging or squeezed; saved natively, laid out with line growth, drawn on the canvas and in SVG/PDF (outlines where ruby is present); scores and hours unchanged |
|
||||
| 2026-10-23 | minor | Width-profile outlines sample adaptively: two samples per profile segment, refined where the width bends, and only where the flattened path does not already sample the width. A local 1,500-ellipse export falls to a 6.56 MB PDF (the reported main baseline is 4.5 MB, about 1.46×) and `profiled_outlines_stay_compact` guards the path-element count. Scores and estimates unchanged. |
|
||||
| 2026-10-23 | minor | Width-profile outlines sample adaptively: two samples per profile segment, refined where the width bends, and only where the flattened path does not already sample the width. The sampled edges are fitted with G1 cubics within a tenth of the flattening tolerance (0.001 pt by default) instead of one cubic per flatten step. On the reviewer's 1,500-ellipse fixture (20–200 pt ellipses, 3–12 pt weights) the PDF falls to 3.59 MB and the SVG to 6.79 MB (reported main baselines 4.48 MB and 9.30 MB, about 0.80× and 0.73×), and `profiled_outlines_stay_compact` guards the path-element count. Scores and estimates unchanged. |
|
||||
| 2026-10-21 | minor | 3D: original Standard, Diffuse, Top Left and Right lighting presets; command access, effective-setting recognition and preview/history; scores and estimates unchanged |
|
||||
| 2026-10-21 | minor | Properties: one selected clip group has Edit Clipping Path and Edit Contents at the top of the panel (public doc cited) (G1). Scores and hours unchanged. |
|
||||
| 2026-10-21 | minor | Print: the Print dialog's Media list carries the Japanese papers — JIS B4 (257 × 364 mm), JIS B5 (182 × 257 mm) and JIS B6 next to the ISO B4/B5, which keep their ISO 216 sizes, plus はがき, 往復はがき, 封筒 長形3号/長形4号/角形2号/角形3号 and 四六判; the JSON id or the dialog label names a paper, any case and spacing. Print score and hours unchanged. |
|
||||
|
||||
Reference in New Issue
Block a user