mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-04-04 22:47:23 +02:00
fix: type issues
This commit is contained in:
parent
54ba228fb6
commit
064e4d83e3
11 changed files with 21 additions and 22 deletions
3
package-lock.json
generated
3
package-lock.json
generated
|
|
@ -9,7 +9,6 @@
|
||||||
"version": "1.113.5",
|
"version": "1.113.5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/lineclip": "^2.0.0",
|
|
||||||
"alea": "^1.0.1",
|
"alea": "^1.0.1",
|
||||||
"d3": "^7.9.0",
|
"d3": "^7.9.0",
|
||||||
"delaunator": "^5.0.1",
|
"delaunator": "^5.0.1",
|
||||||
|
|
@ -21,6 +20,7 @@
|
||||||
"@playwright/test": "^1.57.0",
|
"@playwright/test": "^1.57.0",
|
||||||
"@types/d3": "^7.4.3",
|
"@types/d3": "^7.4.3",
|
||||||
"@types/delaunator": "^5.0.3",
|
"@types/delaunator": "^5.0.3",
|
||||||
|
"@types/lineclip": "^2.0.0",
|
||||||
"@types/node": "^25.0.10",
|
"@types/node": "^25.0.10",
|
||||||
"@types/polylabel": "^1.1.3",
|
"@types/polylabel": "^1.1.3",
|
||||||
"@vitest/browser": "^4.0.18",
|
"@vitest/browser": "^4.0.18",
|
||||||
|
|
@ -1353,6 +1353,7 @@
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/lineclip/-/lineclip-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/lineclip/-/lineclip-2.0.0.tgz",
|
||||||
"integrity": "sha512-LsPRWfV5kC41YgraYhnAMNSNhdJwFlCsUPueSw7sG5UvMqSMxMcaOA9LWN8mZiCUe9jVIAKnLfsNiXpvnd7gKQ==",
|
"integrity": "sha512-LsPRWfV5kC41YgraYhnAMNSNhdJwFlCsUPueSw7sG5UvMqSMxMcaOA9LWN8mZiCUe9jVIAKnLfsNiXpvnd7gKQ==",
|
||||||
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
"@playwright/test": "^1.57.0",
|
"@playwright/test": "^1.57.0",
|
||||||
"@types/d3": "^7.4.3",
|
"@types/d3": "^7.4.3",
|
||||||
"@types/delaunator": "^5.0.3",
|
"@types/delaunator": "^5.0.3",
|
||||||
|
"@types/lineclip": "^2.0.0",
|
||||||
"@types/node": "^25.0.10",
|
"@types/node": "^25.0.10",
|
||||||
"@types/polylabel": "^1.1.3",
|
"@types/polylabel": "^1.1.3",
|
||||||
"@vitest/browser": "^4.0.18",
|
"@vitest/browser": "^4.0.18",
|
||||||
|
|
@ -38,7 +39,6 @@
|
||||||
"vitest": "^4.0.18"
|
"vitest": "^4.0.18"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/lineclip": "^2.0.0",
|
|
||||||
"alea": "^1.0.1",
|
"alea": "^1.0.1",
|
||||||
"d3": "^7.9.0",
|
"d3": "^7.9.0",
|
||||||
"delaunator": "^5.0.1",
|
"delaunator": "^5.0.1",
|
||||||
|
|
|
||||||
|
|
@ -1304,7 +1304,7 @@ class CulturesModule {
|
||||||
cells.culture[cellId] = 0;
|
cells.culture[cellId] = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cells.culture = new Uint16Array(cells.i.length) as unknown as number[];
|
cells.culture = new Uint16Array(cells.i.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const culture of cultures) {
|
for (const culture of cultures) {
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,8 @@ class FeatureModule {
|
||||||
const [startCell, featureVertices] = getCellsData(type, firstCell);
|
const [startCell, featureVertices] = getCellsData(type, firstCell);
|
||||||
const points = clipPoly(
|
const points = clipPoly(
|
||||||
featureVertices.map((vertex: number) => vertices.p[vertex]),
|
featureVertices.map((vertex: number) => vertices.p[vertex]),
|
||||||
|
graphWidth,
|
||||||
|
graphHeight,
|
||||||
);
|
);
|
||||||
const area = polygonArea(points); // feature perimiter area
|
const area = polygonArea(points); // feature perimiter area
|
||||||
const absArea = Math.abs(rn(area));
|
const absArea = Math.abs(rn(area));
|
||||||
|
|
|
||||||
|
|
@ -59,14 +59,12 @@ class Resampler {
|
||||||
grid.cells.temp = new Int8Array(grid.points.length);
|
grid.cells.temp = new Int8Array(grid.points.length);
|
||||||
grid.cells.prec = new Uint8Array(grid.points.length);
|
grid.cells.prec = new Uint8Array(grid.points.length);
|
||||||
|
|
||||||
const parentPackQ = quadtree(parentMap.pack.cells.p.map(([x, y], i) => [x, y, i]));
|
const parentPackQ = quadtree(
|
||||||
|
parentMap.pack.cells.p.map(([x, y], i) => [x, y, i]),
|
||||||
|
);
|
||||||
grid.points.forEach(([x, y]: [number, number], newGridCell: number) => {
|
grid.points.forEach(([x, y]: [number, number], newGridCell: number) => {
|
||||||
const [parentX, parentY] = inverse(x, y);
|
const [parentX, parentY] = inverse(x, y);
|
||||||
const parentPackCell = parentPackQ.find(
|
const parentPackCell = parentPackQ.find(parentX, parentY, Infinity)?.[2];
|
||||||
parentX,
|
|
||||||
parentY,
|
|
||||||
Infinity,
|
|
||||||
)?.[2];
|
|
||||||
if (parentPackCell === undefined) return;
|
if (parentPackCell === undefined) return;
|
||||||
const parentGridCell = parentMap.pack.cells.g[parentPackCell];
|
const parentGridCell = parentMap.pack.cells.g[parentPackCell];
|
||||||
|
|
||||||
|
|
@ -441,16 +439,14 @@ class Resampler {
|
||||||
parentMap: ParentMapDefinition,
|
parentMap: ParentMapDefinition,
|
||||||
inverse: (x: number, y: number) => [number, number],
|
inverse: (x: number, y: number) => [number, number],
|
||||||
) {
|
) {
|
||||||
const parentPackQ = quadtree(parentMap.pack.cells.p.map(([x, y], i) => [x, y, i]));
|
const parentPackQ = quadtree(
|
||||||
|
parentMap.pack.cells.p.map(([x, y], i) => [x, y, i]),
|
||||||
|
);
|
||||||
pack.features.forEach((feature) => {
|
pack.features.forEach((feature) => {
|
||||||
if (!feature) return;
|
if (!feature) return;
|
||||||
const [x, y] = pack.cells.p[feature.firstCell];
|
const [x, y] = pack.cells.p[feature.firstCell];
|
||||||
const [parentX, parentY] = inverse(x, y);
|
const [parentX, parentY] = inverse(x, y);
|
||||||
const parentCell = parentPackQ.find(
|
const parentCell = parentPackQ.find(parentX, parentY, Infinity)?.[2];
|
||||||
parentX,
|
|
||||||
parentY,
|
|
||||||
Infinity,
|
|
||||||
)?.[2];
|
|
||||||
if (parentCell === undefined) return;
|
if (parentCell === undefined) return;
|
||||||
const parentFeature =
|
const parentFeature =
|
||||||
parentMap.pack.features[parentMap.pack.cells.f[parentCell]];
|
parentMap.pack.features[parentMap.pack.cells.f[parentCell]];
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ function featurePathRenderer(feature: PackedGraphFeature): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const simplifiedPoints = simplify(points, 0.3);
|
const simplifiedPoints = simplify(points, 0.3);
|
||||||
const clippedPoints = clipPoly(simplifiedPoints, graphWidth, graphHeight, 1);
|
const clippedPoints = clipPoly(simplifiedPoints, graphWidth, graphHeight);
|
||||||
|
|
||||||
const lineGen = line().curve(curveBasisClosed);
|
const lineGen = line().curve(curveBasisClosed);
|
||||||
const path = `${round(lineGen(clippedPoints) || "")}Z`;
|
const path = `${round(lineGen(clippedPoints) || "")}Z`;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { curveNatural, line, max, select } from "d3";
|
import { curveNatural, line, max, select } from "d3";
|
||||||
|
import type { TypedArray } from "../types/PackedGraph";
|
||||||
import {
|
import {
|
||||||
drawPath,
|
drawPath,
|
||||||
drawPoint,
|
drawPoint,
|
||||||
|
|
@ -400,7 +401,7 @@ const stateLabelsRenderer = (list?: number[]): void => {
|
||||||
angleRad: number,
|
angleRad: number,
|
||||||
halfwidth: number,
|
halfwidth: number,
|
||||||
halfheight: number,
|
halfheight: number,
|
||||||
stateIds: number[],
|
stateIds: TypedArray,
|
||||||
stateId: number,
|
stateId: number,
|
||||||
): boolean {
|
): boolean {
|
||||||
const bbox = textElement.getBBox();
|
const bbox = textElement.getBBox();
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import type { Route } from "../modules/routes-generator";
|
||||||
import type { State } from "../modules/states-generator";
|
import type { State } from "../modules/states-generator";
|
||||||
import type { Zone } from "../modules/zones-generator";
|
import type { Zone } from "../modules/zones-generator";
|
||||||
|
|
||||||
type TypedArray =
|
export type TypedArray =
|
||||||
| Uint8Array
|
| Uint8Array
|
||||||
| Uint16Array
|
| Uint16Array
|
||||||
| Uint32Array
|
| Uint32Array
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import { rand } from "./probabilityUtils";
|
||||||
* @param points - Array of points [[x1, y1], [x2, y2], ...]
|
* @param points - Array of points [[x1, y1], [x2, y2], ...]
|
||||||
* @param graphWidth - Width of the graph
|
* @param graphWidth - Width of the graph
|
||||||
* @param graphHeight - Height of the graph
|
* @param graphHeight - Height of the graph
|
||||||
* @param secure - Secure clipping to avoid edge artifacts
|
|
||||||
* @returns Clipped polygon points
|
* @returns Clipped polygon points
|
||||||
*/
|
*/
|
||||||
export const clipPoly = (
|
export const clipPoly = (
|
||||||
|
|
|
||||||
|
|
@ -228,8 +228,8 @@ import {
|
||||||
wiki,
|
wiki,
|
||||||
} from "./commonUtils";
|
} from "./commonUtils";
|
||||||
|
|
||||||
window.clipPoly = (points: [number, number][], secure?: number) =>
|
window.clipPoly = (points: [number, number][]) =>
|
||||||
clipPoly(points, graphWidth, graphHeight, secure);
|
clipPoly(points, graphWidth, graphHeight);
|
||||||
window.getSegmentId = getSegmentId;
|
window.getSegmentId = getSegmentId;
|
||||||
window.debounce = debounce;
|
window.debounce = debounce;
|
||||||
window.throttle = throttle;
|
window.throttle = throttle;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue