mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
fix: e2e tests
This commit is contained in:
parent
85a9f4b948
commit
6797baf7fe
4 changed files with 22 additions and 24 deletions
|
|
@ -47,7 +47,7 @@ export class LakesModule {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
defineClimateData(heights: Uint8Array) {
|
defineClimateData(heights: number[] | Uint8Array) {
|
||||||
const {cells, features} = pack;
|
const {cells, features} = pack;
|
||||||
const lakeOutCells = new Uint16Array(cells.i.length);
|
const lakeOutCells = new Uint16Array(cells.i.length);
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ export class LakesModule {
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if lake can be potentially open (not in deep depression)
|
// check if lake can be potentially open (not in deep depression)
|
||||||
detectCloseLakes(h: Uint8Array) {
|
detectCloseLakes(h: number[] | Uint8Array) {
|
||||||
const {cells} = pack;
|
const {cells} = pack;
|
||||||
const ELEVATION_LIMIT = +(byId("lakeElevationLimitOutput") as HTMLInputElement)?.value;
|
const ELEVATION_LIMIT = +(byId("lakeElevationLimitOutput") as HTMLInputElement)?.value;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,8 @@ class OceanModule {
|
||||||
|
|
||||||
const points = clipPoly(
|
const points = clipPoly(
|
||||||
relaxed.map(v => this.vertices.p[v]),
|
relaxed.map(v => this.vertices.p[v]),
|
||||||
undefined,
|
graphWidth,
|
||||||
undefined,
|
graphHeight,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
chains.push([t, points]);
|
chains.push([t, points]);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
import Alea from "alea";
|
import Alea from "alea";
|
||||||
import { curveBasis,
|
import { each, rn, round, rw} from "../utils";
|
||||||
line,
|
import { curveBasis, line, mean, min, sum, curveCatmullRom } from "d3";
|
||||||
mean, min, sum, curveCatmullRom } from "d3";
|
|
||||||
import { each,
|
|
||||||
rn,round,
|
|
||||||
rw} from "../utils";
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
var Rivers: RiverModule;
|
var Rivers: RiverModule;
|
||||||
|
|
@ -62,7 +60,7 @@ class RiverModule {
|
||||||
|
|
||||||
const drainWater = () => {
|
const drainWater = () => {
|
||||||
const MIN_FLUX_TO_FORM_RIVER = 30;
|
const MIN_FLUX_TO_FORM_RIVER = 30;
|
||||||
const cellsNumberModifier = (parseInt(pointsInput.dataset.cells || "10000") / 10000) ** 0.25;
|
const cellsNumberModifier = ((pointsInput.dataset.cells as any) / 10000) ** 0.25;
|
||||||
|
|
||||||
const prec = grid.cells.prec;
|
const prec = grid.cells.prec;
|
||||||
const land = cells.i.filter((i: number) => h[i] >= 20).sort((a: number, b: number) => h[b] - h[a]);
|
const land = cells.i.filter((i: number) => h[i] >= 20).sort((a: number, b: number) => h[b] - h[a]);
|
||||||
|
|
@ -76,7 +74,7 @@ class RiverModule {
|
||||||
? features.filter((feature: any) => i === feature.outCell && feature.flux > feature.evaporation)
|
? features.filter((feature: any) => i === feature.outCell && feature.flux > feature.evaporation)
|
||||||
: [];
|
: [];
|
||||||
for (const lake of lakes) {
|
for (const lake of lakes) {
|
||||||
const lakeCell: number = cells.c[i].find((c: number) => h[c] < 20 && cells.f[c] === lake.i) || i;
|
const lakeCell = cells.c[i].find((c: number) => h[c] < 20 && cells.f[c] === lake.i)!;
|
||||||
cells.fl[lakeCell] += Math.max(lake.flux - lake.evaporation, 0); // not evaporated lake water drains to outlet
|
cells.fl[lakeCell] += Math.max(lake.flux - lake.evaporation, 0); // not evaporated lake water drains to outlet
|
||||||
|
|
||||||
// allow chain lakes to retain identity
|
// allow chain lakes to retain identity
|
||||||
|
|
@ -191,7 +189,7 @@ class RiverModule {
|
||||||
cells.conf = new Uint16Array(cells.i.length);
|
cells.conf = new Uint16Array(cells.i.length);
|
||||||
pack.rivers = [];
|
pack.rivers = [];
|
||||||
|
|
||||||
const defaultWidthFactor = rn(1 / (parseInt(pointsInput.dataset.cells || "10000") / 10000) ** 0.25, 2);
|
const defaultWidthFactor = rn(1 / ((pointsInput.dataset.cells as any) / 10000) ** 0.25, 2);
|
||||||
const mainStemWidthFactor = defaultWidthFactor * 1.2;
|
const mainStemWidthFactor = defaultWidthFactor * 1.2;
|
||||||
|
|
||||||
for (const key in riversData) {
|
for (const key in riversData) {
|
||||||
|
|
@ -290,16 +288,16 @@ class RiverModule {
|
||||||
TIME && console.timeEnd("generateRivers");
|
TIME && console.timeEnd("generateRivers");
|
||||||
};
|
};
|
||||||
|
|
||||||
alterHeights(): Uint8Array {
|
alterHeights(): number[] {
|
||||||
const {h, c, t} = pack.cells as {h: Uint8Array, c: number[][], t: Uint8Array};
|
const {h, c, t} = pack.cells as {h: Uint8Array, c: number[][], t: Uint8Array};
|
||||||
return Uint8Array.from(Array.from(h).map((h, i) => {
|
return Array.from(h).map((h, i) => {
|
||||||
if (h < 20 || t[i] < 1) return h;
|
if (h < 20 || t[i] < 1) return h;
|
||||||
return h + t[i] / 100 + (mean(c[i].map(c => t[c])) || 0) / 10000;
|
return h + t[i] / 100 + (mean(c[i].map(c => t[c])) as number) / 10000;
|
||||||
}));
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// depression filling algorithm (for a correct water flux modeling)
|
// depression filling algorithm (for a correct water flux modeling)
|
||||||
resolveDepressions(h: Uint8Array) {
|
resolveDepressions(h: number[]) {
|
||||||
const {cells, features} = pack;
|
const {cells, features} = pack;
|
||||||
const maxIterations = +(document.getElementById("resolveDepressionsStepsOutput") as HTMLInputElement)?.value;
|
const maxIterations = +(document.getElementById("resolveDepressionsStepsOutput") as HTMLInputElement)?.value;
|
||||||
const checkLakeMaxIteration = maxIterations * 0.85;
|
const checkLakeMaxIteration = maxIterations * 0.85;
|
||||||
|
|
@ -327,23 +325,23 @@ class RiverModule {
|
||||||
if (iteration < checkLakeMaxIteration) {
|
if (iteration < checkLakeMaxIteration) {
|
||||||
for (const l of lakes) {
|
for (const l of lakes) {
|
||||||
if (l.closed) continue;
|
if (l.closed) continue;
|
||||||
const minHeight: number = min<number>(l.shoreline.map((s: number) => h[s])) || 100;
|
const minHeight = min(l.shoreline.map((s: number) => h[s])) as number;
|
||||||
if (minHeight >= 100 || l.height > minHeight) continue;
|
if (minHeight >= 100 || l.height > minHeight) continue;
|
||||||
|
|
||||||
if (iteration > elevateLakeMaxIteration) {
|
if (iteration > elevateLakeMaxIteration) {
|
||||||
l.shoreline.forEach((i: number) => (h[i] = cells.h[i]));
|
l.shoreline.forEach((i: number) => (h[i] = cells.h[i]));
|
||||||
l.height = (min<number>(l.shoreline.map((s: number) => h[s])) || 100) - 1;
|
l.height = (min(l.shoreline.map((s: number) => h[s])) as number) - 1;
|
||||||
l.closed = true;
|
l.closed = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
depressions++;
|
depressions++;
|
||||||
l.height = minHeight + 0.2;
|
l.height = (minHeight as number) + 0.2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const i of land) {
|
for (const i of land) {
|
||||||
const minHeight = min<number>(cells.c[i].map((c: number) => height(c))) || 100;
|
const minHeight = min(cells.c[i].map((c: number) => height(c))) as number;
|
||||||
if (minHeight >= 100 || h[i] > minHeight) continue;
|
if (minHeight >= 100 || h[i] > minHeight) continue;
|
||||||
|
|
||||||
depressions++;
|
depressions++;
|
||||||
|
|
@ -430,7 +428,7 @@ class RiverModule {
|
||||||
if (pointIndex === 0) return startingWidth;
|
if (pointIndex === 0) return startingWidth;
|
||||||
|
|
||||||
const fluxWidth = Math.min(flux ** 0.7 / this.FLUX_FACTOR, this.MAX_FLUX_WIDTH);
|
const fluxWidth = Math.min(flux ** 0.7 / this.FLUX_FACTOR, this.MAX_FLUX_WIDTH);
|
||||||
const lengthWidth = pointIndex * this.LENGTH_STEP_WIDTH + (this.LENGTH_PROGRESSION[pointIndex] || this.LENGTH_PROGRESSION.at(-1) || 0);
|
const lengthWidth = pointIndex * this.LENGTH_STEP_WIDTH + (this.LENGTH_PROGRESSION[pointIndex] || this.LENGTH_PROGRESSION.at(-1) as number);
|
||||||
return widthFactor * (lengthWidth + fluxWidth) + startingWidth;
|
return widthFactor * (lengthWidth + fluxWidth) + startingWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue