mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Measure a turned bool along its own axes in WASM layouts
With the WASM engine, a bool whose children turn measured its path with an axis-aligned box: a 50 px union turned 45 degrees came out 70.7 px wide. In a grid, that widened its track and moved its siblings, so a turned grid copy laid out its children elsewhere than a reflow of the same grid did, and elsewhere than the persisted changes put them. `calculate_bool_bounds` now takes the path's extent along the axes of the bool's bounds, as groups measure theirs; a bool without usable axes keeps the axis-aligned box. Found by the WASM replay of the pinned generated programs (program 156, a turned grid copy holding a union), which passes with it. Test: render-wasm `test_turned_bool_bounds_keep_its_orientation` (fails before the fix). WASM only; the benchmark covers JVM code and is not run. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
bce9ab99cd
commit
4d78f3d9ec
@ -133,10 +133,27 @@ fn calculate_bool_bounds(
|
||||
let mut subtree = shapes.subtree(&shape.id);
|
||||
subtree.set_modifiers(modifiers.clone());
|
||||
|
||||
let path = bools::bool_from_shapes(bool_data.bool_type, &children_ids, &subtree);
|
||||
let result = path.bounds();
|
||||
let mut path = bools::bool_from_shapes(bool_data.bool_type, &children_ids, &subtree);
|
||||
|
||||
Some(result)
|
||||
// the path's extent along the axes of the bool's bounds, as a turned
|
||||
// bool keeps its orientation
|
||||
let hv = shape_bounds.hv(1.0);
|
||||
let vv = shape_bounds.vv(1.0);
|
||||
let axes = Matrix::new_all(hv.x, vv.x, 0.0, hv.y, vv.y, 0.0, 0.0, 0.0, 1.0);
|
||||
let finite = [hv.x, hv.y, vv.x, vv.y].iter().all(|v| v.is_finite());
|
||||
match axes.invert().filter(|_| finite) {
|
||||
Some(inverse) => {
|
||||
path.transform(&inverse);
|
||||
let points = path
|
||||
.bounds()
|
||||
.points()
|
||||
.into_iter()
|
||||
.map(|p| axes.map_point(p))
|
||||
.collect();
|
||||
shape_bounds.with_points(points)
|
||||
}
|
||||
None => Some(path.bounds()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Which parts of the geometry a pixel-grid correction rounds: only the ones
|
||||
@ -897,6 +914,42 @@ mod tests {
|
||||
assert_eq!(bounds.height(), 3.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_turned_bool_bounds_keep_its_orientation() {
|
||||
let bool_id = Uuid::new_v4();
|
||||
let child_id = Uuid::new_v4();
|
||||
let shapes = {
|
||||
let mut shapes = ShapesPool::new();
|
||||
shapes.initialize(10);
|
||||
|
||||
let child = shapes.add_shape(child_id);
|
||||
child.set_selrect(0.0, 0.0, 50.0, 50.0);
|
||||
|
||||
let parent = shapes.add_shape(bool_id);
|
||||
parent.set_shape_type(Type::Bool(Bool::default()));
|
||||
parent.add_child(child_id);
|
||||
parent.set_selrect(0.0, 0.0, 50.0, 50.0);
|
||||
shapes
|
||||
};
|
||||
|
||||
// the bool and its child turned 45 degrees about their center
|
||||
let mut turn = Matrix::rotate_deg(45.0);
|
||||
turn.pre_translate(Point::new(-25.0, -25.0));
|
||||
turn.post_translate(Point::new(25.0, 25.0));
|
||||
let parent = shapes.get(&bool_id).unwrap();
|
||||
let mut bounds = HashMap::new();
|
||||
bounds.insert(bool_id, parent.bounds().transform(&turn));
|
||||
let mut modifiers = HashMap::new();
|
||||
modifiers.insert(child_id, turn);
|
||||
|
||||
let result = calculate_bool_bounds(parent, &shapes, &bounds, &modifiers).unwrap();
|
||||
|
||||
assert!((result.width() - 50.0).abs() < 0.01, "{}", result.width());
|
||||
assert!((result.height() - 50.0).abs() < 0.01, "{}", result.height());
|
||||
let center = result.center();
|
||||
assert!((center.x - 25.0).abs() < 0.01 && (center.y - 25.0).abs() < 0.01);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_masked_group_bounds_are_mask_bounds() {
|
||||
let parent_id = Uuid::new_v4();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user