MCPcopy Create free account
hub / github.com/openscopeproject/InteractiveHtmlBom / recalcLayerScale

Function recalcLayerScale

InteractiveHtmlBom/web/render.js:636–660  ·  view source on GitHub ↗
(layerdict, width, height)

Source from the content-addressed store, hash-verified

634}
635
636function recalcLayerScale(layerdict, width, height) {
637 var flip = (layerdict.layer === "B");
638 var bbox = applyRotation(pcbdata.edges_bbox, flip);
639 var scalefactor = 0.98 * Math.min(
640 width / (bbox.maxx - bbox.minx),
641 height / (bbox.maxy - bbox.miny)
642 );
643 if (scalefactor < 0.1) {
644 scalefactor = 1;
645 }
646 layerdict.transform.s = scalefactor;
647 if (flip) {
648 layerdict.transform.x = -((bbox.maxx + bbox.minx) * scalefactor + width) * 0.5;
649 } else {
650 layerdict.transform.x = -((bbox.maxx + bbox.minx) * scalefactor - width) * 0.5;
651 }
652 layerdict.transform.y = -((bbox.maxy + bbox.miny) * scalefactor - height) * 0.5;
653 for (var c of ["bg", "fab", "silk", "highlight"]) {
654 canvas = layerdict[c];
655 canvas.width = width;
656 canvas.height = height;
657 canvas.style.width = (width / devicePixelRatio) + "px";
658 canvas.style.height = (height / devicePixelRatio) + "px";
659 }
660}
661
662function redrawCanvas(layerdict) {
663 prepareLayer(layerdict);

Callers 2

saveImageFunction · 0.85
resizeCanvasFunction · 0.85

Calls 1

applyRotationFunction · 0.85

Tested by

no test coverage detected