mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-12 17:01:09 +00:00
Merge pull request #2253 from storytold/fix/sec-grid-snap-budget
layout: bound the snap lines a frame's grids generate
This commit is contained in:
2 files changed
+22
-1
No files matched your search
@@ -93,3 +93,15 @@ fn deeply_nested_fill_frames_lay_out_without_running_out_of_stack() {
|
||||
assert_eq!(width(&d, chain[DEEP - 1]), 10.0, "past the nesting the layout follows, layers stay");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snap_lines_are_bounded_across_a_frames_grids() {
|
||||
use figcraft_doc::{Document, GridKind, LayoutGrid, NodeKind};
|
||||
let mut d = Document::new("t");
|
||||
let p = d.first_page().unwrap();
|
||||
let f = d.create(p, NodeKind::Frame, "F", 0.0, 0.0, 4000.0, 4000.0).unwrap();
|
||||
d.get_mut(f).unwrap().grids = vec![LayoutGrid { kind: GridKind::Grid, size: 1.0, visible: true, ..LayoutGrid::default() }; 1000];
|
||||
let (xs, ys) = crate::grid_snap_lines(&d, f);
|
||||
assert!(xs.len() + ys.len() <= 200_000, "{}", xs.len() + ys.len());
|
||||
assert!(xs.len() > 4000 && ys.len() > 4000, "the first grids still give their lines");
|
||||
}
|
||||
@@ -1159,6 +1159,9 @@ pub fn grid_snap_lines(doc: &Document, frame: NodeId) -> (Vec<f64>, Vec<f64>) {
|
||||
grid_snap_lines_in(doc, frame, doc.world_transform(frame))
|
||||
}
|
||||
|
||||
/// The most snap coordinates a frame's grids give together (a few dozen grids' worth of lines).
|
||||
const MAX_SNAP_LINES: usize = 200_000;
|
||||
|
||||
/// [`grid_snap_lines`] mapped from the frame's coordinates by `xf` (the frame's world transform
|
||||
/// for page lines).
|
||||
pub fn grid_snap_lines_in(doc: &Document, frame: NodeId, xf: Affine) -> (Vec<f64>, Vec<f64>) {
|
||||
@@ -1166,7 +1169,13 @@ pub fn grid_snap_lines_in(doc: &Document, frame: NodeId, xf: Affine) -> (Vec<f64
|
||||
let mut xs = Vec::new();
|
||||
let mut ys = Vec::new();
|
||||
for g in f.grids.iter().filter(|g| g.visible) {
|
||||
for r in grid_lines(g, f.width, f.height) {
|
||||
// A frame-wide budget: each grid adds up to ~17,000 lines, and a file can hold any number of grids;
|
||||
// a grid that would pass it is left out whole.
|
||||
let lines = grid_lines(g, f.width, f.height);
|
||||
if xs.len() + ys.len() + 2 * lines.len() > MAX_SNAP_LINES {
|
||||
break;
|
||||
}
|
||||
for r in lines {
|
||||
let a = xf * Point::new(r.x0, r.y0);
|
||||
let b = xf * Point::new(r.x1, r.y1);
|
||||
match g.kind {
|
||||
|
||||
Reference in new issue
Block a user