MCPcopy Create free account
hub / github.com/alefore/knit / getPatternDimensions

Method getPatternDimensions

src/pattern_renderer.ts:19–41  ·  view source on GitHub ↗
(pattern: Pattern)

Source from the content-addressed store, hash-verified

17 }
18
19 public getPatternDimensions(pattern: Pattern) {
20 const unflippedPatternSizeStitches = {
21 x: pattern.rowsCount(),
22 y: Math.max(...pattern.rows.map(row => row.outputStitches))
23 };
24
25 const baseStitchSizeWidth =
26 this.canvas.width / unflippedPatternSizeStitches.x;
27 const baseStitchSizeHeight =
28 this.canvas.height / unflippedPatternSizeStitches.y;
29 const stitchSizeAtZoom1 =
30 Math.min(baseStitchSizeWidth, baseStitchSizeHeight);
31 const unflippedPatternSizePixels =
32 scale(unflippedPatternSizeStitches, stitchSizeAtZoom1);
33
34 return {
35 unflippedPatternSizeStitches,
36 unflippedPatternSizePixels,
37 baseStitchSizeWidth,
38 baseStitchSizeHeight,
39 stitchSizeAtZoom1,
40 };
41 }
42
43 public render(
44 pattern: Pattern, zoomLevel: number, offset: KnitPoint,

Callers 3

renderMethod · 0.95
centerPatternMethod · 0.80
handleClickOnPatternMethod · 0.80

Calls 2

scaleFunction · 0.85
rowsCountMethod · 0.80

Tested by

no test coverage detected