mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 11:34:27 +00:00
Merge remote-tracking branch 'upstream/main' into feat/style-neon-glow
# Conflicts: # crates/effects/src/svg_filter/defaults.rs
This commit is contained in:
@@ -666,7 +666,7 @@ fn expanding_a_reflected_symbol_instance_keeps_its_box() {
|
||||
for reset in [false, true] {
|
||||
let (mut s, inst) = turned_instance(0.0);
|
||||
s.execute("object.rotate", &json!({"angle": 150})).unwrap();
|
||||
s.execute("object.reflect", &json!({"axis": "horizontal"})).unwrap();
|
||||
s.execute("object.reflect", &json!({"axis": "horizontal", "basis": "page"})).unwrap();
|
||||
assert!(near(angle(&s, inst), -170.0), "{}", angle(&s, inst));
|
||||
if reset {
|
||||
s.execute("object.resetBoundingBox", &json!({})).unwrap();
|
||||
@@ -719,10 +719,164 @@ fn page_flips_keep_an_upright_box_upright() {
|
||||
s.execute("object.reflect", &json!({"axis": "horizontal"})).unwrap();
|
||||
assert_eq!(angle(&s, a), 0.0);
|
||||
s.execute("object.rotate", &json!({"angle": 30})).unwrap();
|
||||
// A named axis is the turned box's own: the box keeps its angle.
|
||||
s.execute("object.reflect", &json!({"axis": "vertical"})).unwrap();
|
||||
assert!(near(angle(&s, a), 30.0));
|
||||
s.execute("object.reflect", &json!({"axis": "vertical", "basis": "page"})).unwrap();
|
||||
assert!(near(angle(&s, a), -30.0));
|
||||
}
|
||||
|
||||
fn same_matrix(a: Affine, b: Affine) -> bool {
|
||||
a.as_coeffs().iter().zip(b.as_coeffs()).all(|(x, y)| near(*x, y))
|
||||
}
|
||||
|
||||
/// After a rotation, Scale and a named Reflect act along the turned bounding box until Reset
|
||||
/// Bounding Box; `basis: "page"` keeps the page's axes, and Transform Again repeats the matrix the
|
||||
/// transform applied on the page.
|
||||
#[test]
|
||||
fn scale_and_reflect_follow_the_turned_box() {
|
||||
let mut s = session();
|
||||
let a = turned_rect(&mut s);
|
||||
let page = |s: &Session, ids: &[NodeId]| s.doc().unwrap().doc.bounds_of(ids, false).unwrap();
|
||||
let c = Point::new(200.0, 200.0);
|
||||
let frame = OrientedBox { angle: 45.0, rect: Rect::ZERO };
|
||||
s.execute("object.scale", &json!({"sx": 200, "sy": 100})).unwrap();
|
||||
let b = selection_box(&s);
|
||||
assert!(near(b.angle, 45.0) && near(angle(&s, a), 45.0), "{b:?}");
|
||||
assert!(near(b.rect.width(), 200.0) && near(b.rect.height(), 50.0), "{b:?}");
|
||||
assert!(b.center().distance(c) < 1e-6, "{b:?}");
|
||||
let want = Affine::translate(c.to_vec2()) * frame.conjugate(Affine::scale_non_uniform(2.0, 1.0)) * Affine::translate(-c.to_vec2());
|
||||
let Some(LastTransform::Matrix(m, _)) = s.doc().unwrap().last_transform.clone() else { panic!("no transform to repeat") };
|
||||
assert!(same_matrix(m, want), "{m:?}");
|
||||
// The recorded step names its basis, so a replay acts in the same frame.
|
||||
let steps = s.journal_for_action(0);
|
||||
assert!(steps.iter().any(|(id, p)| id == "object.scale" && p["basis"] == "box"), "{steps:?}");
|
||||
|
||||
// Reflected across the box's vertical axis through its left side: the box keeps its angle and
|
||||
// size, and its centre moves a width to the left along the box.
|
||||
let left = b.reference_point(3);
|
||||
s.execute("object.reflect", &json!({"axis": "vertical", "origin": [left.x, left.y]})).unwrap();
|
||||
let r = selection_box(&s);
|
||||
let moved = c + (frame.to_doc() * Point::new(-200.0, 0.0)).to_vec2();
|
||||
assert!(near(r.angle, 45.0) && near(r.rect.width(), 200.0) && near(r.rect.height(), 50.0), "{r:?}");
|
||||
assert!(r.center().distance(moved) < 1e-6, "{r:?}");
|
||||
// Across its horizontal axis through its centre: the box stays where it is.
|
||||
s.execute("object.reflect", &json!({"axis": "horizontal"})).unwrap();
|
||||
assert!(selection_box(&s).center().distance(moved) < 1e-6 && near(angle(&s, a), 45.0));
|
||||
|
||||
// Unknown bases are errors and change nothing.
|
||||
let n = undo_len(&s);
|
||||
assert!(s.execute("object.scale", &json!({"sx": 50, "basis": "turned"})).is_err());
|
||||
assert!(s.execute("object.reflect", &json!({"axis": "vertical", "basis": 1})).is_err());
|
||||
assert!(s.execute("object.reflect", &json!({"axis": 30, "basis": "turned"})).is_err());
|
||||
assert_eq!(undo_len(&s), n);
|
||||
|
||||
// On the page's axes, the box no longer stands at 45°.
|
||||
s.execute("object.scale", &json!({"sx": 50, "sy": 100, "basis": "page"})).unwrap();
|
||||
assert!(!near(angle(&s, a), 45.0));
|
||||
// Transform Again repeats the page matrix after Reset Bounding Box too.
|
||||
s.execute("object.scale", &json!({"sx": 200, "sy": 100})).unwrap();
|
||||
let Some(LastTransform::Matrix(m, _)) = s.doc().unwrap().last_transform.clone() else { panic!("no transform to repeat") };
|
||||
s.execute("object.resetBoundingBox", &json!({})).unwrap();
|
||||
let before = s.doc().unwrap().doc.node(a).unwrap().clone();
|
||||
s.execute("object.transformAgain", &json!({})).unwrap();
|
||||
let mut want = before;
|
||||
want.transform(m, false);
|
||||
let (got, want) = (page(&s, &[a]), want.geometric_bounds_with(&s.doc().unwrap().doc.symbol_boxes()).unwrap());
|
||||
assert!([got.x0 - want.x0, got.y0 - want.y0, got.x1 - want.x1, got.y1 - want.y1].iter().all(|d| d.abs() < 1e-6), "{got:?} {want:?}");
|
||||
}
|
||||
|
||||
/// A saved step without `basis` was recorded before Scale and Reflect followed the turned box, so a
|
||||
/// replay of it acts along the page's axes, as it did then, and its new journal entry says so. A
|
||||
/// step recorded now names its basis and replays along the box. A call without `basis` that is not
|
||||
/// a replay acts along the box.
|
||||
#[test]
|
||||
fn saved_steps_without_a_basis_replay_on_the_page() {
|
||||
// The turned rectangle after `run` runs on it: its page bounds and its box's angle.
|
||||
let after = |run: &dyn Fn(&mut Session)| {
|
||||
let mut s = session();
|
||||
let a = turned_rect(&mut s);
|
||||
run(&mut s);
|
||||
let st = (s.doc().unwrap().doc.bounds_of(&[a], false).unwrap(), angle(&s, a));
|
||||
(st, s.journal.last().unwrap().clone())
|
||||
};
|
||||
let same = |(r, a): (Rect, f64), (q, b): (Rect, f64)| [r.x0 - q.x0, r.y0 - q.y0, r.x1 - q.x1, r.y1 - q.y1, a - b].iter().all(|d| d.abs() < 1e-6);
|
||||
for (id, p) in [("object.scale", json!({"sx": 200, "sy": 100})), ("object.reflect", json!({"axis": "vertical"}))] {
|
||||
let mut on_page = p.clone();
|
||||
on_page["basis"] = json!("page");
|
||||
let (page, _) = after(&|s| {
|
||||
s.execute(id, &on_page).unwrap();
|
||||
});
|
||||
let (old, (_, noted)) = after(&|s| {
|
||||
s.replay(id, &p).unwrap();
|
||||
});
|
||||
assert!(same(old, page), "{id}: {old:?} {page:?}");
|
||||
assert_eq!(noted["basis"], "page", "{id}");
|
||||
|
||||
let (boxed, (recorded_id, recorded)) = after(&|s| {
|
||||
s.execute(id, &p).unwrap();
|
||||
});
|
||||
assert!(!same(boxed, page) && near(boxed.1, 45.0), "{id}: {boxed:?}");
|
||||
assert_eq!(recorded["basis"], "box", "{id}");
|
||||
let (replayed, _) = after(&|s| {
|
||||
s.replay(&recorded_id, &recorded).unwrap();
|
||||
});
|
||||
assert!(same(replayed, boxed), "{id}: {replayed:?} {boxed:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Once Reset Bounding Box squares the box, and for objects standing at different angles, Scale
|
||||
/// acts along the page's axes.
|
||||
#[test]
|
||||
fn scale_follows_the_page_after_a_reset_and_for_mixed_angles() {
|
||||
let mut s = session();
|
||||
let a = turned_rect(&mut s);
|
||||
s.execute("object.resetBoundingBox", &json!({})).unwrap();
|
||||
let page = |s: &Session, ids: &[NodeId]| s.doc().unwrap().doc.bounds_of(ids, false).unwrap();
|
||||
let w = page(&s, &[a]);
|
||||
s.execute("object.scale", &json!({"sx": 200, "sy": 100})).unwrap();
|
||||
let r = page(&s, &[a]);
|
||||
assert!(near(r.width(), 2.0 * w.width()) && near(r.height(), w.height()), "{w:?} {r:?}");
|
||||
assert_eq!(angle(&s, a), 0.0);
|
||||
// A turned rectangle with an upright one: the box is square to the page.
|
||||
let b = turned_rect(&mut s);
|
||||
let u = rect(&mut s, 400.0, 100.0, 50.0, 50.0);
|
||||
sel(&mut s, &[b, u]);
|
||||
let w = page(&s, &[b, u]);
|
||||
s.execute("object.scale", &json!({"sx": 100, "sy": 200})).unwrap();
|
||||
let r = page(&s, &[b, u]);
|
||||
assert!(near(r.width(), w.width()) && near(r.height(), 2.0 * w.height()), "{w:?} {r:?}");
|
||||
}
|
||||
|
||||
/// With anchors selected, Scale and a named Reflect move the anchors along the page's axes, but
|
||||
/// with Transform Objects off they move the whole objects' pattern tiles, along the turned box.
|
||||
#[test]
|
||||
fn pattern_only_transforms_of_selected_anchors_follow_the_turned_box() {
|
||||
let c = Point::new(200.0, 200.0);
|
||||
let frame = OrientedBox { angle: 45.0, rect: Rect::ZERO };
|
||||
let about = |m: Affine| Affine::translate(c.to_vec2()) * m * Affine::translate(-c.to_vec2());
|
||||
let last = |s: &Session| match s.doc().unwrap().last_transform.clone() {
|
||||
Some(LastTransform::Matrix(m, _)) => m,
|
||||
other => panic!("no matrix to repeat: {other:?}"),
|
||||
};
|
||||
let scale = Affine::scale_non_uniform(2.0, 1.0);
|
||||
let flip = Affine::scale_non_uniform(-1.0, 1.0);
|
||||
for (cmd, p, m) in [("object.scale", json!({"sx": 200, "sy": 100}), scale), ("object.reflect", json!({"axis": "vertical"}), flip)] {
|
||||
for objects in [false, true] {
|
||||
let mut s = session();
|
||||
let a = turned_rect(&mut s);
|
||||
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 0]], "mode": "set"})).unwrap();
|
||||
let mut p = p.clone();
|
||||
p["origin"] = json!([c.x, c.y]);
|
||||
p["objects"] = json!(objects);
|
||||
p["patterns"] = json!(true);
|
||||
s.execute(cmd, &p).unwrap();
|
||||
let want = if objects { about(m) } else { about(frame.conjugate(m)) };
|
||||
assert!(same_matrix(last(&s), want), "{cmd} objects {objects}: {:?}", last(&s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn groups_type_and_multiple_selections_keep_their_angle() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_color::{BlendMode, Color, Paint};
|
||||
use vectorcraft_doc::appearance::{Effect, FillLayer, StrokeLayer};
|
||||
use vectorcraft_doc::{AppearanceItem, ImageBlob, ImageObject, LineCap, LineJoin, Node, NodeKind};
|
||||
use vectorcraft_geom::{Affine, FillRule, PathData, Point, Rect};
|
||||
use vectorcraft_testkit::pdf::{PdfPage, pdf};
|
||||
@@ -2684,6 +2685,401 @@ fn live_paint_make_and_expand_keep_abutting_compound_colors() {
|
||||
check_colors(&node(&s, group));
|
||||
}
|
||||
|
||||
/// Gives `id` the appearance rows `items` (paint order) and returns them.
|
||||
fn set_rows(s: &mut Session, id: NodeId, items: Vec<AppearanceItem>) -> Vec<AppearanceItem> {
|
||||
s.edit("t", |d, _| {
|
||||
d.node_mut(id).unwrap().appearance = vectorcraft_doc::Appearance { items: items.clone(), ..Default::default() }.into();
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
items
|
||||
}
|
||||
|
||||
/// A fill row of `p`, changed by `f`.
|
||||
fn fill_row(p: Paint, f: impl FnOnce(&mut FillLayer)) -> AppearanceItem {
|
||||
let mut l = FillLayer::new(p);
|
||||
f(&mut l);
|
||||
AppearanceItem::Fill(l)
|
||||
}
|
||||
|
||||
/// A stroke row of `p` `width` wide, changed by `f`.
|
||||
fn stroke_row(p: Paint, width: f64, f: impl FnOnce(&mut StrokeLayer)) -> AppearanceItem {
|
||||
let mut l = StrokeLayer::new(p, width);
|
||||
f(&mut l);
|
||||
AppearanceItem::Stroke(l)
|
||||
}
|
||||
|
||||
/// The faces and edges of Live Paint group `g` whose bounds lie within x `x0`..`x1`.
|
||||
fn parts_within(s: &Session, g: NodeId, x0: f64, x1: f64) -> (Vec<Node>, Vec<Node>) {
|
||||
let n = node(s, g);
|
||||
let within = |c: &&Arc<Node>| c.geometric_bounds().is_some_and(|b| b.x0 >= x0 - 1e-6 && b.x1 <= x1 + 1e-6);
|
||||
let faces = vectorcraft_tools::builder::faces(&n).into_iter().filter(within).map(|c| (**c).clone()).collect();
|
||||
let edges = vectorcraft_tools::builder::edges(&n).into_iter().filter(within).map(|c| (**c).clone()).collect();
|
||||
(faces, edges)
|
||||
}
|
||||
|
||||
/// Make gives each edge every stroke row of its source that draws, a lower one under an
|
||||
/// unpainted or hidden top row included, with the rows' settings and the source's opacity and
|
||||
/// blending mode; rows that draw nothing stay only with the stored source, which Release returns.
|
||||
#[test]
|
||||
fn live_paint_make_keeps_lower_drawn_stroke_rows() {
|
||||
let mut s = session();
|
||||
let (a, b) = two_at(&mut s, 200.0);
|
||||
let black = Paint::solid(Color::BLACK);
|
||||
let green = Paint::solid(Color::rgb(0.0, 1.0, 0.0));
|
||||
let thick = stroke_row(black.clone(), 3.0, |l| {
|
||||
l.opacity = 0.5;
|
||||
l.blend = BlendMode::Multiply;
|
||||
l.cap = LineCap::Round;
|
||||
});
|
||||
// A: the top stroke has no paint.
|
||||
let a_rows =
|
||||
set_rows(&mut s, a, vec![fill_row(Paint::solid(Color::rgb(1.0, 0.0, 0.0)), |_| {}), thick.clone(), stroke_row(Paint::None, 1.0, |_| {})]);
|
||||
// B: the top stroke is hidden; a zero-weight and a transparent stroke draw nothing either.
|
||||
set_rows(
|
||||
&mut s,
|
||||
b,
|
||||
vec![
|
||||
stroke_row(green.clone(), 2.0, |_| {}),
|
||||
stroke_row(black.clone(), 0.0, |_| {}),
|
||||
stroke_row(black, 2.0, |l| l.opacity = 0.0),
|
||||
stroke_row(Paint::solid(Color::rgb(0.0, 0.0, 1.0)), 5.0, |l| l.visible = false),
|
||||
],
|
||||
);
|
||||
s.edit("t", |d, _| {
|
||||
let n = d.node_mut(a).unwrap();
|
||||
n.opacity = 0.75;
|
||||
n.blend = BlendMode::Screen;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let (_, a_edges) = parts_within(&s, g, 0.0, 100.0);
|
||||
let (_, b_edges) = parts_within(&s, g, 200.0, 300.0);
|
||||
assert!(!a_edges.is_empty() && !b_edges.is_empty());
|
||||
for e in &a_edges {
|
||||
assert_eq!(e.appearance.items, vec![thick.clone()], "A's edge takes the stroke that draws");
|
||||
assert_eq!((e.opacity, e.blend), (0.75, BlendMode::Screen));
|
||||
}
|
||||
for e in &b_edges {
|
||||
assert_eq!(e.appearance.items, vec![stroke_row(green.clone(), 2.0, |_| {})], "B's edge takes only its green stroke");
|
||||
assert_eq!((e.opacity, e.blend), (1.0, BlendMode::Normal));
|
||||
}
|
||||
// Release returns the sources with every row they had.
|
||||
let released = ids(&s.execute("livePaint.release", &json!({})).unwrap());
|
||||
assert!(released.contains(&a));
|
||||
assert_eq!(node(&s, a).appearance.items, a_rows);
|
||||
}
|
||||
|
||||
/// When Make cuts a dashed stroke with arrowheads, a width profile and a brush into edges, each
|
||||
/// edge's dashes go on from where it starts along the path, the arrowheads stay at the path's own
|
||||
/// ends, and the profile and brush, which spread over the whole path, are left off the pieces.
|
||||
#[test]
|
||||
fn live_paint_make_fits_dashes_and_arrowheads_to_each_edge() {
|
||||
use vectorcraft_doc::{Arrowhead, Dash};
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
|
||||
let l = line(&mut s, (-20.0, 50.0), (120.0, 50.0));
|
||||
let dash = Dash { pattern: vec![10.0, 5.0], offset: 2.0, align_corners: true };
|
||||
let row = stroke_row(Paint::solid(Color::BLACK), 2.0, |st| {
|
||||
st.dash = Some(dash.clone());
|
||||
st.start_arrow = Some(Arrowhead::Triangle);
|
||||
st.end_arrow = Some(Arrowhead::Circle);
|
||||
st.brush = Some("Charcoal".into());
|
||||
});
|
||||
let rows = set_rows(&mut s, l, vec![row]);
|
||||
s.execute("select.set", &json!({"ids": [a.0, l.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let gn = node(&s, g);
|
||||
let mut pieces: Vec<(f64, f64, vectorcraft_doc::StrokeLayer)> = vectorcraft_tools::builder::edges(&gn)
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
let st = e.appearance.stroke().filter(|st| st.dash.is_some())?.clone();
|
||||
let sp = e.path_data()?.subpaths.first()?;
|
||||
Some((sp.anchors.first()?.p.x, sp.anchors.last()?.p.x, st))
|
||||
})
|
||||
.collect();
|
||||
pieces.sort_by(|p, q| p.0.total_cmp(&q.0));
|
||||
let ends: Vec<(f64, f64)> = pieces.iter().map(|p| ((p.0 * 1e3).round() / 1e3, (p.1 * 1e3).round() / 1e3)).collect();
|
||||
assert_eq!(ends, vec![(-20.0, 0.0), (0.0, 100.0), (100.0, 120.0)], "each piece runs the way the line does");
|
||||
let offsets: Vec<f64> = pieces.iter().map(|p| (p.2.dash.as_ref().unwrap().offset * 1e3).round() / 1e3).collect();
|
||||
assert_eq!(offsets, vec![2.0, 22.0, 122.0], "the dashes go on along the line");
|
||||
assert!(pieces.iter().all(|p| !p.2.dash.as_ref().unwrap().align_corners && p.2.brush.is_none()));
|
||||
let arrows: Vec<_> = pieces.iter().map(|p| (p.2.start_arrow.clone(), p.2.end_arrow.clone())).collect();
|
||||
assert_eq!(arrows, vec![(Some(Arrowhead::Triangle), None), (None, None), (None, Some(Arrowhead::Circle))]);
|
||||
// A path that crosses itself: the pieces that start at the crossing take their place on the
|
||||
// path from where they run, not from the first time the path passes that point.
|
||||
let mut s3 = session();
|
||||
let anchors = [(0.0, 0.0), (100.0, 100.0), (100.0, 0.0), (0.0, 100.0)].map(|(x, y)| json!({"x": x, "y": y}));
|
||||
let z = NodeId(s3.execute("path.create", &json!({"anchors": anchors, "closed": false})).unwrap()["id"].as_u64().unwrap());
|
||||
set_rows(&mut s3, z, rows.clone());
|
||||
s3.execute("select.set", &json!({"ids": [z.0]})).unwrap();
|
||||
let g3 = NodeId(s3.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let mut cut: Vec<(f64, Option<Arrowhead>, Option<Arrowhead>)> = vectorcraft_tools::builder::edges(&node(&s3, g3))
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
let st = e.appearance.stroke()?;
|
||||
Some(((st.dash.as_ref()?.offset * 1e3).round() / 1e3, st.start_arrow.clone(), st.end_arrow.clone()))
|
||||
})
|
||||
.collect();
|
||||
cut.sort_by(|p, q| p.0.total_cmp(&q.0));
|
||||
let d = 2.0 + 50.0 * 2f64.sqrt();
|
||||
let r = |v: f64| (v * 1e3).round() / 1e3;
|
||||
assert_eq!(
|
||||
cut,
|
||||
vec![(2.0, Some(Arrowhead::Triangle), None), (r(d), None, None), (r(d + 100.0 + 100.0 * 2f64.sqrt()), None, Some(Arrowhead::Circle))]
|
||||
);
|
||||
// An uncut path keeps all of it.
|
||||
let mut s2 = session();
|
||||
let l2 = line(&mut s2, (0.0, 0.0), (50.0, 0.0));
|
||||
set_rows(&mut s2, l2, rows.clone());
|
||||
s2.execute("select.set", &json!({"ids": [l2.0]})).unwrap();
|
||||
let g2 = NodeId(s2.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let edges: Vec<_> = vectorcraft_tools::builder::edges(&node(&s2, g2)).iter().map(|e| e.appearance.items.clone()).collect();
|
||||
assert_eq!(edges, vec![rows]);
|
||||
}
|
||||
|
||||
/// When Gap Options or Merge cuts an edge in two, each piece keeps the edge's dashes going on from
|
||||
/// where it starts along the edge, an arrowhead only at the end of the edge it ends at, and no brush.
|
||||
#[test]
|
||||
fn live_paint_gap_options_and_merge_fit_an_edge_look_to_each_piece() {
|
||||
use vectorcraft_doc::{Arrowhead, Dash};
|
||||
let mut s = session();
|
||||
let l = line(&mut s, (0.0, 50.0), (100.0, 50.0));
|
||||
let stub = line(&mut s, (50.0, 0.0), (50.0, 48.0));
|
||||
let row = stroke_row(Paint::solid(Color::BLACK), 2.0, |st| {
|
||||
st.dash = Some(Dash { pattern: vec![10.0, 5.0], offset: 2.0, align_corners: false });
|
||||
st.start_arrow = Some(Arrowhead::Triangle);
|
||||
st.end_arrow = Some(Arrowhead::Circle);
|
||||
st.brush = Some("Charcoal".into());
|
||||
});
|
||||
let rows = set_rows(&mut s, l, vec![row]);
|
||||
s.execute("select.set", &json!({"ids": [l.0, stub.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let dashed = |s: &Session, g: NodeId| {
|
||||
let mut out: Vec<(f64, f64, vectorcraft_doc::StrokeLayer)> = vectorcraft_tools::builder::edges(&node(s, g))
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
let st = e.appearance.stroke().filter(|st| st.dash.is_some())?.clone();
|
||||
let sp = e.path_data()?.subpaths.first()?;
|
||||
Some(((sp.anchors.first()?.p.x * 1e3).round() / 1e3, (sp.anchors.last()?.p.x * 1e3).round() / 1e3, st))
|
||||
})
|
||||
.collect();
|
||||
out.sort_by(|p, q| p.0.total_cmp(&q.0));
|
||||
out
|
||||
};
|
||||
let before = dashed(&s, g);
|
||||
assert_eq!(before.len(), 1, "nothing cuts the line yet");
|
||||
assert_eq!(vec![AppearanceItem::Stroke(before[0].2.clone())], rows);
|
||||
let r = s.execute("livePaint.gapOptions", &json!({"id": g.0, "closeGaps": true})).unwrap();
|
||||
assert_eq!(r["closed"], json!(1));
|
||||
let pieces = dashed(&s, g);
|
||||
let ends: Vec<(f64, f64)> = pieces.iter().map(|p| (p.0, p.1)).collect();
|
||||
assert_eq!(ends, vec![(0.0, 50.0), (50.0, 100.0)], "the line is cut where the gap closes");
|
||||
let offsets: Vec<f64> = pieces.iter().map(|p| (p.2.dash.as_ref().unwrap().offset * 1e3).round() / 1e3).collect();
|
||||
assert_eq!(offsets, vec![2.0, 52.0], "the dashes go on along the line");
|
||||
let arrows: Vec<_> = pieces.iter().map(|p| (p.2.start_arrow.clone(), p.2.end_arrow.clone())).collect();
|
||||
assert_eq!(arrows, vec![(Some(Arrowhead::Triangle), None), (None, Some(Arrowhead::Circle))]);
|
||||
assert!(pieces.iter().all(|p| p.2.brush.is_none()), "a brush spreads over the whole line");
|
||||
// Merge: the piece of the edge that an added path cuts off, which takes the edge's look, gets
|
||||
// it fitted to where it lies along the edge in the same way.
|
||||
let mut s = session();
|
||||
let l = line(&mut s, (0.0, 50.0), (100.0, 50.0));
|
||||
set_rows(&mut s, l, rows.clone());
|
||||
s.execute("select.set", &json!({"ids": [l.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let cut = line(&mut s, (25.0, 0.0), (25.0, 100.0));
|
||||
s.execute("livePaint.merge", &json!({"ids": [g.0, cut.0]})).unwrap();
|
||||
let pieces = dashed(&s, g);
|
||||
let ends: Vec<(f64, f64)> = pieces.iter().map(|p| (p.0, p.1)).collect();
|
||||
assert_eq!(ends, vec![(0.0, 25.0), (25.0, 100.0)], "the added line cuts the edge");
|
||||
let offsets: Vec<f64> = pieces.iter().map(|p| (p.2.dash.as_ref().unwrap().offset * 1e3).round() / 1e3).collect();
|
||||
assert_eq!(offsets, vec![2.0, 27.0], "the dashes go on along the line");
|
||||
let arrows: Vec<_> = pieces.iter().map(|p| (p.2.start_arrow.clone(), p.2.end_arrow.clone())).collect();
|
||||
assert_eq!(arrows, vec![(Some(Arrowhead::Triangle), None), (None, Some(Arrowhead::Circle))]);
|
||||
assert!(pieces.iter().all(|p| p.2.brush.is_none()), "a brush spreads over the whole line");
|
||||
// A repainted edge that Merge cuts keeps its paint on every piece.
|
||||
let mut s = session();
|
||||
let l = line(&mut s, (0.0, 50.0), (100.0, 50.0));
|
||||
s.execute("select.set", &json!({"ids": [l.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [50, 50], "color": "#ff0000", "width": 3})).unwrap();
|
||||
let cut = line(&mut s, (50.0, 0.0), (50.0, 100.0));
|
||||
s.execute("livePaint.merge", &json!({"ids": [g.0, cut.0]})).unwrap();
|
||||
let gn = node(&s, g);
|
||||
let red = Paint::solid(Color::from_hex("#ff0000").unwrap());
|
||||
let mut on_line: Vec<(f64, bool)> = vectorcraft_tools::builder::edges(&gn)
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
let sp = e.path_data()?.subpaths.first()?;
|
||||
let (a, z) = (sp.anchors.first()?.p, sp.anchors.last()?.p);
|
||||
((a.y - 50.0).abs() < 1e-6 && (z.y - 50.0).abs() < 1e-6)
|
||||
.then(|| ((a.x.min(z.x) * 1e3).round() / 1e3, e.appearance.stroke().is_some_and(|st| st.paint == red)))
|
||||
})
|
||||
.collect();
|
||||
on_line.sort_by(|p, q| p.0.total_cmp(&q.0));
|
||||
assert_eq!(on_line, vec![(0.0, true), (50.0, true)], "both pieces keep the edge's paint");
|
||||
}
|
||||
|
||||
/// The edge Make builds from a closed path that nothing cuts starts at the anchor the path starts
|
||||
/// at and runs the way the path does, whichever anchor that is, so its dashes and brush lie where
|
||||
/// they do on the path, and it keeps the path's stroke row as it is.
|
||||
#[test]
|
||||
fn live_paint_make_starts_a_closed_edge_where_its_path_starts() {
|
||||
use vectorcraft_doc::Dash;
|
||||
let corners = [(50.0, 0.0), (100.0, 50.0), (50.0, 100.0), (0.0, 50.0)];
|
||||
for clockwise in [true, false] {
|
||||
for start in 0..4 {
|
||||
let mut s = session();
|
||||
let mut pts: Vec<(f64, f64)> = (0..4).map(|k| corners[(k + start) % 4]).collect();
|
||||
if !clockwise {
|
||||
pts.reverse();
|
||||
}
|
||||
let anchors: Vec<_> = pts.iter().map(|(x, y)| json!({"x": x, "y": y})).collect();
|
||||
let z = NodeId(s.execute("path.create", &json!({"anchors": anchors, "closed": true})).unwrap()["id"].as_u64().unwrap());
|
||||
let row = stroke_row(Paint::solid(Color::BLACK), 2.0, |st| {
|
||||
st.dash = Some(Dash { pattern: vec![10.0, 5.0], offset: 2.0, align_corners: false });
|
||||
st.brush = Some("Charcoal".into());
|
||||
});
|
||||
let rows = set_rows(&mut s, z, vec![row]);
|
||||
s.execute("select.set", &json!({"ids": [z.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let gn = node(&s, g);
|
||||
let edges = vectorcraft_tools::builder::edges(&gn);
|
||||
let [e] = edges.as_slice() else { panic!("one edge, got {}", edges.len()) };
|
||||
let sp = e.path_data().unwrap().subpaths.first().unwrap().clone();
|
||||
let at: Vec<(f64, f64)> = sp.anchors.iter().map(|a| ((a.p.x * 1e3).round() / 1e3, (a.p.y * 1e3).round() / 1e3)).collect();
|
||||
assert!(sp.closed);
|
||||
assert_eq!(at, pts, "clockwise {clockwise}, start {start}");
|
||||
assert_eq!(e.appearance.items, rows, "clockwise {clockwise}, start {start}");
|
||||
}
|
||||
}
|
||||
// A closed path that crosses itself is cut into loops, and the loop that holds the path's
|
||||
// first anchor is still only part of the path: it keeps no brush.
|
||||
let mut s = session();
|
||||
let anchors = [(0.0, 0.0), (100.0, 100.0), (100.0, 0.0), (0.0, 100.0)].map(|(x, y)| json!({"x": x, "y": y}));
|
||||
let z = NodeId(s.execute("path.create", &json!({"anchors": anchors, "closed": true})).unwrap()["id"].as_u64().unwrap());
|
||||
let row = stroke_row(Paint::solid(Color::BLACK), 2.0, |st| {
|
||||
st.dash = Some(Dash { pattern: vec![10.0, 5.0], offset: 2.0, align_corners: false });
|
||||
st.brush = Some("Charcoal".into());
|
||||
});
|
||||
set_rows(&mut s, z, vec![row]);
|
||||
s.execute("select.set", &json!({"ids": [z.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let gn = node(&s, g);
|
||||
let edges = vectorcraft_tools::builder::edges(&gn);
|
||||
assert!(edges.len() > 1, "the crossing cuts the path, got {} edge", edges.len());
|
||||
assert!(edges.iter().all(|e| e.appearance.stroke().is_some_and(|st| st.brush.is_none())), "no loop is the whole path");
|
||||
}
|
||||
|
||||
/// When Make cuts a stroke whose only setting that depends on direction is a gradient along or
|
||||
/// across it, each edge runs the way its source path does, so the gradient keeps its direction.
|
||||
#[test]
|
||||
fn live_paint_make_keeps_the_direction_of_gradient_strokes() {
|
||||
use vectorcraft_doc::StrokeGradientMode;
|
||||
for mode in [StrokeGradientMode::Along, StrokeGradientMode::Across] {
|
||||
for (x0, x1) in [(-20.0, 120.0), (120.0, -20.0)] {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
|
||||
let l = line(&mut s, (x0, 50.0), (x1, 50.0));
|
||||
let gradient = Paint::Gradient(Box::new(vectorcraft_color::GradientPaint::new(vectorcraft_color::Gradient::default())));
|
||||
set_rows(&mut s, l, vec![stroke_row(gradient, 2.0, |st| st.gradient_mode = mode)]);
|
||||
s.execute("select.set", &json!({"ids": [a.0, l.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let pieces: Vec<(f64, f64)> = vectorcraft_tools::builder::edges(&node(&s, g))
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
e.appearance.stroke().filter(|st| st.gradient_mode == mode)?;
|
||||
let sp = e.path_data()?.subpaths.first()?;
|
||||
Some((sp.anchors.first()?.p.x, sp.anchors.last()?.p.x))
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(pieces.len(), 3, "{mode:?}, from {x0}");
|
||||
assert!(
|
||||
pieces.iter().all(|&(p, q)| (q - p).signum() == (x1 - x0).signum()),
|
||||
"{mode:?}, from {x0}: each piece runs the way the line does: {pieces:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Make gives each face every fill row of its source that draws, in order and with their
|
||||
/// opacity, blending mode, overprint and effects, and the source's gradients keep their fit on
|
||||
/// the source; Expand keeps the rows, and Undo and Redo bring the group back with them.
|
||||
#[test]
|
||||
fn live_paint_make_keeps_all_drawn_fill_rows_and_attributes() {
|
||||
let mut s = session();
|
||||
let (a, b) = two(&mut s);
|
||||
let lower = fill_row(Paint::solid(Color::rgb(1.0, 0.0, 0.0)), |l| {
|
||||
l.opacity = 0.4;
|
||||
l.blend = BlendMode::Multiply;
|
||||
l.overprint = true;
|
||||
l.effects.push(Effect { id: "distort.roughen".into(), params: Value::Null, visible: true });
|
||||
});
|
||||
// A: two fills that draw, with a hidden one between them and an unpainted one above them.
|
||||
set_rows(
|
||||
&mut s,
|
||||
a,
|
||||
vec![
|
||||
lower.clone(),
|
||||
fill_row(Paint::solid(Color::rgb(0.0, 1.0, 0.0)), |l| l.visible = false),
|
||||
fill_row(Paint::None, |_| {}),
|
||||
stroke_row(Paint::None, 1.0, |_| {}),
|
||||
],
|
||||
);
|
||||
// The top fill (and the stroke) become a gradient fitted to A's bounds.
|
||||
let (want_fill, _) = paint_with_gradients(&mut s, a);
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let want = vec![lower, fill_row(want_fill, |_| {})];
|
||||
let rows_within = |s: &Session, x0: f64, x1: f64| parts_within(s, g, x0, x1).0.iter().map(|f| f.appearance.items.clone()).collect::<Vec<_>>();
|
||||
assert_eq!(rows_within(&s, 0.0, 50.0), vec![want.clone()], "A's face takes both fills that draw, the gradient at its fit on A");
|
||||
let blue = vec![fill_row(Paint::solid(Color::rgb(0.0, 0.0, 1.0)), |_| {})];
|
||||
assert_eq!(rows_within(&s, 50.0, 100.0), vec![blue], "B is in front");
|
||||
s.execute("livePaint.expand", &json!({})).unwrap();
|
||||
let expanded = node(&s, g);
|
||||
assert!(!vectorcraft_tools::builder::is_live_paint(&expanded));
|
||||
let kept =
|
||||
expanded.children().unwrap().iter().filter(|c| c.geometric_bounds().is_some_and(|b| b.x1 <= 50.0 + 1e-6)).any(|c| c.appearance.items == want);
|
||||
assert!(kept, "Expand keeps both fills");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(rows_within(&s, 0.0, 50.0), vec![want.clone()]);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
assert_eq!(rows_within(&s, 0.0, 50.0), vec![want]);
|
||||
}
|
||||
|
||||
/// A face takes the fill rows of the front-most covering source whose fill draws: a source in
|
||||
/// front whose fill is hidden or transparent, or whose opacity is 0, does not hide the paint of the
|
||||
/// source behind it, and a face that no such source covers has no paint.
|
||||
#[test]
|
||||
fn live_paint_make_uses_frontmost_source_with_drawn_fill() {
|
||||
for front in ["hidden", "clear", "transparent object"] {
|
||||
let mut s = session();
|
||||
let (a, b) = two(&mut s);
|
||||
s.edit("t", |d, _| {
|
||||
let n = d.node_mut(b).unwrap();
|
||||
let mut app = (*n.appearance).clone();
|
||||
match front {
|
||||
"hidden" => app.fill_mut().unwrap().visible = false,
|
||||
"clear" => app.fill_mut().unwrap().opacity = 0.0,
|
||||
_ => n.opacity = 0.0,
|
||||
}
|
||||
n.appearance = app.into();
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let rows_within = |x0: f64, x1: f64| parts_within(&s, g, x0, x1).0.iter().map(|f| f.appearance.items.clone()).collect::<Vec<_>>();
|
||||
let red = vec![fill_row(Paint::solid(Color::rgb(1.0, 0.0, 0.0)), |_| {})];
|
||||
assert_eq!(rows_within(50.0, 100.0), vec![red], "{front}: the overlap shows A");
|
||||
assert_eq!(rows_within(100.0, 150.0), vec![vec![fill_row(Paint::None, |_| {})]], "{front}: B alone paints nothing");
|
||||
assert_eq!(parts_within(&s, g, 100.0, 150.0).0[0].opacity, 1.0, "{front}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_fill_assigns_the_face_under_the_point() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -219,9 +219,10 @@ fn rotate_reflect_and_scale_carry_unplaced_gradients() {
|
||||
s.execute("object.rotate", &json!({"angle": 90})).unwrap();
|
||||
let g = fill_geom(&s, id);
|
||||
assert!((g.end.x - g.start.x).abs() < 1e-9 && (g.length() - 100.0).abs() < 1e-9, "vertical after a 90° turn: {g:?}");
|
||||
s.execute("object.reflect", &json!({"axis": "horizontal"})).unwrap();
|
||||
s.execute("object.reflect", &json!({"axis": "horizontal", "basis": "page"})).unwrap();
|
||||
let r = fill_geom(&s, id);
|
||||
// The vertical vector is centred on the object, so the reflection swaps its ends.
|
||||
// The vertical vector is centred on the object, so the reflection across the page's
|
||||
// horizontal axis swaps its ends.
|
||||
assert!(r.start.distance(g.end) < 1e-9 && r.end.distance(g.start) < 1e-9, "{g:?} → {r:?}");
|
||||
|
||||
// A circle's radial gradient becomes an ellipse under a non-uniform scale.
|
||||
|
||||
@@ -406,7 +406,7 @@ fn a_batch_step_records_what_it_took_from_the_preferences() {
|
||||
]);
|
||||
s.execute("command.batch", &json!({ "commands": steps })).unwrap();
|
||||
let p = &s.journal.last().unwrap().1;
|
||||
assert_eq!(p["commands"][2]["params"], json!({"sx": 300, "strokes": true, "corners": false}));
|
||||
assert_eq!(p["commands"][2]["params"], json!({"sx": 300, "strokes": true, "corners": false, "basis": "box"}));
|
||||
// Replayed with other preferences, the scale still scales the stroke.
|
||||
let r = replayed(&s);
|
||||
assert!(!r.prefs.scale_strokes);
|
||||
|
||||
@@ -1700,6 +1700,7 @@ fn filters_set_effects_and_stroke_styles() {
|
||||
("test.engine.badn", json!([{"id": "plugin.test.engine.fx", "params": {"n": "two"}}]), "`n`"),
|
||||
("test.engine.file", json!([{"id": "distort.glass", "params": {"textureImage": {"path": "/etc/hosts"}}}]), "textureImage"),
|
||||
("test.engine.file2", json!([{"id": "texture.texturizer", "params": {"textureImage": {"path": "/etc/hosts"}}}]), "textureImage"),
|
||||
("test.engine.file3", json!([{"id": "artistic.roughPastels", "params": {"textureImage": {"path": "/etc/hosts"}}}]), "textureImage"),
|
||||
("test.engine.two3d", json!([{"id": "threeD.extrude"}, {"id": "threeD.extrude"}]), "one 3D effect"),
|
||||
] {
|
||||
let e = filter(&mut s, name, fx).unwrap_err().to_string();
|
||||
|
||||
@@ -323,8 +323,7 @@ fn glass_loads_a_texture_saves_it_and_draws_it() {
|
||||
assert_eq!(doc.node(NodeId(g)).unwrap().appearance.effects[0].params, glass_params(&s, g));
|
||||
assert_eq!(Renderer::new().render_region(&doc, Rect::new(0.0, 0.0, 200.0, 200.0), 1.0, true).pixels, loaded.pixels);
|
||||
// The same file by path, through Effect Options, stores the same texture.
|
||||
let dir = std::env::temp_dir().join(format!("vc-glass-texture-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let dir = vectorcraft_testkit::TempDir::new("glass-texture");
|
||||
let path = dir.join("rings.png");
|
||||
std::fs::write(&path, &png).unwrap();
|
||||
let (mut t, h) = striped();
|
||||
@@ -334,7 +333,7 @@ fn glass_loads_a_texture_saves_it_and_draws_it() {
|
||||
assert_eq!(glass_params(&t, h)["textureImage"], json!(stored));
|
||||
assert_eq!(glass_params(&t, h)["texture"], json!("loaded"));
|
||||
assert_eq!(render(&t).pixels, loaded.pixels);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
drop(dir);
|
||||
// The stored string is taken as it is (as effect.list gives it, and a graphic style copies it).
|
||||
t.execute("effect.apply", &json!({"effect": "distort.glass", "ids": [h], "params": {"textureImage": stored, "texture": "frosted"}})).unwrap();
|
||||
let second = t.doc().unwrap().doc.node(NodeId(h)).unwrap().appearance.effects[1].params.clone();
|
||||
@@ -391,6 +390,53 @@ fn texturizer_loads_a_texture_and_draws_it() {
|
||||
assert_eq!(Renderer::new().render_region(&doc, Rect::new(0.0, 0.0, 200.0, 200.0), 1.0, true).pixels, loaded.pixels);
|
||||
}
|
||||
|
||||
/// Effect › Artistic › Rough Pastels › Load Texture: an image file, given as bytes or by path, is
|
||||
/// stored with the effect and picked; it draws as the surface, a save and open keeps it, a file
|
||||
/// that isn't an image is refused without a change, and undo takes it away.
|
||||
#[test]
|
||||
fn rough_pastels_loads_a_texture_saves_it_and_draws_it() {
|
||||
let png = rings_png();
|
||||
let data = vectorcraft_format::base64_encode(&png);
|
||||
let (mut s, g) = striped();
|
||||
let file = json!({"name": "rings.png", "dataBase64": data});
|
||||
s.execute("effect.apply", &json!({"effect": "artistic.roughPastels", "ids": [g], "params": {"relief": 20, "textureImage": file}})).unwrap();
|
||||
let p = glass_params(&s, g);
|
||||
assert_eq!(p["texture"], json!("loaded"), "loading a texture picks it");
|
||||
let stored = p["textureImage"].as_str().unwrap().to_string();
|
||||
assert_eq!(vectorcraft_render::effects::pixel::texture(&stored).unwrap().size(), (12, 10));
|
||||
let loaded = render(&s);
|
||||
for (_, builtin) in vectorcraft_render::effects::pixel::TEXTURES {
|
||||
s.execute("effect.setParams", &json!({"index": 0, "ids": [g], "params": {"texture": builtin}})).unwrap();
|
||||
assert!(mean_diff(&loaded, &render(&s)) > 0.001, "{builtin}");
|
||||
}
|
||||
s.execute("effect.setParams", &json!({"index": 0, "ids": [g], "params": {"texture": "loaded"}})).unwrap();
|
||||
assert_eq!(render(&s).pixels, loaded.pixels, "the texture stayed with the effect");
|
||||
let doc = vectorcraft_format::load(&vectorcraft_format::save(&s.doc().unwrap().doc, false)).unwrap();
|
||||
assert_eq!(doc.node(NodeId(g)).unwrap().appearance.effects[0].params, glass_params(&s, g));
|
||||
assert_eq!(Renderer::new().render_region(&doc, Rect::new(0.0, 0.0, 200.0, 200.0), 1.0, true).pixels, loaded.pixels);
|
||||
// A file that isn't an image changes nothing.
|
||||
let junk = vectorcraft_format::base64_encode(b"not an image");
|
||||
let before = glass_params(&s, g);
|
||||
let e = s.execute("effect.setParams", &json!({"index": 0, "ids": [g], "params": {"textureImage": {"dataBase64": junk}}})).unwrap_err();
|
||||
assert!(e.to_string().contains("textureImage"), "{e}");
|
||||
let e = s.execute("effect.setParams", &json!({"index": 0, "ids": [g], "params": {"textureImage": 5}})).unwrap_err();
|
||||
assert!(e.to_string().contains("textureImage"), "{e}");
|
||||
assert_eq!(glass_params(&s, g), before);
|
||||
// The same file by path, through Effect Options, stores the same texture; undo takes it away.
|
||||
let dir = vectorcraft_testkit::TempDir::new("rough-pastels-texture");
|
||||
let path = dir.join("rings.png");
|
||||
std::fs::write(&path, &png).unwrap();
|
||||
let (mut t, h) = striped();
|
||||
t.execute("effect.apply", &json!({"effect": "artistic.roughPastels", "ids": [h], "params": {"relief": 20}})).unwrap();
|
||||
assert!(glass_params(&t, h).get("textureImage").is_none());
|
||||
t.execute("effect.setParams", &json!({"index": 0, "ids": [h], "params": {"textureImage": {"path": path.to_string_lossy()}}})).unwrap();
|
||||
drop(dir);
|
||||
assert_eq!((&glass_params(&t, h)["textureImage"], &glass_params(&t, h)["texture"]), (&json!(stored), &json!("loaded")));
|
||||
assert_eq!(render(&t).pixels, loaded.pixels);
|
||||
t.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!(glass_params(&t, h).get("textureImage").is_none(), "undone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spin_blur_reaches_past_the_corners() {
|
||||
let (mut s, g) = striped();
|
||||
|
||||
@@ -216,7 +216,7 @@ fn the_journal_records_the_scale_options_used() {
|
||||
run(&mut s, "object.scale", json!({"sx": 150}));
|
||||
let (cmd, p) = s.journal.last().unwrap().clone();
|
||||
assert_eq!(cmd, "object.scale");
|
||||
assert_eq!(p, json!({"sx": 150, "strokes": false, "corners": true}));
|
||||
assert_eq!(p, json!({"sx": 150, "strokes": false, "corners": true, "basis": "box"}));
|
||||
// An explicit value stays; moves don't scale, so they record nothing.
|
||||
run(&mut s, "object.scale", json!({"sx": 150, "strokes": true}));
|
||||
assert_eq!(s.journal.last().unwrap().1["strokes"], json!(true));
|
||||
|
||||
Reference in New Issue
Block a user