From 85a9f4b948523b2b9dfb698d108660bda775c61b Mon Sep 17 00:00:00 2001 From: Marc Emmanuel Date: Sun, 25 Jan 2026 19:35:48 +0100 Subject: [PATCH] refactor: update shoreline calculation and improve type imports in PackedGraph --- src/modules/features.ts | 10 +++++++--- src/types/PackedGraph.ts | 6 +++--- src/utils/polyfills.ts | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modules/features.ts b/src/modules/features.ts index c85931f3..bedb48ff 100644 --- a/src/modules/features.ts +++ b/src/modules/features.ts @@ -1,4 +1,4 @@ -import { clipPoly, connectVertices, createTypedArray, distanceSquared, isLand, isWater, rn, TYPED_ARRAY_MAX_VALUES,unique } from "../utils"; +import { clipPoly, connectVertices, createTypedArray, distanceSquared, isLand, isWater, rn, TYPED_ARRAY_MAX_VALUES, unique } from "../utils"; import Alea from "alea"; import { polygonArea } from "d3"; @@ -194,7 +194,12 @@ class FeatureModule { if (type === "lake") { if (area > 0) feature.vertices = (feature.vertices as number[]).reverse(); - feature.shoreline = unique((feature.vertices as number[]).map(vertex => vertices.c[vertex].filter((index: number) => isLand(index, pack))).flat() || []); + feature.shoreline = unique( + (feature.vertices as number[]) + .flatMap( + vertexIndex => vertices.c[vertexIndex].filter((index) => isLand(index, pack)) + ) + ); feature.height = Lakes.getHeight(feature as PackedGraphFeature); } @@ -228,7 +233,6 @@ class FeatureModule { while (queue.length) { const cellId = queue.pop() as number; if (borderCells[cellId]) border = true; - if (!border && borderCells[cellId]) border = true; for (const neighborId of neighbors[cellId]) { const isNeibLand = isLand(neighborId, pack); diff --git a/src/types/PackedGraph.ts b/src/types/PackedGraph.ts index c058520e..23f464df 100644 --- a/src/types/PackedGraph.ts +++ b/src/types/PackedGraph.ts @@ -1,5 +1,5 @@ -import { PackedGraphFeature } from "../modules/features"; -import { River } from "../modules/river-generator"; +import type { PackedGraphFeature } from "../modules/features"; +import type { River } from "../modules/river-generator"; type TypedArray = Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Float32Array | Float64Array; @@ -25,7 +25,7 @@ export interface PackedGraph { }; vertices: { i: number[]; // vertex indices - c: number[][]; // neighboring cells + c: [number, number, number][]; // neighboring cells v: number[][]; // neighboring vertices x: number[]; // x coordinates y: number[]; // y coordinates diff --git a/src/utils/polyfills.ts b/src/utils/polyfills.ts index 89a0d2d9..18f5f1bd 100644 --- a/src/utils/polyfills.ts +++ b/src/utils/polyfills.ts @@ -44,7 +44,7 @@ declare global { } interface Array { - flat(depth?: number): T; + flat(depth?: number): T[]; at(index: number): T | undefined; }