Perspective grid: a grid dragged off its preset reports no preset name

perspective.grid.get reports define.name only while the grid still has
the preset's fields, as Define Grid's Preset menu shows [Custom]. Part of #5248.
This commit is contained in:
Don Omondi
2026-11-07 00:17:12 +07:00
committed by bflatastic
parent 4e11389bf0
commit 5019846d08
3 changed files with 28 additions and 3 deletions
+8 -2
View File
@@ -29,7 +29,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Perspective Grid",
[],
None,
"{} → {grid: the model (as perspective.grid.set takes it), define: the Define Grid fields (as perspective.grid.define takes them), station: {x, y, distance} (the viewer: centre of vision on the horizon, distance to the picture plane, pt), defined: false while the document uses the default grid}",
"{} → {grid: the model (as perspective.grid.set takes it), define: the Define Grid fields (as perspective.grid.define takes them; name is the preset only while the grid still has its fields, else \"\" for custom: dragging the horizon, a vanishing point or the station point makes it custom, moving a plane does not), station: {x, y, distance} (the viewer: centre of vision on the horizon, distance to the picture plane, pt), defined: false while the document uses the default grid}",
has_doc,
grid_get
),
@@ -222,7 +222,13 @@ pub(crate) fn grid_info(doc: &vectorcraft_doc::Document, g: &PerspectiveGrid) ->
fn grid_get(s: &mut Session, _: &Value) -> Result<Value> {
let doc = &s.doc()?.doc;
Ok(grid_info(doc, &grid_of(doc)))
let g = grid_of(doc);
let mut info = grid_info(doc, &g);
// The grid is its preset only while it has the preset's fields: a station point or vanishing
// point dragged since makes it a custom grid.
let def = g.definition();
info["define"]["name"] = json!(s.preset_named(&def, &[&def.name]));
Ok(info)
}
fn grid_define(s: &mut Session, p: &Value) -> Result<Value> {
+17
View File
@@ -342,6 +342,23 @@ fn lock_station_point_swings_the_other_vanishing_point() {
assert!(n.viewing_angle() < 45.0);
}
#[test]
fn a_grid_dragged_off_its_preset_reports_no_preset_name() {
let mut s = session();
run(&mut s, "perspective.grid.preset", json!({"name": "[1P-Normal View]"}));
let name = |s: &mut Session| run(s, "perspective.grid.get", json!({}))["define"]["name"].clone();
assert_eq!(name(&mut s), json!("[1P-Normal View]"));
// Moving a plane keeps the definition: still the preset.
run(&mut s, "perspective.plane.move", json!({"plane": "ground", "by": 50}));
assert_eq!(name(&mut s), json!("[1P-Normal View]"));
let g = grid(&s);
drag(&mut s, "perspectiveGrid", Point::new(g.vp_left, g.horizon), Point::new(g.vp_left - 40.0, g.horizon - 60.0));
assert!(!near(grid(&s).horizon, g.horizon), "the horizon moved");
assert_eq!(name(&mut s), json!(""), "a custom grid now");
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(name(&mut s), json!("[1P-Normal View]"));
}
#[test]
fn snap_to_grid_lands_drawn_and_moved_art_on_gridlines() {
let mut s = session();
+3 -1
View File
@@ -6053,7 +6053,9 @@ a stroke when it has `rect`. With both `rect` and `points`, the command also tou
## Perspective grid
The grid is document data (`perspective.grid.set` edits the model directly). `perspective.grid.get` reads it:
`grid` (the model), `define` (the Define Grid fields), `station` (the viewer: `x` the centre of vision on the
`grid` (the model), `define` (the Define Grid fields; its `name` is the preset only while the grid still has that
preset's fields, else `""` for a custom grid, so dragging the horizon, a vanishing point or the station point clears it
and moving a plane does not), `station` (the viewer: `x` the centre of vision on the
horizon `y`, `distance` from the picture plane, in points) and `defined` (false while the document uses the default
grid). `perspective.grid.define` sets the grid from the Define Grid fields: `kind`, `units`, `scale`
(`[artboard, real world]`), `gridline`, `angle` (the viewing angle, 0–90°), `distance` (the viewing distance),