refactor(es modules): set src as TS base folder

This commit is contained in:
Azgaar 2022-06-27 01:22:30 +03:00
parent 0d05e1b250
commit 32d7db765d
8 changed files with 33 additions and 40 deletions

View file

@ -7664,7 +7664,6 @@
<script src="/src/libs/priority-queue.min.js"></script>
<script src="/src/libs/delaunator.min.js"></script>
<script src="/src/modules/voronoi.js"></script>
<script src="/src/config/heightmap-templates.js"></script>
<script src="/src/config/precreated-heightmaps.js"></script>
<script type="module" src="/src/modules/heightmap-generator.js"></script>

View file

@ -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 () {

View file

@ -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"});

View file

@ -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)))
];
}
}

View file

@ -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<T>(array: T[]) {
return array[array.length - 1];

View file

@ -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;

View file

@ -14,11 +14,8 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true
// "baseUrl": ".",
// "paths": {
// "@/*": ["./src/*"]
// }
"skipLibCheck": true,
"baseUrl": "src"
},
"include": ["src"]
}

View file

@ -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")}
// ]
// }
// });