saxi
Version:
Drive the AxiDraw pen plotter
44 lines • 1.45 kB
JavaScript
import { vmul } from "./vec.js";
function vround(v, digits = 2) {
return { x: Number(v.x.toFixed(digits)), y: Number(v.y.toFixed(digits)) };
}
/**
* Canvas size where the SVG is drawn.
*/
export class PaperSize {
get landscape() {
return new PaperSize({
x: Math.max(this.size.x, this.size.y),
y: Math.min(this.size.x, this.size.y),
});
}
get portrait() {
return new PaperSize({
x: Math.min(this.size.x, this.size.y),
y: Math.max(this.size.x, this.size.y),
});
}
get isLandscape() {
return this.size.x === Math.max(this.size.x, this.size.y);
}
/**
* Common-known paper sizes.
*/
static standard = {
USLetter: new PaperSize(vround(vmul({ x: 8.5, y: 11 }, 25.4))),
USLegal: new PaperSize(vround(vmul({ x: 8.5, y: 14 }, 25.4))),
ArchA: new PaperSize(vround(vmul({ x: 9, y: 12 }, 25.4))),
A3: new PaperSize({ x: 297, y: 420 }),
A4: new PaperSize({ x: 210, y: 297 }),
A5: new PaperSize({ x: 148, y: 210 }),
A6: new PaperSize({ x: 105, y: 148 }),
"6x8": new PaperSize(vround(vmul({ x: 6, y: 8 }, 25.4))),
"5x7": new PaperSize(vround(vmul({ x: 5, y: 7 }, 25.4))),
"11x14": new PaperSize(vround(vmul({ x: 11, y: 14 }, 25.4))),
};
size;
constructor(size) {
this.size = size;
}
}
//# sourceMappingURL=paper-size.js.map