mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 09:31:23 +01:00
refactor: update shoreline calculation and improve type imports in PackedGraph
This commit is contained in:
parent
3ed3d0dbd8
commit
85a9f4b948
3 changed files with 11 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ declare global {
|
|||
}
|
||||
|
||||
interface Array<T> {
|
||||
flat(depth?: number): T;
|
||||
flat(depth?: number): T[];
|
||||
at(index: number): T | undefined;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue