| 18 | } |
| 19 | |
| 20 | export class Pattern { |
| 21 | public rows: Row[]; |
| 22 | public rowSwitchStyle: RowSwitchStyle; |
| 23 | |
| 24 | constructor() { |
| 25 | this.rows = []; |
| 26 | this.rowSwitchStyle = RowSwitchStyles.backAndForth; |
| 27 | } |
| 28 | |
| 29 | public setRound(): this { |
| 30 | this.rowSwitchStyle = RowSwitchStyles.round; |
| 31 | return this; |
| 32 | } |
| 33 | |
| 34 | public rowsCount(): number { |
| 35 | return this.rows.length; |
| 36 | } |
| 37 | |
| 38 | public lastRow(): Row { |
| 39 | const last = this.rows.at(-1); |
| 40 | if (!last) { |
| 41 | throw new Error('Called lastRow on empty pattern.'); |
| 42 | } |
| 43 | return last; |
| 44 | } |
| 45 | |
| 46 | public get outputStitches(): number { |
| 47 | return this.rows.reduce((total, row) => total + row.outputStitches, 0); |
| 48 | } |
| 49 | |
| 50 | public isEmpty(): boolean { |
| 51 | return this.rowsCount() === 0; |
| 52 | } |
| 53 | |
| 54 | public get showRowDirection(): boolean { |
| 55 | return this.rowSwitchStyle === RowSwitchStyles.backAndForth; |
| 56 | } |
| 57 | |
| 58 | public addRow(row: Row): void { |
| 59 | this.rows.push(row); |
| 60 | } |
| 61 | |
| 62 | public forEachRow(func: (row: Row, index: number) => void): void { |
| 63 | this.rows.forEach(func); |
| 64 | } |
| 65 | } |
nothing calls this directly
no outgoing calls
no test coverage detected