Flare: distribute the first ring for small seeds

This commit is contained in:
dotCooCoo
2026-11-17 05:07:35 -08:00
parent 277e0f2742
commit 8f0379cc3f
4 changed files with 33 additions and 4 deletions
+9 -3
View File
@@ -53,7 +53,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Flare",
[],
None,
"{cx, cy, diameter=100, opacity=50 (%), brightness=30 (%), growth=20 (%), fuzziness=50 (%), rays=15, longest=300 (%), rayFuzziness=100 (%), rotation=0 (deg, turns the rays clockwise), x2?, y2? (ring end; else pathLength at direction), pathLength=300, rings=10, largest=50 (%), direction=45 (deg counter-clockwise from 3 o'clock: where the rings run from the centre), seed?, ringSeed? (whole number below 2^53: places the rings along the path anew, keeping their count and sizes)} → {id}",
"{cx, cy, diameter=100, opacity=50 (%), brightness=30 (%), growth=20 (%), fuzziness=50 (%), rays=15, longest=300 (%), rayFuzziness=100 (%), rotation=0 (deg, turns the rays clockwise), x2?, y2? (ring end; else pathLength at direction), pathLength=300, rings=10, largest=50 (%), direction=45 (deg counter-clockwise from 3 o'clock: where the rings run from the centre), seed?, ringSeed? (whole number below 2^53: deterministically places every ring along the path, including the first for small seed values, keeping their count and sizes)} → {id}",
has_doc,
flare
),
@@ -565,7 +565,7 @@ fn flare(s: &mut Session, p: &Value) -> Result<Value> {
None | Some(Value::Null) => Ok(None),
Some(v) => v.as_u64().map(Some).ok_or_else(|| bad("shape.flare", format!("`{key}` must be a whole number of at least 0, not {v}"))),
};
// The generator's state is odd (never 0).
// Xorshift64. Both streams start from a nonzero state.
let random = |mut state: u64| {
move || {
state ^= state << 13;
@@ -580,7 +580,13 @@ fn flare(s: &mut Session, p: &Value) -> Result<Value> {
Some(r) if r >= 1 << 53 => return Err(bad("shape.flare", format!("`ringSeed` must be below 2^53, not {r}"))),
r => r,
};
let mut ring_at = ring_seed.map(|r| random((r << 1) | 1));
let mut ring_at = ring_seed.map(|r| {
// SplitMix64 initializes the ring-position stream.
let mut z = r.wrapping_add(0x9e37_79b9_7f4a_7c15);
z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);
z = (z ^ (z >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb);
random(z ^ (z >> 31))
});
let stop = |offset: f32, opacity: f32| GradientStop { opacity, ..GradientStop::new(offset, vectorcraft_color::Color::WHITE) };
let radial = |centre: Point, radius: f64, stops: Vec<GradientStop>| {
let mut g = GradientPaint::new(Gradient::new(GradientKind::Radial, stops));
+20
View File
@@ -3313,6 +3313,26 @@ fn flare_ring_seed_moves_only_the_rings() {
assert_eq!(s.doc().unwrap().history.undo.len(), undo);
}
#[test]
fn flare_small_ring_seeds_spread_the_first_ring_along_the_path() {
let mut s = session();
let mut positions = Vec::new();
for seed in [0, 1, 2, 5, 11, (1u64 << 53) - 1] {
let p = json!({"cx": 20, "cy": 30, "x2": 1020, "y2": 30, "rays": 0, "rings": 1, "ringSeed": seed});
let id = NodeId(s.execute("shape.flare", &p).unwrap()["id"].as_u64().unwrap());
let NodeKind::Group { children, .. } = &s.doc().unwrap().doc.node(id).unwrap().kind else { panic!("flare is a group") };
let ring = children.iter().find(|n| n.name.as_deref() == Some("Ring")).unwrap();
let center = ring.geometric_bounds().unwrap().center();
assert!((20.0..=1020.0).contains(&center.x), "seed {seed}: {center:?}");
assert!((center.y - 30.0).abs() < 1e-9);
positions.push(center.x);
}
assert!((positions[0] - positions[1]).abs() > 1.0, "neighboring small seeds visibly move the first ring: {positions:?}");
let lo = positions[..5].iter().copied().fold(f64::INFINITY, f64::min);
let hi = positions[..5].iter().copied().fold(f64::NEG_INFINITY, f64::max);
assert!(hi - lo > 250.0, "small seeds spread the first ring along the path: {positions:?}");
}
/// `shape.ellipse` without `anchors`, or with 4, draws the live ellipse it always drew.
#[test]
fn ellipse_with_four_anchors_is_the_live_ellipse() {
+3 -1
View File
@@ -11508,7 +11508,9 @@ it while the drag sizes the halo: the halo's radius keeps the ratio to the point
went down, through `growth` within 0 to 300 %. Letting the key go sizes the center with the drag again, and the flare
keeps the new `growth`. While the rings' end point is placed, Up and Down Arrow add and remove rings (0 to 50; with
Rings off they do nothing), and each press of backquote (the ~ key; a pointer event's `backquote` turning true) sends a
new `ringSeed`, which moves the rings along the path and keeps their count and sizes. Each new flare starts from the
new `ringSeed`, which moves the rings along the path and keeps their count and sizes. In VectorCraft, small seed
values, including 0, distribute the first ring along the path; the same seed and parameters reproduce the same
positions. Each new flare starts from the
options' counts and growth, without a `ringSeed`. The Artboard tool's are the active artboard's Artboard Options
(dialog `artboardOptions`; the Artboard tool's active artboard while it is in use, else the window's; its `x` and `y`
are the artboard's top-left corner in document points, while the dialog shows X and Y at the reference point the
+1
View File
@@ -1129,6 +1129,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- While Alt (Option on macOS) is held, the Flare Tool Options' Cancel button reads Reset, which puts every option back to the Flare tool's default and leaves the dialog open (`ui.dialogReset`).
- An Alt-click (Option-click on macOS) with the Flare tool draws a flare centered at the click at once, without opening the Flare Tool Options, as [the help page](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf) describes for a default flare. As VectorCraft's own rules, the flare takes the tool's current options (the defaults until they are changed), Alt counts when it is held as the button goes down, a drag with Alt still draws the flare in two stages, and on the active perspective plane the flare is the one the click dialog's OK draws there (`alt_click_draws_a_flare_with_the_options_at_once`, `alt_click_draws_on_the_active_perspective_plane`, `an_alt_click_with_the_flare_tool_draws_the_flare_the_click_dialog_draws`).
- While a flare's center is dragged out, Ctrl (Command on macOS) keeps the center's size and the drag sizes the halo; while its rings' end point is placed, Up/Down Arrow add and remove rings and ~ places them anew (`shape.flare`'s `ringSeed`) ([Draw and edit flares](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/draw-shapes/draw-and-edit-flares.html); `flare_arrows_change_the_rays_then_the_rings`, `flare_tilde_places_the_rings_anew`, `flare_ctrl_keeps_the_center_and_the_drag_sizes_the_halo`).
- Flare ring placement accepts small `ringSeed` values, including 0, without concentrating the first ring at the center; the same seed and parameters reproduce the same positions. This seed mapping is VectorCraft's own (`flare_small_ring_seeds_spread_the_first_ring_along_the_path`, `flare_ring_seed_moves_only_the_rings`).
- A plain step of a number field (Up/Down or a wheel notch) goes to the next whole unit in its direction and a Ctrl/Cmd step goes to the next tenth, so 5.1 mm steps up to 6 mm and down to 5 mm (#2881). A Shift step adds or takes ten and keeps the fraction.
- In the number, text and color fields of the panels and the Control bar, Shift+Enter (Shift+Return) applies the value and keeps the field active with its value selected; a text box of several lines takes it as a line break. In a dialog, Shift+Enter applies the value and confirms the dialog, as Enter does.
- The Pattern Options panel's Name field and the name fields that a double-click opens in the Layers, Artboards and Asset Export panels take Shift+Enter (Shift+Return) the same way: it applies the name and keeps the field active with the name selected.