refactor: drawCultures

This commit is contained in:
max 2022-08-02 00:36:02 +03:00
parent 6a3ef0f790
commit cbe6da0949
4 changed files with 70 additions and 33 deletions

View file

@ -94,21 +94,34 @@ const CONNECT_VERTICES_MAX_ITERATIONS = 50000;
export function connectVertices({
vertices,
startingVertex,
ofSameType
ofSameType,
checkedCellsMutable
}: {
vertices: IGraphVertices;
startingVertex: number;
ofSameType: (cellId: number) => boolean;
checkedCellsMutable?: Uint8Array;
}) {
const chain: number[] = []; // vertices chain to form a path
const addToChecked = (cellIds: number[]) => {
if (checkedCellsMutable) {
cellIds.forEach(cellId => {
checkedCellsMutable[cellId] = 1;
});
}
};
let next = startingVertex;
for (let i = 0; i === 0 || (next !== startingVertex && i < CONNECT_VERTICES_MAX_ITERATIONS); i++) {
const previous = chain.at(-1);
const current = next;
chain.push(current);
const [c1, c2, c3] = vertices.c[current].map(ofSameType);
const neibCells = vertices.c[current];
addToChecked(neibCells);
const [c1, c2, c3] = neibCells.map(ofSameType);
const [v1, v2, v3] = vertices.v[current];
if (v1 !== previous && c1 !== c2) next = v1;