improve bounds tracking and output in cut modes. improve dark mode export dialog

This commit is contained in:
Stewart Allen 2024-06-12 10:31:40 -07:00
commit a15e73495f
4 changed files with 91 additions and 51 deletions

View file

@ -12,37 +12,47 @@ gapp.register("kiri.pack", [], (root, exports) => {
const { kiri } = root;
class Packer {
constructor(w, h, spacing, inv) {
constructor(w, h, spacing, opt = {}) {
this.root = { x: 0, y: 0, w: w, h: h };
this.max = { w: 0, h: 0 };
this.packed = false;
this.spacing = typeof(spacing) === 'number' ? spacing : 1;
this.inv = inv;
this.opt = opt;
this.pad = this.spacing / 2;
}
// array of blocks/tiles with {w,h} properties
simple(blocks) {
let n = 0, block, x = 0, y = 0, mh = 0;
let n = 0, block, x = 0, y = 0, mh = 0, maxx = 0, maxy = 0;
let spacing = blocks.length > 1 ? this.spacing : 0;
while (n < blocks.length) {
block = blocks[n++];
block.fit = { x, y };
this.max.w = Math.max(this.max.w, x + block.w);
this.max.h = Math.max(this.max.h, y + block.h);
maxx = Math.max(maxx, x);
maxy = Math.max(maxy, y);
mh = Math.max(mh, block.h);
x += block.w + spacing;
if (x > this.root.w) {
x = 0;
y += ((mh + spacing) * (this.inv ? -1 : 1));
y = y + mh + spacing;
mh = 0;
}
if (this.inv && (y < -this.root.h)) {
return this;
}
if (y > this.root.h) {
return this;
}
}
if (this.opt.invx) {
for (let block of blocks) {
block.fit.x = maxx - block.fit.x;
}
}
if (this.opt.invy) {
for (let block of blocks) {
block.fit.y = maxy - block.fit.y;
}
}
this.packed = true;
return this;
}

View file

@ -93,16 +93,15 @@ function platformUpdateOrigin(update_bounds = true) {
origin.x += process.camOriginOffX;
origin.y += process.camOriginOffY;
origin.z += process.camOriginOffZ;
if (isIndexed) {
origin.y = 0;
}
}
// WireEDM origin offsets
if (MODE === MODES.WEDM) {
origin.x -= process.ctOriginOffX;
origin.y -= process.ctOriginOffY;
}
if (isIndexed) {
origin.y = 0;
origin.y += process.ctOriginOffY;
}
space.platform.setRulers(ruler, ruler, 1 / api.view.unit_scale(), 'X', isBelt ? 'Z' : 'Y');