mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 20:46:22 +01:00
Tests: page item width and height setters give the page-aligned size on rotated objects
A rotated rectangle given a width and then a height through the scripting object model reads back the values set, its geometric bounds have that size, and other objects stay as they were. The resize doc comment names the page's axes.
This commit is contained in:
1 parent
a8d1b29766
commit
76aee609f1
2 files changed
+24
-1
No files matched your search
@@ -1392,7 +1392,9 @@ fn item_set_top(h: &Host, a: &[Data]) -> Answer {
|
||||
move_to(h, a, None, Some(y))
|
||||
}
|
||||
|
||||
/// Scales the item about its top-left corner to `size` points wide (`width`) or tall.
|
||||
/// Scales the item about its top-left corner along the page's axes to `size` points wide (`width`)
|
||||
/// or tall, so the page-aligned bounds that `width` and `height` read have that size, rotated
|
||||
/// objects included.
|
||||
fn resize(h: &Host, a: &[Data], width: bool) -> Answer {
|
||||
let what = if width { "width" } else { "height" };
|
||||
let size = number(arg(a, 1), what)?;
|
||||
|
||||
@@ -118,6 +118,27 @@ fn page_item_geometry_uses_document_coordinates_with_y_up() {
|
||||
assert_eq!(out[4], json!([20, 250, 80, 210]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_item_size_setters_on_a_rotated_object_give_the_page_aligned_size() {
|
||||
let (mut s, a, b) = doc();
|
||||
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
|
||||
s.execute("object.rotate", &json!({"angle": 30})).unwrap();
|
||||
let other = format!("{:?}", s.active().unwrap().doc.node(b));
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var i = app.activeDocument.selection[0], h = i.height;\
|
||||
i.width = 80; vc.log([i.width, i.height - h]);\
|
||||
i.height = 90; vc.log([i.width, i.height]);\
|
||||
var g = i.geometricBounds; vc.log([g[2] - g[0], g[1] - g[3]]);",
|
||||
);
|
||||
let pairs: Vec<[f64; 2]> = out.iter().map(|v| [v[0].as_f64().unwrap(), v[1].as_f64().unwrap()]).collect();
|
||||
for (got, want) in pairs.iter().zip([[80.0, 0.0], [80.0, 90.0], [80.0, 90.0]]) {
|
||||
assert!((got[0] - want[0]).abs() < 1e-6 && (got[1] - want[1]).abs() < 1e-6, "{out:?}");
|
||||
}
|
||||
assert_eq!(pairs.len(), 3, "{out:?}");
|
||||
assert_eq!(format!("{:?}", s.active().unwrap().doc.node(b)), other, "the other object stays as it was");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_coordinate_pair_is_inverse_and_y_up() {
|
||||
let mut s = Session::new();
|
||||
|
||||
Reference in new issue
Block a user