Viewport from two corners
64-bitThe size and center of a new viewport, and what it shows.
w = |Δx|; h = |Δy|; center = (a + b) ÷ 2
Width and height are absolute coordinate differences and the center is the mean of the corners. A side under 1e-9 paper units (absolute) is refused. The model point and the scale the viewport starts with come from sheets.js aimViewport.
const w = Math.abs(b.x - a.x), h = Math.abs(b.y - a.y);
if (w < 1e-9 || h < 1e-9) { c.print(t('cmd.mview.viewport_needs_width_height')); return; }
const aim = aimViewport(c.doc, lay.paper.unit, w, h, modelExtents(c.doc));
if (!c.doc.layers.has('Viewports')) c.doc.addLayer({ name: 'Viewports', color: 8, plot: false });
const frz = [...c.doc.layers.values()].filter((l) => l.newVpFrozen).map((l) => l.name); // layers frozen in new viewports (VP.2)
c.doc.change('MVIEW', () => c.doc.add({ type: 'viewport', layer: 'Viewports', color: null, x: (a.x + b.x) / 2, y: (a.y + b.y) / 2, w, h, cx: aim.cx, cy: aim.cy, s: aim.s, ...(frz.length ? { frz } : {}) }));