mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-04-03 22:17:24 +02:00
refactor: migrate resample module (#1351)
* refactor: resampling functionality * fix: type issues * fix: reorder polyfills import in index.ts * refactor: reorder exports in index.ts for consistency
This commit is contained in:
parent
3f9a7702d4
commit
f2fc42799b
20 changed files with 601 additions and 417 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { clipPolygon } from "lineclip";
|
||||
import { last } from "./arrayUtils";
|
||||
import { distanceSquared } from "./functionUtils";
|
||||
import { rn } from "./numberUtils";
|
||||
|
|
@ -8,14 +9,12 @@ import { rand } from "./probabilityUtils";
|
|||
* @param points - Array of points [[x1, y1], [x2, y2], ...]
|
||||
* @param graphWidth - Width of the graph
|
||||
* @param graphHeight - Height of the graph
|
||||
* @param secure - Secure clipping to avoid edge artifacts
|
||||
* @returns Clipped polygon points
|
||||
*/
|
||||
export const clipPoly = (
|
||||
points: [number, number][],
|
||||
graphWidth?: number,
|
||||
graphHeight?: number,
|
||||
secure: number = 0,
|
||||
graphWidth: number,
|
||||
graphHeight: number,
|
||||
) => {
|
||||
if (points.length < 2) return points;
|
||||
if (points.some((point) => point === undefined)) {
|
||||
|
|
@ -23,7 +22,7 @@ export const clipPoly = (
|
|||
return points;
|
||||
}
|
||||
|
||||
return window.polygonclip(points, [0, 0, graphWidth, graphHeight], secure);
|
||||
return clipPolygon(points, [0, 0, graphWidth, graphHeight]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -375,7 +374,6 @@ export const initializePrompt = (): void => {
|
|||
declare global {
|
||||
interface Window {
|
||||
ERROR: boolean;
|
||||
polygonclip: any;
|
||||
|
||||
clipPoly: typeof clipPoly;
|
||||
getSegmentId: typeof getSegmentId;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import {
|
|||
type Vertices,
|
||||
Voronoi,
|
||||
} from "../modules/voronoi";
|
||||
import type { PackedGraph } from "../types/PackedGraph";
|
||||
import { createTypedArray } from "./arrayUtils";
|
||||
import { rn } from "./numberUtils";
|
||||
import { byId } from "./shorthands";
|
||||
|
|
@ -541,7 +542,7 @@ export function* poissonDiscSampler(
|
|||
* @param {number} i - The index of the packed cell
|
||||
* @returns {boolean} - True if the cell is land, false otherwise
|
||||
*/
|
||||
export const isLand = (i: number, packedGraph: any) => {
|
||||
export const isLand = (i: number, packedGraph: PackedGraph) => {
|
||||
return packedGraph.cells.h[i] >= 20;
|
||||
};
|
||||
|
||||
|
|
@ -550,7 +551,7 @@ export const isLand = (i: number, packedGraph: any) => {
|
|||
* @param {number} i - The index of the packed cell
|
||||
* @returns {boolean} - True if the cell is water, false otherwise
|
||||
*/
|
||||
export const isWater = (i: number, packedGraph: any) => {
|
||||
export const isWater = (i: number, packedGraph: PackedGraph) => {
|
||||
return packedGraph.cells.h[i] < 20;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import "./polyfills";
|
||||
|
||||
import { lerp, lim, minmax, normalize, rn } from "./numberUtils";
|
||||
import "./polyfills";
|
||||
|
||||
window.rn = rn;
|
||||
window.lim = lim;
|
||||
|
|
@ -228,8 +227,8 @@ import {
|
|||
wiki,
|
||||
} from "./commonUtils";
|
||||
|
||||
window.clipPoly = (points: [number, number][], secure?: number) =>
|
||||
clipPoly(points, graphWidth, graphHeight, secure);
|
||||
window.clipPoly = (points: [number, number][]) =>
|
||||
clipPoly(points, graphWidth, graphHeight);
|
||||
window.getSegmentId = getSegmentId;
|
||||
window.debounce = debounce;
|
||||
window.throttle = throttle;
|
||||
|
|
@ -336,9 +335,9 @@ export {
|
|||
nth,
|
||||
openURL,
|
||||
P,
|
||||
Pint,
|
||||
parseError,
|
||||
parseTransform,
|
||||
Pint,
|
||||
poissonDiscSampler,
|
||||
ra,
|
||||
rand,
|
||||
|
|
@ -351,10 +350,10 @@ export {
|
|||
shouldRegenerateGrid,
|
||||
si,
|
||||
splitInTwo,
|
||||
TYPED_ARRAY_MAX_VALUES,
|
||||
throttle,
|
||||
toHEX,
|
||||
trimVowels,
|
||||
TYPED_ARRAY_MAX_VALUES,
|
||||
unique,
|
||||
wiki,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue