diff --git a/index.html b/index.html index aea12cc9..c3b4e7d3 100644 --- a/index.html +++ b/index.html @@ -7664,7 +7664,6 @@ - diff --git a/src/modules/burgs-and-states.js b/src/modules/burgs-and-states.js index 07601977..509a8089 100644 --- a/src/modules/burgs-and-states.js +++ b/src/modules/burgs-and-states.js @@ -7,6 +7,7 @@ import {rn, minmax} from "/src/utils/numberUtils"; import {rand, P, each, gauss, ra, rw, generateSeed} from "/src/utils/probabilityUtils"; import {round, splitInTwo} from "/src/utils/stringUtils"; import {trimVowels, getAdjective} from "/src/utils/languageUtils"; +import {Voronoi} from "/src/modules/voronoi"; window.BurgsAndStates = (function () { const generate = function () { diff --git a/src/modules/ui/options.js b/src/modules/ui/options.js index d34dc235..0e2f1d0c 100644 --- a/src/modules/ui/options.js +++ b/src/modules/ui/options.js @@ -1,10 +1,10 @@ import {applyOption} from "./general"; -import {last} from "/src/utils/arrayUtils"; import {lock, locked} from "/src/scripts/options/lock"; -import {tip, clearMainTip} from "/src/scripts/tooltips"; +import {clearMainTip, tip} from "/src/scripts/tooltips"; +import {last} from "/src/utils/arrayUtils"; +import {minmax, rn} from "/src/utils/numberUtils"; +import {gauss, P, rand, rw} from "/src/utils/probabilityUtils"; import {byId, stored} from "/src/utils/shorthands"; -import {rn, minmax} from "/src/utils/numberUtils"; -import {rand, P, gauss} from "/src/utils/probabilityUtils"; $("#optionsContainer").draggable({handle: ".drag-trigger", snap: "svg", snapMode: "both"}); $("#exitCustomization").draggable({handle: "div"}); diff --git a/src/modules/voronoi.js b/src/modules/voronoi.js index 19581c9d..8a389c56 100644 --- a/src/modules/voronoi.js +++ b/src/modules/voronoi.js @@ -1,4 +1,4 @@ -class Voronoi { +export class Voronoi { /** * Creates a Voronoi diagram from the given Delaunator, a list of points, and the number of points. The Voronoi diagram is constructed using (I think) the {@link https://en.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm |Bowyer-Watson Algorithm} * The {@link https://github.com/mapbox/delaunator/ |Delaunator} library uses {@link https://en.wikipedia.org/wiki/Doubly_connected_edge_list |half-edges} to represent the relationship between points and triangles. @@ -10,27 +10,26 @@ class Voronoi { this.delaunay = delaunay; this.points = points; this.pointsN = pointsN; - this.cells = { v: [], c: [], b: [] }; // voronoi cells: v = cell vertices, c = adjacent cells, b = near-border cell - this.vertices = { p: [], v: [], c: [] }; // cells vertices: p = vertex coordinates, v = neighboring vertices, c = adjacent cells + this.cells = {v: [], c: [], b: []}; // voronoi cells: v = cell vertices, c = adjacent cells, b = near-border cell + this.vertices = {p: [], v: [], c: []}; // cells vertices: p = vertex coordinates, v = neighboring vertices, c = adjacent cells // Half-edges are the indices into the delaunator outputs: // delaunay.triangles[e] gives the point ID where the half-edge starts // delaunay.halfedges[e] returns either the opposite half-edge in the adjacent triangle, or -1 if there's not an adjacent triangle. for (let e = 0; e < this.delaunay.triangles.length; e++) { - const p = this.delaunay.triangles[this.nextHalfedge(e)]; if (p < this.pointsN && !this.cells.c[p]) { const edges = this.edgesAroundPoint(e); - this.cells.v[p] = edges.map(e => this.triangleOfEdge(e)); // cell: adjacent vertex + this.cells.v[p] = edges.map(e => this.triangleOfEdge(e)); // cell: adjacent vertex this.cells.c[p] = edges.map(e => this.delaunay.triangles[e]).filter(c => c < this.pointsN); // cell: adjacent valid cells - this.cells.b[p] = edges.length > this.cells.c[p].length ? 1 : 0; // cell: is border + this.cells.b[p] = edges.length > this.cells.c[p].length ? 1 : 0; // cell: is border } const t = this.triangleOfEdge(e); if (!this.vertices.p[t]) { - this.vertices.p[t] = this.triangleCenter(t); // vertex: coordinates + this.vertices.p[t] = this.triangleCenter(t); // vertex: coordinates this.vertices.v[t] = this.trianglesAdjacentToTriangle(t); // vertex: adjacent vertices - this.vertices.c[t] = this.pointsOfTriangle(t); // vertex: adjacent cells + this.vertices.c[t] = this.pointsOfTriangle(t); // vertex: adjacent cells } } } @@ -89,28 +88,36 @@ class Voronoi { * @param {number} t The index of the triangle * @returns {[number, number, number]} The edges of the triangle. */ - edgesOfTriangle(t) { return [3 * t, 3 * t + 1, 3 * t + 2]; } + edgesOfTriangle(t) { + return [3 * t, 3 * t + 1, 3 * t + 2]; + } /** * Enables lookup of a triangle, given one of the half-edges of that triangle. Taken from {@link https://mapbox.github.io/delaunator/#edge-and-triangle| the Delaunator docs.} * @param {number} e The index of the edge * @returns {number} The index of the triangle */ - triangleOfEdge(e) { return Math.floor(e / 3); } + triangleOfEdge(e) { + return Math.floor(e / 3); + } /** * Moves to the next half-edge of a triangle, given the current half-edge's index. Taken from {@link https://mapbox.github.io/delaunator/#edge-to-edges| the Delaunator docs.} * @param {number} e The index of the current half edge * @returns {number} The index of the next half edge */ - nextHalfedge(e) { return (e % 3 === 2) ? e - 2 : e + 1; } + nextHalfedge(e) { + return e % 3 === 2 ? e - 2 : e + 1; + } /** * Moves to the previous half-edge of a triangle, given the current half-edge's index. Taken from {@link https://mapbox.github.io/delaunator/#edge-to-edges| the Delaunator docs.} * @param {number} e The index of the current half edge * @returns {number} The index of the previous half edge */ - prevHalfedge(e) { return (e % 3 === 0) ? e + 2 : e - 1; } + prevHalfedge(e) { + return e % 3 === 0 ? e + 2 : e - 1; + } /** * Finds the circumcenter of the triangle identified by points a, b, and c. Taken from {@link https://en.wikipedia.org/wiki/Circumscribed_circle#Circumcenter_coordinates| Wikipedia} @@ -128,8 +135,8 @@ class Voronoi { const cd = cx * cx + cy * cy; const D = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)); return [ - Math.floor(1 / D * (ad * (by - cy) + bd * (cy - ay) + cd * (ay - by))), - Math.floor(1 / D * (ad * (cx - bx) + bd * (ax - cx) + cd * (bx - ax))) + Math.floor((1 / D) * (ad * (by - cy) + bd * (cy - ay) + cd * (ay - by))), + Math.floor((1 / D) * (ad * (cx - bx) + bd * (ax - cx) + cd * (bx - ax))) ]; } } diff --git a/src/utils/arrayUtils.ts b/src/utils/arrayUtils.ts index f23e2fa4..9fead55d 100644 --- a/src/utils/arrayUtils.ts +++ b/src/utils/arrayUtils.ts @@ -1,4 +1,4 @@ -import {UINT8_MAX, UINT16_MAX, UINT32_MAX} from "../constants"; +import {UINT16_MAX, UINT32_MAX, UINT8_MAX} from "../constants"; export function last(array: T[]) { return array[array.length - 1]; diff --git a/src/utils/graphUtils.ts b/src/utils/graphUtils.ts index 7490ac65..5d5fb38d 100644 --- a/src/utils/graphUtils.ts +++ b/src/utils/graphUtils.ts @@ -3,9 +3,9 @@ import {TIME} from "../config/logging"; import {createTypedArray} from "./arrayUtils"; import {rn} from "./numberUtils"; import {byId} from "./shorthands"; +import {Voronoi} from "/src/modules/voronoi"; const Delaunator = window.Delaunator; -const Voronoi = window.Voronoi; const graphWidth = window.graphWidth; const graphHeight = window.graphHeight; diff --git a/tsconfig.json b/tsconfig.json index 26af30b9..3adf2c27 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,11 +14,8 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, - "skipLibCheck": true - // "baseUrl": ".", - // "paths": { - // "@/*": ["./src/*"] - // } + "skipLibCheck": true, + "baseUrl": "src" }, "include": ["src"] } diff --git a/vite.config.js b/vite.config.js index e0f8fd4a..7033e2e7 100644 --- a/vite.config.js +++ b/vite.config.js @@ -3,23 +3,12 @@ // import path from "path"; // const pathName = path.dirname(fileURLToPath(import.meta.url)); -// const resolved = path.resolve(pathName, "./src"); // export default defineConfig({ // // base: "/Fantasy-Map-Generator/", // resolve: { -// alias: { -// // "@": path.resolve(pathName, "./src") -// // "@": path.resolve(path.dirname(fileURLToPath(import.meta.url)), "./src") -// // "@": path.resolve(path.dirname(fileURLToPath(import.meta.url)), "/src") -// // { -// // find: "@", -// // replacement: path.resolve(pathName, "./src"), -// // customResolver: request => { -// // console.log(request); -// // return request; -// // } -// // } -// } +// alias: [ +// {find: "@", replacement: path.resolve(pathName, "./src")} +// ] // } // });