UNPKG

saxi

Version:

Drive the AxiDraw pen plotter

108 lines 4.99 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.replan = replan; const Optimization = __importStar(require("optimize-paths")); const planning_1 = require("./planning"); const util_1 = require("./util"); const vec_1 = require("./vec"); // CSS, and thus SVG, defines 1px = 1/96th of 1in // https://www.w3.org/TR/css-values-4/#absolute-lengths const svgUnitsPerInch = 96; const mmPerInch = 25.4; const mmPerSvgUnit = mmPerInch / svgUnitsPerInch; function replan(inPaths, planOptions) { let paths = inPaths; const device = (0, planning_1.Device)(planOptions.hardware); // Rotate drawing around center of paper to handle plotting portrait drawings // along y-axis of plotter // Rotate around the center of the page, but in SvgUnits (not mm) if (planOptions.rotateDrawing !== 0) { console.time("rotating paths"); paths = paths.map((pl) => pl.map((p) => (0, vec_1.vrot)(p, (0, vec_1.vmul)({ x: planOptions.paperSize.size.x / 2, y: planOptions.paperSize.size.y / 2 }, 1 / mmPerSvgUnit), planOptions.rotateDrawing))); console.timeEnd("rotating paths"); } // Compute scaling using _all_ the paths, so it's the same no matter what // layers are selected. if (planOptions.fitPage) { paths = (0, util_1.scaleToPaper)(paths, planOptions.paperSize, planOptions.marginMm); } else { paths = paths.map(ps => ps.map(p => (0, vec_1.vmul)(p, mmPerSvgUnit))); if (planOptions.cropToMargins) { paths = (0, util_1.cropToMargins)(paths, planOptions.paperSize, planOptions.marginMm); } } // Rescaling loses the stroke info, so refer back to the original paths to // filter based on the stroke. Rescaling doesn't change the number or order // of the paths. if (planOptions.layerMode === 'group') { paths = paths.filter((path, i) => planOptions.selectedGroupLayers.has(inPaths[i].groupId)); } else if (planOptions.layerMode === 'stroke') { paths = paths.filter((path, i) => planOptions.selectedStrokeLayers.has(inPaths[i].stroke)); } if (planOptions.pointJoinRadius > 0) { paths = paths.map((p) => (0, util_1.dedupPoints)(p, planOptions.pointJoinRadius)); } if (planOptions.sortPaths) { console.time("sorting paths"); paths = Optimization.reorder(paths); console.timeEnd("sorting paths"); } if (planOptions.minimumPathLength > 0) { console.time("eliding short paths"); paths = Optimization.elideShorterThan(paths, planOptions.minimumPathLength); console.timeEnd("eliding short paths"); } if (planOptions.pathJoinRadius > 0) { console.time("joining nearby paths"); paths = Optimization.merge(paths, planOptions.pathJoinRadius); console.timeEnd("joining nearby paths"); } // Convert the paths to units of "steps". paths = paths.map((ps) => ps.map((p) => (0, vec_1.vmul)(p, device.stepsPerMm))); // And finally, motion planning. console.time('planning pen motions'); const theplan = (0, planning_1.plan)(paths, { penUpPos: device.penPctToPos(planOptions.penUpHeight), penDownPos: device.penPctToPos(planOptions.penDownHeight), penDownProfile: { acceleration: planOptions.penDownAcceleration * device.stepsPerMm, maximumVelocity: planOptions.penDownMaxVelocity * device.stepsPerMm, corneringFactor: planOptions.penDownCorneringFactor * device.stepsPerMm }, penUpProfile: { acceleration: planOptions.penUpAcceleration * device.stepsPerMm, maximumVelocity: planOptions.penUpMaxVelocity * device.stepsPerMm, corneringFactor: 0 }, penDropDuration: planOptions.penDropDuration, penLiftDuration: planOptions.penLiftDuration, }); console.timeEnd("planning pen motions"); return theplan; } //# sourceMappingURL=massager.js.map