12 lines
262 B
TypeScript
12 lines
262 B
TypeScript
export interface PixelRun {
|
|
x: number;
|
|
y: number;
|
|
width: number;
|
|
}
|
|
|
|
export function pixelRuns(rows: string[]): PixelRun[] {
|
|
return rows.flatMap((row, y) =>
|
|
[...row.matchAll(/X+/g)].map((match) => ({ x: match.index ?? 0, y, width: match[0].length }))
|
|
);
|
|
}
|