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

Method renderRowCables

src/cable_pattern_factory.ts:137–166  ·  view source on GitHub ↗
(row: number)

Source from the content-addressed store, hash-verified

135 }
136
137 renderRowCables(row: number): number[] {
138 const output: number[] = Array(this.rowsWidth).fill(-1);
139 const Mark = (cable: number, position: number) => {
140 if (position < 0 || position >= output.length) return; // Prevent out-of-bounds access
141 if (output[position] !== -1)
142 throw new Error(
143 'Unable to render row cables: ' + cable + ' ' + output[position] +
144 ' at row ' + row + ' position ' + position);
145 output[position] = cable;
146 };
147
148 for (let cable = 0; cable < this.cables; cable++) {
149 const cablePositions = this.positions[row % this.positions.length];
150 const pos = cablePositions ? cablePositions[cable] : undefined;
151 if (pos !== undefined) {
152 Mark(cable, pos);
153 Mark(cable, pos + 1);
154 }
155 }
156 if (this.innerCables)
157 for (let cable = 0; cable < this.cables - 2; cable++) {
158 const innerCablePositions = this.positionsInnerCables[row];
159 const innerPos = innerCablePositions ? innerCablePositions[cable] : undefined;
160 if (innerPos !== undefined) {
161 Mark(this.cables + cable, innerPos);
162 Mark(this.cables + cable, innerPos + 1);
163 }
164 }
165 return output;
166 }
167
168 computeRow(row: number): Row {
169 return (row % 2 == 0) ? this.#cablesRow(row / 2) : this.#lameRow();

Callers 1

#cablesRowMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected