mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 11:45:55 +00:00
Merge pull request #9409 from dotCooCoo/fix/selection-marks-skip-view-hidden-members
Selection: leave out guides and templates hidden by the view
This commit is contained in:
@@ -131,6 +131,13 @@ impl Node {
|
||||
matches!(self.kind, NodeKind::Layer { template: true, .. })
|
||||
}
|
||||
|
||||
/// Whether a view that hides template layers (`templates`) or guides (`guides`) leaves this
|
||||
/// object out: a template layer while templates are hidden, or a path made into a guide while
|
||||
/// guides are hidden. The canvas draws ruler guides apart from the art.
|
||||
pub fn hidden_by_view(&self, templates: bool, guides: bool) -> bool {
|
||||
(templates && self.is_template()) || (guides && matches!(self.kind, NodeKind::Path { guide: true, .. }))
|
||||
}
|
||||
|
||||
/// The art objects of this container: its children, looking through sublayers, which are not
|
||||
/// objects (bottom first). With `editable`, only the visible, unlocked objects in visible,
|
||||
/// unlocked, non-template sublayers.
|
||||
@@ -360,17 +367,32 @@ impl Node {
|
||||
self.geometric(Some(symbols))
|
||||
}
|
||||
|
||||
/// Children that contribute to a container's editing bounds and selection highlights. A live trace retains a
|
||||
/// hidden bitmap for re-tracing/release; only source-image views measure that bitmap.
|
||||
/// Children that contribute to a container's editing bounds. A live trace retains a hidden bitmap for
|
||||
/// re-tracing/release; only source-image views measure that bitmap. Selection highlights outline
|
||||
/// [`Node::drawn_children`].
|
||||
pub fn editing_children(&self) -> &[Arc<Node>] {
|
||||
let children = self.children().map(Vec::as_slice).unwrap_or_default();
|
||||
let trace_source = self.extras().trace.is_some()
|
||||
&& !self.trace_view().shows_source()
|
||||
&& children.first().is_some_and(|n| !n.visible && matches!(n.kind, NodeKind::Image(_)));
|
||||
let trace_source = !self.trace_view().shows_source() && self.trace_source().is_some_and(|n| !n.visible);
|
||||
let skip = usize::from(self.extras().shaper.is_some() || trace_source);
|
||||
children.get(skip..).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The children a selection highlight outlines: [`Node::editing_children`] without the hidden
|
||||
/// members, which the canvas does not draw. An Image Trace object's hidden source image stays
|
||||
/// when the object's view shows it, and every path of a compound path stays, since the compound
|
||||
/// path draws all of them.
|
||||
pub fn drawn_children(&self) -> impl Iterator<Item = &Arc<Node>> {
|
||||
let members = !matches!(self.kind, NodeKind::Compound { .. });
|
||||
let source = self.trace_source().filter(|_| self.trace_view().shows_source());
|
||||
self.editing_children().iter().filter(move |c| !members || c.visible || source.is_some_and(|s| Arc::ptr_eq(s, c)))
|
||||
}
|
||||
|
||||
/// The first child of an Image Trace object when it is an image: the bitmap the trace keeps.
|
||||
fn trace_source(&self) -> Option<&Arc<Node>> {
|
||||
self.extras().trace.as_ref()?;
|
||||
self.children()?.first().filter(|n| matches!(n.kind, NodeKind::Image(_)))
|
||||
}
|
||||
|
||||
/// The box of [`Node::geometric_bounds`], or of [`Node::geometric_bounds_with`] when `symbols`
|
||||
/// is given.
|
||||
pub(crate) fn geometric(&self, symbols: Option<&SymbolBoxes>) -> Option<Rect> {
|
||||
|
||||
@@ -112,9 +112,7 @@ pub(crate) fn holds_instance(n: &Node) -> bool {
|
||||
/// guide the view hides, a ruler guide (the canvas draws those), drawn hidden, or the instance its
|
||||
/// symbol is being edited from?
|
||||
pub(crate) fn left_out(opts: &crate::RenderOptions, doc: &vectorcraft_doc::Document, a: &Node) -> bool {
|
||||
let view_item = a.is_ruler_guide()
|
||||
|| (opts.skip_templates || opts.hide_templates) && matches!(a.kind, NodeKind::Layer { template: true, .. })
|
||||
|| (opts.skip_templates || opts.hide_guides) && matches!(a.kind, NodeKind::Path { guide: true, .. });
|
||||
let view_item = a.is_ruler_guide() || a.hidden_by_view(opts.skip_templates || opts.hide_templates, opts.skip_templates || opts.hide_guides);
|
||||
!a.visible || view_item || opts.hidden.contains(&a.id) || edited_instance(opts, doc, a.id)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,36 @@ pub(super) fn c32(rgb: [u8; 3]) -> Color32 {
|
||||
Color32::from_rgb(rgb[0], rgb[1], rgb[2])
|
||||
}
|
||||
|
||||
/// What the view hides among a selected object's members, which the selection marks leave out as
|
||||
/// the canvas does ([`Node::hidden_by_view`]): template layers while View › Hide Template is on,
|
||||
/// and paths made into guides while the guides are hidden. The default hides nothing.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub(super) struct ViewHides {
|
||||
pub(super) templates: bool,
|
||||
pub(super) guides: bool,
|
||||
}
|
||||
|
||||
impl ViewHides {
|
||||
/// What `app`'s view hides.
|
||||
pub(super) fn of(app: &VectorcraftApp) -> Self {
|
||||
Self { templates: !app.ui.view.templates, guides: !app.ui.view.guides_shown() }
|
||||
}
|
||||
|
||||
/// [`Node::drawn_children`] of `n` without the members the view leaves out. Every path of a
|
||||
/// compound path stays, since the compound path draws all of them, guides or not.
|
||||
fn children(self, n: &Node) -> impl Iterator<Item = &std::sync::Arc<Node>> {
|
||||
let hide_guides = self.guides && !matches!(n.kind, NodeKind::Compound { .. });
|
||||
n.drawn_children().filter(move |c| !c.hidden_by_view(self.templates, hide_guides))
|
||||
}
|
||||
}
|
||||
|
||||
/// Outline of a node for highlighting (paths, compound children, area type frames, image bounds,
|
||||
/// the box as drawn of type in perspective and of symbol instances, whose art `symbols` measures
|
||||
/// ([`Node::drawn_corners`]); a clip group's clipping path only, as [`walk_drawn`] visits it).
|
||||
pub(super) fn node_outline(n: &Node, symbols: &SymbolBoxes) -> BezPath {
|
||||
/// ([`Node::drawn_corners`]); a clip group's clipping path only, as [`walk_drawn`] visits it,
|
||||
/// without the members `hides` leaves out).
|
||||
pub(super) fn node_outline(n: &Node, symbols: &SymbolBoxes, hides: ViewHides) -> BezPath {
|
||||
let mut bp = BezPath::new();
|
||||
walk_drawn(n, &mut |c| match &c.kind {
|
||||
walk_drawn(n, hides, &mut |c| match &c.kind {
|
||||
NodeKind::Path { path, .. } => bp.extend(path.to_bezpath()),
|
||||
// Area type shows its frame: the type area Direct Selection reshapes; type on a path its
|
||||
// path, which the selection tools' brackets sit on; point type shows its baseline(s).
|
||||
@@ -31,9 +55,10 @@ pub(super) fn node_outline(n: &Node, symbols: &SymbolBoxes) -> BezPath {
|
||||
corners(&mut bp, q);
|
||||
}
|
||||
}
|
||||
// An image shows its frame, turned or distorted with it.
|
||||
NodeKind::Image(_) => {
|
||||
if let Some(b) = c.geometric_bounds_with(symbols) {
|
||||
bp.extend(vectorcraft_geom::shapes::rectangle(b).to_bezpath());
|
||||
if let Some(frame) = c.image_frame() {
|
||||
bp.extend(frame);
|
||||
}
|
||||
}
|
||||
// A symbol instance shows its art's box, turned, skewed or in perspective with it.
|
||||
@@ -62,6 +87,38 @@ pub(super) fn node_outline(n: &Node, symbols: &SymbolBoxes) -> BezPath {
|
||||
bp
|
||||
}
|
||||
|
||||
/// Whether `n` is a linked image or a placed document, which the selection marks cross.
|
||||
fn is_linked(n: &Node) -> bool {
|
||||
match &n.kind {
|
||||
NodeKind::Image(im) => im.link.is_some(),
|
||||
NodeKind::PlacedDocument(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The lines that cross each linked image and placed document of `n` that [`walk_drawn`] visits,
|
||||
/// from corner to corner of its frame or box (#9080), without the members `hides` leaves out. The
|
||||
/// selection marks draw them; the hover highlight does not.
|
||||
pub(super) fn linked_crosses(n: &Node, hides: ViewHides) -> BezPath {
|
||||
let mut bp = BezPath::new();
|
||||
walk_drawn(n, hides, &mut |c| match &c.kind {
|
||||
NodeKind::Image(_) if is_linked(c) => {
|
||||
if let Some(cross) = c.image_cross() {
|
||||
bp.extend(cross);
|
||||
}
|
||||
}
|
||||
NodeKind::PlacedDocument(p) => {
|
||||
let [tl, tr, br, bl] = p.corners();
|
||||
bp.move_to(tl);
|
||||
bp.line_to(br);
|
||||
bp.move_to(tr);
|
||||
bp.line_to(bl);
|
||||
}
|
||||
_ => {}
|
||||
});
|
||||
bp
|
||||
}
|
||||
|
||||
/// Adds the closed outline through the four corners `q` to `bp`.
|
||||
fn corners(bp: &mut BezPath, q: [Point; 4]) {
|
||||
let [a, b, c, d] = q;
|
||||
@@ -77,22 +134,36 @@ fn corners(bp: &mut BezPath, q: [Point; 4]) {
|
||||
/// #2460).
|
||||
pub(super) const OVERLAY_MAX_ANCHORS: usize = 100_000;
|
||||
|
||||
/// Whether `nodes` have more than [`OVERLAY_MAX_ANCHORS`] points to outline ([`overlay_points`];
|
||||
/// counting stops there).
|
||||
pub(super) fn too_many_anchors<'a>(nodes: impl IntoIterator<Item = &'a Node>) -> bool {
|
||||
fn over(n: &Node, left: &mut usize) -> bool {
|
||||
match left.checked_sub(overlay_points(n)) {
|
||||
/// Whether `nodes` have more than [`OVERLAY_MAX_ANCHORS`] points to outline ([`overlay_points`],
|
||||
/// without the members `hides` leaves out; counting stops there).
|
||||
pub(super) fn too_many_anchors<'a>(nodes: impl IntoIterator<Item = &'a Node>, hides: ViewHides) -> bool {
|
||||
over_limit(nodes, false, hides)
|
||||
}
|
||||
|
||||
/// Whether `nodes` have more than [`OVERLAY_MAX_ANCHORS`] points to outline and to cross where they
|
||||
/// are linked images or placed documents ([`linked_crosses`]), as the selection marks draw them
|
||||
/// without the members `hides` leaves out.
|
||||
pub(super) fn too_many_marks<'a>(nodes: impl IntoIterator<Item = &'a Node>, hides: ViewHides) -> bool {
|
||||
over_limit(nodes, true, hides)
|
||||
}
|
||||
|
||||
/// Whether `nodes` have more than [`OVERLAY_MAX_ANCHORS`] points ([`overlay_points`], with the
|
||||
/// ends of the crossing lines when `crosses`) in what [`walk_drawn`] visits; counting stops there.
|
||||
fn over_limit<'a>(nodes: impl IntoIterator<Item = &'a Node>, crosses: bool, hides: ViewHides) -> bool {
|
||||
fn over(n: &Node, left: &mut usize, crosses: bool, hides: ViewHides) -> bool {
|
||||
let ends = if crosses && is_linked(n) { 4 } else { 0 };
|
||||
match left.checked_sub(overlay_points(n) + ends) {
|
||||
Some(l) => *left = l,
|
||||
None => return true,
|
||||
}
|
||||
// A clip group counts only its clipping path, the one child `walk_drawn` visits.
|
||||
if n.clips() {
|
||||
return n.children().and_then(|children| children.first()).is_some_and(|clip| over(clip, left));
|
||||
return n.children().and_then(|children| children.first()).is_some_and(|clip| over(clip, left, crosses, hides));
|
||||
}
|
||||
!matches!(n.kind, NodeKind::Envelope { .. }) && n.editing_children().iter().any(|c| over(c, left))
|
||||
!matches!(n.kind, NodeKind::Envelope { .. }) && hides.children(n).any(|c| over(c, left, crosses, hides))
|
||||
}
|
||||
let mut left = OVERLAY_MAX_ANCHORS;
|
||||
nodes.into_iter().any(|n| over(n, &mut left))
|
||||
nodes.into_iter().any(|n| over(n, &mut left, crosses, hides))
|
||||
}
|
||||
|
||||
/// The points counted for `n` itself, without its children, toward [`OVERLAY_MAX_ANCHORS`]: a
|
||||
@@ -120,21 +191,22 @@ fn overlay_points(n: &Node) -> usize {
|
||||
}
|
||||
|
||||
/// [`Node::walk`] over what a selection highlight shows: an envelope's content is left out (the
|
||||
/// envelope shows its mesh instead), and a clip group or clipping layer shows only its clipping
|
||||
/// path, its first child, not the art the path clips (#2422).
|
||||
pub(super) fn walk_drawn<'a>(n: &'a Node, f: &mut impl FnMut(&'a Node)) {
|
||||
/// envelope shows its mesh instead), a clip group or clipping layer shows only its clipping path,
|
||||
/// its first child, not the art the path clips (#2422), and hidden members
|
||||
/// ([`Node::drawn_children`]) and the members `hides` leaves out are left out.
|
||||
pub(super) fn walk_drawn<'a>(n: &'a Node, hides: ViewHides, f: &mut impl FnMut(&'a Node)) {
|
||||
f(n);
|
||||
if matches!(n.kind, NodeKind::Envelope { .. }) {
|
||||
return;
|
||||
}
|
||||
if n.clips() {
|
||||
if let Some(clip) = n.children().and_then(|children| children.first()) {
|
||||
walk_drawn(clip, f);
|
||||
walk_drawn(clip, hides, f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for c in n.editing_children().iter() {
|
||||
walk_drawn(c, f);
|
||||
for c in hides.children(n) {
|
||||
walk_drawn(c, hides, f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -798,6 +798,69 @@ fn other_panes_draw_their_guides_and_selected_objects() {
|
||||
assert!(!crate::canvas::selection::outlines(&app, st).is_empty(), "the selected rectangle is outlined in its pane");
|
||||
}
|
||||
|
||||
/// Another pane crosses a selected linked image from corner to corner, as the current pane does, and outlines a
|
||||
/// selected embedded image alone (#9080).
|
||||
#[test]
|
||||
fn other_panes_cross_a_selected_linked_image() {
|
||||
use craft_image_codecs::{ChannelLayout, EncodeOptions, Format, Image, SampleType};
|
||||
let png = vectorcraft_testkit::temp_dir("panes-linked-image").join("red.png");
|
||||
let image = Image::from_raw(40, 40, ChannelLayout::Rgba, SampleType::U8, [200u8, 40, 40, 255].repeat(40 * 40)).unwrap();
|
||||
std::fs::write(&png, craft_image_codecs::encode(&image, Format::Png, &EncodeOptions::default()).unwrap()).unwrap();
|
||||
let mut app = app_with(2);
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
let mut place = |link: bool, at: [f64; 2]| {
|
||||
app.session.execute("file.place", &json!({"path": png, "link": link, "at": at})).unwrap()["ids"][0].as_u64().unwrap()
|
||||
};
|
||||
let (linked, embedded) = (place(true, [100.0, 100.0]), place(false, [250.0, 100.0]));
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// How many paths the first document's pane outlines with `id` selected there.
|
||||
let mut paths = |id: u64| {
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
app.session.execute("select.set", &json!({"ids": [id]})).unwrap();
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let st = &app.session.documents()[0];
|
||||
crate::canvas::selection::outlines(&app, st).iter().map(|o| o.paths.len()).sum::<usize>()
|
||||
};
|
||||
let (linked, embedded) = (paths(linked), paths(embedded));
|
||||
assert_eq!((linked, embedded), (2, 1), "the outline of a linked image and its crossing lines; an embedded image's outline alone");
|
||||
}
|
||||
|
||||
/// Another pane outlines a selected group's visible members only: hiding a member draws the same outlines as deleting
|
||||
/// it.
|
||||
#[test]
|
||||
fn other_panes_leave_out_a_selected_groups_hidden_members() {
|
||||
let mut app = app_with(2);
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
let id = |made: serde_json::Value| made["id"].as_u64().unwrap();
|
||||
let shown = id(app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 100, "height": 80})).unwrap());
|
||||
let hidden = id(app.run("shape.ellipse", json!({"x": 200, "y": 100, "width": 90, "height": 60})).unwrap());
|
||||
app.run("select.set", json!({"ids": [shown, hidden]})).unwrap();
|
||||
let group = id(app.run("object.group", json!({})).unwrap());
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// The paths the first document's pane outlines with the group selected there, after the commands `edit` there.
|
||||
let outlines = |app: &mut VectorcraftApp, edit: &[(&str, serde_json::Value)]| {
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
for (command, params) in edit {
|
||||
app.run(command, params.clone()).unwrap();
|
||||
}
|
||||
app.run("select.set", json!({"ids": [group]})).unwrap();
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
frame(app, &ctx, vec![]);
|
||||
frame(app, &ctx, vec![]);
|
||||
let st = &app.session.documents()[0];
|
||||
crate::canvas::selection::outlines(app, st).into_iter().flat_map(|o| o.paths).map(|p| p.elements().to_vec()).collect::<Vec<_>>()
|
||||
};
|
||||
let both = outlines(&mut app, &[]);
|
||||
let without = outlines(&mut app, &[("select.set", json!({"ids": [hidden]})), ("edit.clear", json!({}))]);
|
||||
let with_hidden = outlines(&mut app, &[("edit.undo", json!({})), ("select.set", json!({"ids": [hidden]})), ("object.hide", json!({}))]);
|
||||
assert_ne!(both, without, "the outlines show both members");
|
||||
assert_eq!(with_hidden, without, "a hidden member is not outlined");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_a_document_while_tiled_fits_each_document_to_its_new_pane() {
|
||||
let mut app = app_with(2);
|
||||
|
||||
@@ -24,7 +24,7 @@ use vectorcraft_geom::{AnchorKind, BezPath, PathData, PathEl, Point};
|
||||
use vectorcraft_tools::Mods;
|
||||
|
||||
use super::cursor::ViewKey;
|
||||
use super::outline::{c32, node_outline, selection_hit_at, too_many_anchors, walk_drawn};
|
||||
use super::outline::{ViewHides, c32, linked_crosses, node_outline, selection_hit_at, too_many_anchors, too_many_marks, walk_drawn};
|
||||
// PLAN: `BodyKind`, `Win` and `ViewKey::from(CanvasView)` are canvas-w10's (cv.S1, S2, S5); their paths here follow the contract.
|
||||
use super::{BodyKind, VectorcraftApp, Win};
|
||||
// PLAN: `anchors` takes `tool_points` because the Curvature tool's own points come from `session.overlays`, which only `show` may call (`&mut app`).
|
||||
@@ -147,9 +147,9 @@ fn hidden(app: &VectorcraftApp) -> bool {
|
||||
crate::dialogs::halftone::previewing(app)
|
||||
}
|
||||
|
||||
/// Whether the selection has too many points to outline: its bounds stand for it.
|
||||
fn too_big(st: &DocState) -> bool {
|
||||
too_many_anchors(st.selection.objects.iter().filter_map(|id| st.doc.node(*id)))
|
||||
/// Whether the selection has too many points to outline and cross in `app`'s view: its bounds stand for it.
|
||||
fn too_big(app: &VectorcraftApp, st: &DocState) -> bool {
|
||||
too_many_marks(st.selection.objects.iter().filter_map(|id| st.doc.node(*id)), ViewHides::of(app))
|
||||
}
|
||||
|
||||
/// The rectangle of `bounds` as a path.
|
||||
@@ -166,17 +166,17 @@ fn group(out: &mut Vec<Outlined>, color: Color32) -> &mut Outlined {
|
||||
&mut out[at]
|
||||
}
|
||||
|
||||
/// The outlines of the selection, one [`Outlined`] per layer colour: each selected object's outline (the bounds of
|
||||
/// all of them when they have too many points), the spine of each selected blend, and the key object's outline (its
|
||||
/// The outlines of the selection, one [`Outlined`] per layer colour: each selected object's outline and the lines
|
||||
/// across its linked images and placed documents (the bounds of all of them when they have too many points), the spine of each selected blend, and the key object's outline (its
|
||||
/// bounds when it has too many points). Nothing during Halftone Preview.
|
||||
pub(super) fn outlines(app: &VectorcraftApp, st: &DocState) -> Vec<Outlined> {
|
||||
let mut out: Vec<Outlined> = vec![];
|
||||
if hidden(app) {
|
||||
return out;
|
||||
}
|
||||
let (sel, symbols) = (&st.selection, st.doc.symbol_boxes());
|
||||
let (sel, symbols, hides) = (&st.selection, st.doc.symbol_boxes(), ViewHides::of(app));
|
||||
let color_of = |id: NodeId| c32(st.doc.layer_color(id));
|
||||
if too_big(st) {
|
||||
if too_big(app, st) {
|
||||
// The cache is warmed by `show`; a test or a miss measures again.
|
||||
let bounds = match app.canvas.selection_bounds {
|
||||
Some((key, bounds)) if key == (st.uid, st.revision) => bounds,
|
||||
@@ -188,9 +188,11 @@ pub(super) fn outlines(app: &VectorcraftApp, st: &DocState) -> Vec<Outlined> {
|
||||
} else {
|
||||
for id in &sel.objects {
|
||||
let Some(node) = st.doc.node(*id) else { continue };
|
||||
let path = node_outline(node, &symbols);
|
||||
if !path.elements().is_empty() {
|
||||
group(&mut out, color_of(*id)).paths.push(path);
|
||||
// Linked images and placed documents are also crossed from corner to corner.
|
||||
for path in [node_outline(node, &symbols, hides), linked_crosses(node, hides)] {
|
||||
if !path.elements().is_empty() {
|
||||
group(&mut out, color_of(*id)).paths.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (blend, spine) in blend_spines(st) {
|
||||
@@ -198,7 +200,11 @@ pub(super) fn outlines(app: &VectorcraftApp, st: &DocState) -> Vec<Outlined> {
|
||||
}
|
||||
}
|
||||
if let Some((key, node)) = sel.key.and_then(|key| Some((key, st.doc.node(key)?))) {
|
||||
let path = if too_many_anchors([node]) { node.geometric_bounds_with(&symbols).map(bounds_path) } else { Some(node_outline(node, &symbols)) };
|
||||
let path = if too_many_anchors([node], hides) {
|
||||
node.geometric_bounds_with(&symbols).map(bounds_path)
|
||||
} else {
|
||||
Some(node_outline(node, &symbols, hides))
|
||||
};
|
||||
if let Some(path) = path {
|
||||
group(&mut out, color_of(key)).key = Some(path);
|
||||
}
|
||||
@@ -266,10 +272,10 @@ pub(super) fn anchors(app: &VectorcraftApp, st: &DocState, tool: &str, tool_poin
|
||||
segment_mark: SegmentMark::Line,
|
||||
options: path_options(prefs),
|
||||
};
|
||||
if hidden(app) || too_big(st) || (curvature && tool_points) {
|
||||
if hidden(app) || too_big(app, st) || (curvature && tool_points) {
|
||||
return out;
|
||||
}
|
||||
let sel = &st.selection;
|
||||
let (sel, hides) = (&st.selection, ViewHides::of(app));
|
||||
// The selected anchors by path, and the selected segment with its path.
|
||||
let mut chosen: Vec<(u64, Vec<KnotRef>)> = vec![];
|
||||
let mut segment: Option<(u64, KnotRef)> = None;
|
||||
@@ -277,7 +283,7 @@ pub(super) fn anchors(app: &VectorcraftApp, st: &DocState, tool: &str, tool_poin
|
||||
let Some(node) = st.doc.node(*id) else { continue };
|
||||
let partial = sel.partial(*id);
|
||||
let color = c32(st.doc.layer_color(*id));
|
||||
walk_drawn(node, &mut |c| {
|
||||
walk_drawn(node, hides, &mut |c| {
|
||||
let envelope = vectorcraft_doc::live::envelope_overlay(c).and_then(|(_, grid)| grid);
|
||||
let grid = match &c.kind {
|
||||
NodeKind::Mesh(m) => Some(m),
|
||||
@@ -369,13 +375,14 @@ pub(super) fn hover(app: &VectorcraftApp, st: &DocState, tool: &str, at: Point,
|
||||
if kept {
|
||||
return None;
|
||||
}
|
||||
outline_of(st, id)
|
||||
outline_of(st, id, ViewHides::of(app))
|
||||
}
|
||||
|
||||
/// The hover outline of `id` in its layer colour, unless it has too many points.
|
||||
fn outline_of(st: &DocState, id: NodeId) -> Option<Hovered> {
|
||||
let node = st.doc.node(id).filter(|n| !too_many_anchors([*n]))?;
|
||||
Some(Hovered { path: node_outline(node, &st.doc.symbol_boxes()), color: c32(st.doc.layer_color(id)) })
|
||||
/// The hover outline of `id` in its layer colour, without the members `hides` leaves out, unless it has too many
|
||||
/// points.
|
||||
fn outline_of(st: &DocState, id: NodeId, hides: ViewHides) -> Option<Hovered> {
|
||||
let node = st.doc.node(id).filter(|n| !too_many_anchors([*n], hides))?;
|
||||
Some(Hovered { path: node_outline(node, &st.doc.symbol_boxes(), hides), color: c32(st.doc.layer_color(id)) })
|
||||
}
|
||||
|
||||
/// The hover outline the canvas shows at document point `at` with the keys `held`: none while Space lends the view
|
||||
@@ -405,7 +412,7 @@ pub(super) fn eyedropper_hover(app: &mut VectorcraftApp, at: Point, mods: Mods,
|
||||
}
|
||||
let info = app.view_info();
|
||||
let id = eyedropper_hover_object(app, at, mods, info)?;
|
||||
outline_of(app.session.active()?, id)
|
||||
outline_of(app.session.active()?, id, ViewHides::of(app))
|
||||
}
|
||||
|
||||
/// What the Eyedropper's hover object depends on: the point, the keys held, the document as it is, the selection and
|
||||
@@ -495,7 +502,7 @@ fn eyedropper_hover_object(app: &mut VectorcraftApp, at: Point, mods: Mods, view
|
||||
/// The dots of the selection: point type's origin, the centre of each object that shows it, and the key anchor.
|
||||
pub(super) fn dots(app: &VectorcraftApp, st: &DocState) -> Dots {
|
||||
let mut out = Dots { grow: grow(&app.session.prefs), ..Dots::default() };
|
||||
if hidden(app) || too_big(st) {
|
||||
if hidden(app) || too_big(app, st) {
|
||||
return out;
|
||||
}
|
||||
let symbols = st.doc.symbol_boxes();
|
||||
|
||||
@@ -243,7 +243,7 @@ fn the_key_object_has_its_own_outline() {
|
||||
let ids = app.session.active().unwrap().selection.objects.clone();
|
||||
app.run("select.key", json!({"id": curve.0})).unwrap();
|
||||
let st = app.session.active().unwrap();
|
||||
let want = node_outline(st.doc.node(curve).unwrap(), &st.doc.symbol_boxes());
|
||||
let want = node_outline(st.doc.node(curve).unwrap(), &st.doc.symbol_boxes(), ViewHides::default());
|
||||
let color = c32(st.doc.layer_color(curve));
|
||||
let out = outlines(&app, st);
|
||||
let key = out.iter().find(|o| o.color == color).and_then(|o| o.key.as_ref()).unwrap();
|
||||
@@ -252,6 +252,298 @@ fn the_key_object_has_its_own_outline() {
|
||||
assert_eq!(out.iter().map(|o| o.paths.len()).sum::<usize>(), ids.len(), "the selection's own outlines stay");
|
||||
}
|
||||
|
||||
/// A file with a 40 × 40 px red PNG in a new temporary folder named `name`.
|
||||
fn red_png(name: &str) -> std::path::PathBuf {
|
||||
use craft_image_codecs::{ChannelLayout, EncodeOptions, Format, Image, SampleType};
|
||||
let png = vectorcraft_testkit::temp_dir(name).join("red.png");
|
||||
let image = Image::from_raw(40, 40, ChannelLayout::Rgba, SampleType::U8, [200u8, 40, 40, 255].repeat(40 * 40)).unwrap();
|
||||
std::fs::write(&png, craft_image_codecs::encode(&image, Format::Png, &EncodeOptions::default()).unwrap()).unwrap();
|
||||
png
|
||||
}
|
||||
|
||||
/// The two lines from corner to corner of `[tl, tr, br, bl]`.
|
||||
fn cross_of([tl, tr, br, bl]: [Point; 4]) -> Vec<PathEl> {
|
||||
vec![PathEl::MoveTo(tl), PathEl::LineTo(br), PathEl::MoveTo(tr), PathEl::LineTo(bl)]
|
||||
}
|
||||
|
||||
/// The outline of `[tl, tr, br, bl]`: its corners joined by straight lines.
|
||||
fn frame_of([tl, tr, br, bl]: [Point; 4]) -> Vec<PathEl> {
|
||||
vec![PathEl::MoveTo(tl), PathEl::LineTo(tr), PathEl::LineTo(br), PathEl::LineTo(bl), PathEl::ClosePath]
|
||||
}
|
||||
|
||||
/// A selected linked image and a selected placed document are crossed from corner to corner, on a turned or
|
||||
/// distorted image along its frame; a selected embedded image shows its outline alone, along its frame when turned or
|
||||
/// distorted. The key object's outline and the hover outline are not crossed (#9080).
|
||||
#[test]
|
||||
fn a_selected_linked_image_is_crossed_and_an_embedded_one_is_not() {
|
||||
let png = red_png("selection-linked");
|
||||
let placed = png.with_file_name("art.vectorcraft");
|
||||
std::fs::write(&placed, vectorcraft_format::save_file(&vectorcraft_doc::Document::new(60.0, 40.0))).unwrap();
|
||||
let mut app = blank();
|
||||
let place = |app: &mut VectorcraftApp, path: &std::path::Path, link: bool, at: [f64; 2]| {
|
||||
NodeId(app.run("file.place", json!({"path": path, "link": link, "at": at})).unwrap()["ids"][0].as_u64().unwrap())
|
||||
};
|
||||
let linked = place(&mut app, &png, true, [100.0, 120.0]);
|
||||
let embedded = place(&mut app, &png, false, [300.0, 120.0]);
|
||||
let document = place(&mut app, &placed, true, [200.0, 230.0]);
|
||||
let corners = |app: &VectorcraftApp, id: NodeId| {
|
||||
let n = app.session.active().unwrap().doc.node(id).unwrap();
|
||||
match &n.kind {
|
||||
NodeKind::PlacedDocument(p) => p.corners(),
|
||||
_ => n.image_corners().unwrap(),
|
||||
}
|
||||
};
|
||||
// Whether the selection's outlines hold a path made of `els`.
|
||||
let drawn = |app: &VectorcraftApp, els: &[PathEl]| {
|
||||
outlines(app, app.session.active().unwrap()).iter().any(|o| o.paths.iter().any(|p| p.elements() == els))
|
||||
};
|
||||
// Whether `id` is crossed, and whether it is outlined along its frame.
|
||||
let marked = |app: &VectorcraftApp, id: NodeId| (drawn(app, &cross_of(corners(app, id))), drawn(app, &frame_of(corners(app, id))));
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
assert_eq!(marked(&app, linked), (true, true), "a linked image");
|
||||
assert!(drawn(&app, &cross_of(corners(&app, document))), "a placed document");
|
||||
assert_eq!(marked(&app, embedded), (false, true), "an embedded image");
|
||||
assert_eq!(outlines(&app, app.session.active().unwrap()).iter().map(|o| o.paths.len()).sum::<usize>(), 5, "three outlines and two crosses");
|
||||
app.run("select.set", json!({"ids": [linked.0, embedded.0]})).unwrap();
|
||||
app.run("object.rotate", json!({"angle": 30})).unwrap();
|
||||
assert_eq!(marked(&app, linked), (true, true), "a turned linked image, along its frame");
|
||||
assert_eq!(marked(&app, embedded), (false, true), "a turned embedded image, outlined along its frame");
|
||||
// Move each image's bottom right corner up its right side, so its corners no longer make a parallelogram.
|
||||
app.session
|
||||
.edit("Distort", |doc, _| {
|
||||
for id in [linked, embedded] {
|
||||
if let Some(n) = doc.node_mut(id)
|
||||
&& let Some([tl, tr, br, bl]) = n.image_corners()
|
||||
{
|
||||
n.set_image_corners([tl, tr, br.lerp(tr, 0.4), bl]).map_err(|e| vectorcraft_engine::EngineError::Other(format!("{e:?}")))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
assert!([linked, embedded].iter().all(|id| doc.node(*id).unwrap().is_distorted_image()), "both images are distorted");
|
||||
assert_eq!(marked(&app, linked), (true, true), "a distorted linked image, corner to corner");
|
||||
assert_eq!(marked(&app, embedded), (false, true), "a distorted embedded image, outlined along its frame");
|
||||
// The key object's outline is its frame alone, and so is the hover outline.
|
||||
for id in [linked, embedded] {
|
||||
app.run("select.key", json!({"id": id.0})).unwrap();
|
||||
let st = app.session.active().unwrap();
|
||||
let key = outlines(&app, st).into_iter().find_map(|o| o.key).unwrap();
|
||||
assert_eq!(key.elements(), frame_of(corners(&app, id)).as_slice(), "the key object's outline of {id:?}");
|
||||
assert_eq!(
|
||||
outline_of(st, id, ViewHides::default()).unwrap().path.elements(),
|
||||
frame_of(corners(&app, id)).as_slice(),
|
||||
"the hover outline of {id:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The selection's outlines count the ends of the lines that cross linked images toward the overlay's limit; the
|
||||
/// hover outline and the key object's outline, which draw no such lines, do not (#9080).
|
||||
#[test]
|
||||
fn the_overlay_limit_counts_crossing_lines_only_where_they_are_drawn() {
|
||||
use super::super::outline::{too_many_anchors, too_many_marks};
|
||||
let image = |link: Option<vectorcraft_doc::LinkInfo>| {
|
||||
let im = vectorcraft_doc::ImageObject {
|
||||
key: "k".into(),
|
||||
width: 10,
|
||||
height: 10,
|
||||
xf: vectorcraft_geom::Affine::IDENTITY,
|
||||
link,
|
||||
placement: Default::default(),
|
||||
pixels: None,
|
||||
};
|
||||
vectorcraft_doc::Node::new(NodeId(1), NodeKind::Image(Box::new(im)))
|
||||
};
|
||||
// Four corners each fit; with the four ends of the crossing lines they do not.
|
||||
let count = OVERLAY_MAX_ANCHORS / 6;
|
||||
let linked = vec![image(Some(vectorcraft_doc::LinkInfo { path: "/a.png".into(), ..Default::default() })); count];
|
||||
let embedded = vec![image(None); count];
|
||||
let all = ViewHides::default();
|
||||
assert!(!too_many_anchors(&linked, all) && too_many_marks(&linked, all), "linked images");
|
||||
assert!(!too_many_anchors(&embedded, all) && !too_many_marks(&embedded, all), "embedded images");
|
||||
}
|
||||
|
||||
/// A selected group outlines, marks and crosses only the members the canvas draws: a hidden member and a linked image
|
||||
/// in a hidden group inside it leave no outline, anchors or crossing lines, in the selection's marks and in the hover
|
||||
/// outline. Hiding them shows the same as deleting them.
|
||||
#[test]
|
||||
fn a_selected_group_leaves_its_hidden_members_unmarked() {
|
||||
let png = red_png("selection-hidden");
|
||||
let mut app = blank();
|
||||
let left = id_of(&app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 20, "height": 20})).unwrap());
|
||||
let right = id_of(&app.run("shape.rectangle", json!({"x": 330, "y": 230, "width": 20, "height": 20})).unwrap());
|
||||
let hidden = id_of(&app.run("shape.rectangle", json!({"x": 120, "y": 100, "width": 40, "height": 40})).unwrap());
|
||||
let linked = app.run("file.place", json!({"path": png, "link": true, "at": [240.0, 150.0]})).unwrap()["ids"][0].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [linked]})).unwrap();
|
||||
let inner = id_of(&app.run("object.group", json!({})).unwrap());
|
||||
app.run("select.set", json!({"ids": [left.0, right.0, hidden.0, inner.0]})).unwrap();
|
||||
let group = id_of(&app.run("object.group", json!({})).unwrap());
|
||||
// With the group selected after the commands `edit`: its outline paths, the paths that show anchors with their
|
||||
// anchor count, and its hover outline.
|
||||
let shown = |app: &mut VectorcraftApp, edit: &[(&str, serde_json::Value)]| {
|
||||
for (command, params) in edit {
|
||||
app.run(command, params.clone()).unwrap();
|
||||
}
|
||||
app.run("select.set", json!({"ids": [group.0]})).unwrap();
|
||||
let st = app.session.active().unwrap();
|
||||
let outlined: Vec<Vec<PathEl>> = outlines(app, st).into_iter().flat_map(|o| o.paths).map(|p| p.elements().to_vec()).collect();
|
||||
let anchored = marks(app).paths.iter().map(|p| p.anchor_count()).collect::<Vec<_>>();
|
||||
let hovered = outline_of(st, group, ViewHides::of(app)).map(|h| h.path.elements().to_vec());
|
||||
(outlined, anchored, hovered)
|
||||
};
|
||||
let both = shown(&mut app, &[]);
|
||||
let without = shown(&mut app, &[("select.set", json!({"ids": [hidden.0, inner.0]})), ("edit.clear", json!({}))]);
|
||||
let with_hidden = shown(&mut app, &[("edit.undo", json!({})), ("select.set", json!({"ids": [hidden.0, inner.0]})), ("object.hide", json!({}))]);
|
||||
assert_ne!(both, without, "the marks show every member");
|
||||
assert_eq!(without.1, vec![4, 4], "the anchors of the two visible members");
|
||||
assert_eq!(with_hidden, without, "hidden members are not marked");
|
||||
}
|
||||
|
||||
/// A selected group leaves out a member made into a guide while the guides are hidden, as the canvas does: its
|
||||
/// outlines, anchors and hover outline are the same as with that member deleted. With the guides shown, the guide is
|
||||
/// marked too.
|
||||
#[test]
|
||||
fn a_selected_group_leaves_out_its_guides_while_guides_are_hidden() {
|
||||
let mut app = blank();
|
||||
let path = id_of(&app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 20, "height": 20})).unwrap());
|
||||
let guide = id_of(&app.run("shape.rectangle", json!({"x": 200, "y": 150, "width": 40, "height": 40})).unwrap());
|
||||
app.run("select.set", json!({"ids": [guide.0]})).unwrap();
|
||||
app.run("view.guides.make", json!({})).unwrap();
|
||||
app.run("select.set", json!({"ids": [path.0, guide.0]})).unwrap();
|
||||
let group = id_of(&app.run("object.group", json!({})).unwrap());
|
||||
assert!(
|
||||
matches!(app.session.active().unwrap().doc.node(guide).map(|n| &n.kind), Some(NodeKind::Path { guide: true, .. })),
|
||||
"the group holds a guide"
|
||||
);
|
||||
// With the group selected: the boxes of its outline paths, the paths that show anchors, and its hover outline's box.
|
||||
let shown = |app: &mut VectorcraftApp| {
|
||||
app.run("select.set", json!({"ids": [group.0]})).unwrap();
|
||||
let st = app.session.active().unwrap();
|
||||
let outlined: Vec<vectorcraft_geom::Rect> = outlines(app, st).into_iter().flat_map(|o| o.paths).map(|p| p.bounding_box()).collect();
|
||||
let anchored = marks(app).paths.iter().map(|p| p.anchor_count()).collect::<Vec<_>>();
|
||||
let hovered = outline_of(st, group, ViewHides::of(app)).map(|h| h.path.bounding_box());
|
||||
(outlined, anchored, hovered)
|
||||
};
|
||||
let both = shown(&mut app);
|
||||
app.run("view.guides", json!({})).unwrap();
|
||||
assert!(!app.ui.view.guides_shown(), "the guides are hidden");
|
||||
let guides_hidden = shown(&mut app);
|
||||
app.run("view.guides", json!({})).unwrap();
|
||||
app.run("select.set", json!({"ids": [guide.0]})).unwrap();
|
||||
app.run("edit.clear", json!({})).unwrap();
|
||||
let without = shown(&mut app);
|
||||
assert_eq!(both.1.len(), 2, "with the guides shown, the guide shows its anchors too: {both:?}");
|
||||
assert_ne!(both, without, "with the guides shown, the guide is marked");
|
||||
assert_eq!(guides_hidden, without, "with the guides hidden, only the path is marked");
|
||||
}
|
||||
|
||||
/// A selected layer leaves out the art of a template sublayer while View › Hide Template is on, and a group a guide
|
||||
/// while the guides are hidden: their outlines and the overlay's point limit count only what the canvas draws.
|
||||
#[test]
|
||||
fn the_marks_leave_out_template_layers_and_guides_the_view_hides() {
|
||||
use super::super::outline::{node_outline, too_many_anchors, too_many_marks};
|
||||
use std::sync::Arc;
|
||||
use vectorcraft_doc::{Appearance, LayerColor, Node};
|
||||
use vectorcraft_geom::SubPath;
|
||||
let rect = |id: u64, r: vectorcraft_geom::Rect| Node::path(NodeId(id), vectorcraft_geom::shapes::rectangle(r), Appearance::default());
|
||||
let path = Arc::new(rect(2, vectorcraft_geom::Rect::new(0.0, 0.0, 10.0, 10.0)));
|
||||
let points: Vec<Point> = (0..=OVERLAY_MAX_ANCHORS).map(|i| Point::new(i as f64, 0.0)).collect();
|
||||
let mut many = Node::path(NodeId(3), PathData::single(SubPath::polyline(&points, false)), Appearance::default());
|
||||
let mut template = Node::layer(NodeId(4), "Template", LayerColor::Preset(1));
|
||||
if let NodeKind::Layer { template: on, children, .. } = &mut template.kind {
|
||||
*on = true;
|
||||
children.push(Arc::new(many.clone()));
|
||||
}
|
||||
let mut layer = Node::layer(NodeId(5), "Layer", LayerColor::Preset(0));
|
||||
if let Some(children) = layer.children_mut() {
|
||||
children.extend([Arc::new(template), path.clone()]);
|
||||
}
|
||||
if let NodeKind::Path { guide, .. } = &mut many.kind {
|
||||
*guide = true;
|
||||
}
|
||||
let group = Node::group(NodeId(6), vec![Arc::new(many), path.clone()]);
|
||||
let doc = vectorcraft_doc::Document::new(300.0, 300.0);
|
||||
let symbols = doc.symbol_boxes();
|
||||
let alone = node_outline(&path, &symbols, ViewHides::default()).bounding_box();
|
||||
let mut wrong = vec![];
|
||||
for (n, what, hides) in [
|
||||
(&layer, "a layer with a template sublayer", ViewHides { templates: true, guides: false }),
|
||||
(&group, "a group with a guide", ViewHides { templates: false, guides: true }),
|
||||
] {
|
||||
for (hides, hidden) in [(ViewHides::default(), false), (hides, true)] {
|
||||
let outline = node_outline(n, &symbols, hides).bounding_box();
|
||||
if (outline == alone) != hidden || too_many_anchors([n], hides) == hidden || too_many_marks([n], hides) == hidden {
|
||||
wrong.push(format!("{what}, hidden by the view: {hidden}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(wrong.is_empty(), "the marks count only what the view draws: {wrong:?}");
|
||||
// A compound path made into a guide draws every path, so each stays outlined while the guides are hidden.
|
||||
let guide_rect = |id: u64, r: vectorcraft_geom::Rect| {
|
||||
let mut n = rect(id, r);
|
||||
if let NodeKind::Path { guide, .. } = &mut n.kind {
|
||||
*guide = true;
|
||||
}
|
||||
Arc::new(n)
|
||||
};
|
||||
let compound = Node::new(
|
||||
NodeId(7),
|
||||
NodeKind::Compound {
|
||||
children: vec![
|
||||
guide_rect(8, vectorcraft_geom::Rect::new(0.0, 0.0, 100.0, 100.0)),
|
||||
guide_rect(9, vectorcraft_geom::Rect::new(30.0, 30.0, 70.0, 70.0)),
|
||||
],
|
||||
rule: vectorcraft_geom::FillRule::EvenOdd,
|
||||
},
|
||||
);
|
||||
let contours = |hides| node_outline(&compound, &symbols, hides).elements().iter().filter(|e| matches!(e, PathEl::MoveTo(_))).count();
|
||||
assert_eq!(contours(ViewHides { templates: false, guides: true }), contours(ViewHides::default()), "a compound path keeps its guide paths");
|
||||
}
|
||||
|
||||
/// The overlay's limit counts the points of the members the highlight outlines: a hidden member of a group, a blend, a
|
||||
/// repeat or an intertwine, and the art of a hidden sublayer, do not count toward it.
|
||||
#[test]
|
||||
fn the_overlay_limit_leaves_out_hidden_members() {
|
||||
use super::super::outline::{too_many_anchors, too_many_marks};
|
||||
use std::sync::Arc;
|
||||
use vectorcraft_doc::{Appearance, LayerColor, Node};
|
||||
use vectorcraft_geom::SubPath;
|
||||
let points: Vec<Point> = (0..=OVERLAY_MAX_ANCHORS).map(|i| Point::new(i as f64, 0.0)).collect();
|
||||
let many = Arc::new(Node::path(NodeId(2), PathData::single(SubPath::polyline(&points, false)), Appearance::default()));
|
||||
let few = Arc::new(Node::path(
|
||||
NodeId(3),
|
||||
vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(0.0, 0.0, 10.0, 10.0)),
|
||||
Appearance::default(),
|
||||
));
|
||||
let mut wrong = vec![];
|
||||
for visible in [true, false] {
|
||||
let mut member = (*many).clone();
|
||||
member.visible = visible;
|
||||
let members = || vec![Arc::new(member.clone()), few.clone()];
|
||||
let group = Node::group(NodeId(1), members());
|
||||
let blend = Node::new(NodeId(6), NodeKind::Blend { children: members(), spec: Default::default() });
|
||||
let repeat = Node::new(NodeId(7), NodeKind::Repeat(vectorcraft_doc::RepeatSpec::grid(members(), 0.0, 0.0)));
|
||||
let intertwine = Node::new(NodeId(8), NodeKind::Intertwine { children: members() });
|
||||
let mut sublayer = Node::layer(NodeId(5), "Sublayer", LayerColor::Preset(1));
|
||||
sublayer.visible = visible;
|
||||
if let Some(children) = sublayer.children_mut() {
|
||||
children.push(many.clone());
|
||||
}
|
||||
let mut layer = Node::layer(NodeId(4), "Layer", LayerColor::Preset(0));
|
||||
if let Some(children) = layer.children_mut() {
|
||||
children.extend([Arc::new(sublayer), few.clone()]);
|
||||
}
|
||||
for (n, what) in [(&group, "a group"), (&blend, "a blend"), (&repeat, "a repeat"), (&intertwine, "an intertwine"), (&layer, "a layer")] {
|
||||
if too_many_anchors([n], ViewHides::default()) != visible || too_many_marks([n], ViewHides::default()) != visible {
|
||||
wrong.push(format!("{what}, member visible: {visible}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(wrong.is_empty(), "the limit is crossed only by visible points: {wrong:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_anchors_of_a_container_selected_whole_draw_selected() {
|
||||
let (mut app, _) = scene();
|
||||
|
||||
@@ -11,7 +11,7 @@ use super::artboards::names_an_artboard;
|
||||
use super::cursor::still_wait;
|
||||
use super::fill::{fill_view, polygon_area};
|
||||
use super::marks::{HiddenMarks, thread_overlays};
|
||||
use super::outline::{node_outline, walk_drawn};
|
||||
use super::outline::{ViewHides, node_outline, walk_drawn};
|
||||
use super::raster::{frame_view, pixel_region, placed_changes, placed_key_at, placed_since, poll_worker};
|
||||
use super::*;
|
||||
use crate::CacheKey;
|
||||
@@ -31,9 +31,13 @@ fn shaper_selection_highlights_only_the_visible_result() {
|
||||
let g = st.doc.node(st.selection.objects[0]).unwrap();
|
||||
assert!(g.extras().shaper.is_some());
|
||||
let symbols = st.doc.symbol_boxes();
|
||||
let bounds = node_outline(g, &symbols).bounding_box();
|
||||
let bounds = node_outline(g, &symbols, ViewHides::default()).bounding_box();
|
||||
assert!((bounds.x0 - 100.0).abs() < 0.01 && (bounds.x1 - 200.0).abs() < 0.01, "{bounds:?}");
|
||||
assert_eq!(node_outline(st.doc.node(line).unwrap(), &symbols).bounding_box().x0, 50.0, "an isolated original still shows its full outline");
|
||||
assert_eq!(
|
||||
node_outline(st.doc.node(line).unwrap(), &symbols, ViewHides::default()).bounding_box().x0,
|
||||
50.0,
|
||||
"an isolated original still shows its full outline"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -50,7 +54,7 @@ fn a_symbol_instance_is_outlined_around_its_art() {
|
||||
inst = Some(n);
|
||||
}
|
||||
});
|
||||
assert_eq!(node_outline(inst.unwrap(), &st.doc.symbol_boxes()).bounding_box(), Rect::new(20.0, 30.0, 40.0, 50.0));
|
||||
assert_eq!(node_outline(inst.unwrap(), &st.doc.symbol_boxes(), ViewHides::default()).bounding_box(), Rect::new(20.0, 30.0, 40.0, 50.0));
|
||||
}
|
||||
|
||||
/// The points of `bp`'s move and line elements, in order.
|
||||
@@ -111,7 +115,7 @@ fn a_turned_or_skewed_symbol_instance_is_outlined_along_its_frame() {
|
||||
("skewed", Affine::skew(0.5, 0.0)),
|
||||
] {
|
||||
let (n, frame) = placed(a);
|
||||
let got = outline_points(&node_outline(&n, &symbols));
|
||||
let got = outline_points(&node_outline(&n, &symbols, ViewHides::default()));
|
||||
assert!(same_points(&got, &frame), "{case}: {got:?} is not the frame {frame:?}");
|
||||
}
|
||||
// In perspective, the frame's corners go through the projection.
|
||||
@@ -120,7 +124,7 @@ fn a_turned_or_skewed_symbol_instance_is_outlined_along_its_frame() {
|
||||
in_perspective(&mut n, h);
|
||||
let (_, flat) = placed(Affine::IDENTITY);
|
||||
let drawn = flat.map(|p| h.apply(p).unwrap());
|
||||
let got = outline_points(&node_outline(&n, &symbols));
|
||||
let got = outline_points(&node_outline(&n, &symbols, ViewHides::default()));
|
||||
assert!(same_points(&got, &drawn), "in perspective: {got:?} is not the projected frame {drawn:?}");
|
||||
}
|
||||
|
||||
@@ -137,7 +141,7 @@ fn type_in_perspective_is_outlined_by_its_projected_box() {
|
||||
let h = vectorcraft_geom::Homography([[1.0, 0.0, 0.0], [0.1, 1.0, 0.0], [0.002, 0.0, 1.0]]);
|
||||
in_perspective(&mut n, h);
|
||||
let drawn = [(b.x0, b.y0), (b.x1, b.y0), (b.x1, b.y1), (b.x0, b.y1)].map(|(x, y)| h.apply(Point::new(x, y)).unwrap());
|
||||
let got = outline_points(&node_outline(&n, &st.doc.symbol_boxes()));
|
||||
let got = outline_points(&node_outline(&n, &st.doc.symbol_boxes(), ViewHides::default()));
|
||||
assert!(same_points(&got, &drawn), "{got:?} is not the projected box {drawn:?}");
|
||||
}
|
||||
|
||||
@@ -4938,17 +4942,83 @@ fn live_trace_selection_highlight_excludes_the_retained_source_rectangle() {
|
||||
for view in TraceView::ALL {
|
||||
group.extras_mut().trace = Some(Box::new(json!({"view":view.id()})));
|
||||
let mut visited = vec![];
|
||||
walk_drawn(&group, &mut |n| visited.push(n.id));
|
||||
walk_drawn(&group, ViewHides::default(), &mut |n| visited.push(n.id));
|
||||
assert_eq!(visited.contains(&NodeId(2)), view.shows_source());
|
||||
let want = if view.shows_source() {
|
||||
vectorcraft_geom::Rect::new(0.0, 0.0, 200.0, 200.0)
|
||||
} else {
|
||||
vectorcraft_geom::Rect::new(20.0, 30.0, 80.0, 90.0)
|
||||
};
|
||||
assert_eq!(node_outline(&group, &symbols).bounding_box(), want);
|
||||
assert_eq!(node_outline(&group, &symbols, ViewHides::default()).bounding_box(), want);
|
||||
}
|
||||
// Without a trace the image is an ordinary hidden member, which the canvas does not draw.
|
||||
group.extras_mut().trace = None;
|
||||
assert_eq!(node_outline(&group, &symbols).bounding_box(), vectorcraft_geom::Rect::new(0.0, 0.0, 200.0, 200.0));
|
||||
assert_eq!(node_outline(&group, &symbols, ViewHides::default()).bounding_box(), vectorcraft_geom::Rect::new(20.0, 30.0, 80.0, 90.0));
|
||||
// A hidden path sent to the back of a trace is not its source image, in any view.
|
||||
let mut path =
|
||||
Node::path(NodeId(4), vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(0.0, 0.0, 200.0, 200.0)), Appearance::default());
|
||||
path.visible = false;
|
||||
let art = Node::path(NodeId(3), vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(20.0, 30.0, 80.0, 90.0)), Appearance::default());
|
||||
let mut group = Node::group(NodeId(1), vec![Arc::new(path), Arc::new(art)]);
|
||||
for view in TraceView::ALL {
|
||||
group.extras_mut().trace = Some(Box::new(json!({"view":view.id()})));
|
||||
assert_eq!(
|
||||
node_outline(&group, &symbols, ViewHides::default()).bounding_box(),
|
||||
vectorcraft_geom::Rect::new(20.0, 30.0, 80.0, 90.0),
|
||||
"{view:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A compound path draws every path it holds, hidden ones included, so its highlight outlines them
|
||||
/// all; a group, a blend, a repeat, an intertwine and a layer leave out a hidden member, and a
|
||||
/// layer the art of a hidden sublayer. A clip group shows its clipping path whether or not it is
|
||||
/// hidden, and a hidden object on its own keeps its outline.
|
||||
#[test]
|
||||
fn a_compound_path_outlines_its_hidden_paths_and_a_group_does_not() {
|
||||
use std::sync::Arc;
|
||||
use vectorcraft_doc::{Appearance, LayerColor, NodeId};
|
||||
use vectorcraft_geom::{FillRule, PathEl};
|
||||
let rect = |id: u64, r: vectorcraft_geom::Rect, visible: bool| {
|
||||
let mut n = Node::path(NodeId(id), vectorcraft_geom::shapes::rectangle(r), Appearance::default());
|
||||
n.visible = visible;
|
||||
Arc::new(n)
|
||||
};
|
||||
let children = || {
|
||||
vec![rect(2, vectorcraft_geom::Rect::new(0.0, 0.0, 100.0, 100.0), true), rect(3, vectorcraft_geom::Rect::new(30.0, 30.0, 70.0, 70.0), false)]
|
||||
};
|
||||
let doc = vectorcraft_doc::Document::new(300.0, 300.0);
|
||||
let symbols = doc.symbol_boxes();
|
||||
let contours = |n: &Node| node_outline(n, &symbols, ViewHides::default()).elements().iter().filter(|e| matches!(e, PathEl::MoveTo(_))).count();
|
||||
assert_eq!(contours(&Node::new(NodeId(1), NodeKind::Compound { children: children(), rule: FillRule::EvenOdd })), 2, "a compound path");
|
||||
assert_eq!(contours(&Node::new(NodeId(1), NodeKind::Blend { children: children(), spec: Default::default() })), 1, "a blend");
|
||||
assert_eq!(contours(&Node::group(NodeId(1), children())), 1, "a group");
|
||||
assert_eq!(contours(&Node::new(NodeId(1), NodeKind::Intertwine { children: children() })), 1, "an intertwine");
|
||||
assert_eq!(contours(&Node::new(NodeId(1), NodeKind::Repeat(vectorcraft_doc::RepeatSpec::grid(children(), 0.0, 0.0)))), 1, "a repeat");
|
||||
// A clip group shows its clipping path, hidden or not, and none of the art it clips.
|
||||
let clip = |visible: bool| {
|
||||
let mut members = children();
|
||||
members.insert(0, rect(6, vectorcraft_geom::Rect::new(10.0, 10.0, 90.0, 90.0), visible));
|
||||
let mut n = Node::group(NodeId(1), members);
|
||||
if let NodeKind::Group { clip, .. } = &mut n.kind {
|
||||
*clip = true;
|
||||
}
|
||||
contours(&n)
|
||||
};
|
||||
assert_eq!((clip(true), clip(false)), (1, 1), "a clip group");
|
||||
// A hidden object that is itself selected keeps its outline.
|
||||
assert_eq!(contours(&rect(7, vectorcraft_geom::Rect::new(0.0, 0.0, 10.0, 10.0), false)), 1, "a hidden object");
|
||||
let mut layer = Node::layer(NodeId(1), "Layer", LayerColor::Preset(0));
|
||||
let mut sublayer = Node::layer(NodeId(4), "Sublayer", LayerColor::Preset(1));
|
||||
sublayer.visible = false;
|
||||
if let Some(c) = sublayer.children_mut() {
|
||||
c.push(rect(5, vectorcraft_geom::Rect::new(150.0, 150.0, 200.0, 200.0), true));
|
||||
}
|
||||
if let Some(c) = layer.children_mut() {
|
||||
c.extend(children());
|
||||
c.push(Arc::new(sublayer));
|
||||
}
|
||||
assert_eq!(contours(&layer), 1, "a layer");
|
||||
}
|
||||
|
||||
/// #2572: Show Text Threads links a thread's frames from the out port of one to the in port of
|
||||
|
||||
@@ -678,6 +678,8 @@ since 2026-10-01.
|
||||
|
||||
- **Selection — disconnected path deletion (#3380, deletion only):** Clear/Delete and Cut turn surviving disconnected pieces of an ordinary contour into independent selected sibling objects. The first keeps its ID; all keep appearance, baked transforms and stacking order. `deletion_split_preserves_gradient_placement` compares rendered survivors with the original paint space and checks linear/radial fill/stroke vectors, already placed gradients and atomic Undo/Redo; connected remainders keep automatic fitting. Existing multi-subpath paths and explicit compound members retain their semantics. Original synthetic regressions in `crates/engine/tests/it/delete_path_pieces.rs` cover styled/transformed rectangles, cubic handles, compound preservation and atomic Undo/Redo; `crates/ui-egui/src/tests/removeanchors.rs` covers real-frame Delete/Backspace and a second Delete removing all survivors. Segment endpoint highlighting remains open. Scores and hours unchanged.
|
||||
- **Selection: deletion on paths with many subpaths:** Clear/Delete, `path.deleteAnchors`, Copy, Cut and Cut Path read each subpath's selected anchors or segments directly from the path's ordered selection, instead of scanning every selected anchor or segment of the path once per subpath. The result is unchanged: `crates/engine/tests/it/delete_path_pieces.rs` checks exact surviving subpaths and their order, open and closed contours, an untouched subpath, references to missing subpaths and indexes, one Undo/Redo step and a second Delete, for anchor and segment selections on one path. Scores and hours unchanged.
|
||||
- **Selection: linked images are crossed (#9080):** a selected linked image or placed document shows two lines in its layer's color from corner to corner of its frame, in the current pane and in other panes of the same document. A selected embedded image shows its outline alone. A selected or highlighted image of either kind is outlined along its frame, so a turned or distorted image's outline follows its corners instead of the box square to the page around it. The lines are part of the selection marks, so View › Hide Edges hides them and output does not draw them. When the selection has more than VectorCraft's own limit of 100,000 outline points (each linked image or placed document adds 4 for the ends of its lines), the current pane and other panes draw one rectangle around the selected objects instead of their outlines and lines; the current pane still draws the key object's thicker outline. `a_selected_linked_image_is_crossed_and_an_embedded_one_is_not` in `crates/ui-egui/src/canvas/selection/tests.rs` covers a linked image, a placed document and an embedded image, each image also turned and distorted, the key object's outline and the hover highlight; `the_overlay_limit_counts_crossing_lines_only_where_they_are_drawn` in the same file covers the limit; `other_panes_cross_a_selected_linked_image` in `crates/ui-egui/src/canvas/panes/tests.rs` covers another pane. Scores and hours unchanged.
|
||||
- **Selection: hidden members are not marked:** a selected group or layer draws no outline, anchors or lines across a linked image for its hidden members or for the art of a hidden sublayer, and neither do the hover outline and other panes. A selected blend, repeat or intertwine draws no outline for its hidden members. The points of hidden members do not count toward the 100,000-point limit. The rectangle drawn above that limit still uses the selection's bounds, which include a group's hidden members. Every path of a compound path, and an Image Trace object's source image in the views that show it, are still outlined. `a_selected_group_leaves_its_hidden_members_unmarked` (with the hover outline) and `the_overlay_limit_leaves_out_hidden_members` in `crates/ui-egui/src/canvas/selection/tests.rs`; `other_panes_leave_out_a_selected_groups_hidden_members` in `crates/ui-egui/src/canvas/panes/tests.rs`; `a_compound_path_outlines_its_hidden_paths_and_a_group_does_not` and `live_trace_selection_highlight_excludes_the_retained_source_rectangle` in `crates/ui-egui/src/canvas/tests.rs`. Scores and hours unchanged.
|
||||
- **Panel collapse controls (#5925, in part):** The small » in a floating tab-group header moves that group into the side icon rail, reusing the existing rail or creating one. An opened rail panel has the same control to fold its flyout back into the rail, including after a tab switch. Both controls preserve the tab group and its menu; other floating groups and full-width docked headers stay as they were. Pointer regressions in `crates/ui-egui/src/panel_docking/tests.rs` cover grouped tabs, reopening, separate groups, a missing rail, the menu and flyout closure after switching tabs; `native_tests.rs` covers the native-window click and removal of the empty palette. Scores and estimates unchanged.
|
||||
|
||||
- 3D lighting presets: `crates/effects/src/lighting_presets.rs`, `crates/engine/src/cmd/effectcmd/lighting_presets_tests.rs` and the pointer tests in `crates/ui-egui/src/dialogs/revolve/tests.rs` cover recognition, atomic targeting, native round trips, preview, Cancel, reset and Undo.
|
||||
|
||||
Reference in New Issue
Block a user