mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
* chore: add npm + vite for progressive enhancement * fix: update Dockerfile to copy only the dist folder contents * fix: update Dockerfile to use multi-stage build for optimized production image * fix: correct nginx config file copy command in Dockerfile * chore: add netlify configuration for build and redirects * fix: add NODE_VERSION to environment in Netlify configuration * remove wrong dist folder * Update package.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: split public and src * migrating all util files from js to ts * feat: Implement HeightmapGenerator and Voronoi module - Added HeightmapGenerator class for generating heightmaps with various tools (Hill, Pit, Range, Trough, Strait, etc.). - Introduced Voronoi class for creating Voronoi diagrams using Delaunator. - Updated index.html to include new modules. - Created index.ts to manage module imports. - Enhanced arrayUtils and graphUtils with type definitions and improved functionality. - Added utility functions for generating grids and calculating Voronoi cells. * chore: add GitHub Actions workflow for deploying to GitHub Pages * fix: update branch name in GitHub Actions workflow from 'main' to 'master' * chore: update package.json to specify Node.js engine version and remove unused launch.json * Initial plan * Update copilot guidelines to reflect NPM/Vite/TypeScript migration Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> * Update src/modules/heightmap-generator.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/utils/graphUtils.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/heightmap-generator.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * feat: Add TIME and ERROR variables to global scope in HeightmapGenerator * fix: Update base path in vite.config.ts for Netlify deployment * fix: Update Node.js version in Dockerfile to 24-alpine --------- Co-authored-by: Marc Emmanuel <marc.emmanuel@tado.com> Co-authored-by: Marc Emmanuel <marcwissler@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
103 lines
2.6 KiB
JavaScript
103 lines
2.6 KiB
JavaScript
/*
|
|
(c) 2017, Vladimir Agafonkin
|
|
Simplify.js, a high-performance JS polyline simplification library
|
|
mourner.github.io/simplify-js
|
|
*/
|
|
{
|
|
// square distance between 2 points
|
|
function getSqDist([x1, y1], [x2, y2]) {
|
|
const dx = x1 - x2;
|
|
const dy = y1 - y2;
|
|
|
|
return dx * dx + dy * dy;
|
|
}
|
|
|
|
// square distance from a point to a segment
|
|
function getSqSegDist([x1, y1], [x, y], [x2, y2]) {
|
|
let dx = x2 - x;
|
|
let dy = y2 - y;
|
|
|
|
if (dx !== 0 || dy !== 0) {
|
|
const t = ((x1 - x) * dx + (y1 - y) * dy) / (dx * dx + dy * dy);
|
|
|
|
if (t > 1) {
|
|
x = x2;
|
|
y = y2;
|
|
} else if (t > 0) {
|
|
x += dx * t;
|
|
y += dy * t;
|
|
}
|
|
}
|
|
|
|
dx = x1 - x;
|
|
dy = y1 - y;
|
|
|
|
return dx * dx + dy * dy;
|
|
}
|
|
// rest of the code doesn't care about point format
|
|
|
|
// basic distance-based simplification
|
|
function simplifyRadialDist(points, sqTolerance) {
|
|
let prevPoint = points[0];
|
|
const newPoints = [prevPoint];
|
|
let point;
|
|
|
|
for (let i = 1; i < points.length; i++) {
|
|
point = points[i];
|
|
if (!point) continue;
|
|
|
|
if (getSqDist(point, prevPoint) > sqTolerance) {
|
|
newPoints.push(point);
|
|
prevPoint = point;
|
|
}
|
|
}
|
|
|
|
if (prevPoint !== point) newPoints.push(point);
|
|
return newPoints;
|
|
}
|
|
|
|
function simplifyDPStep(points, first, last, sqTolerance, simplified) {
|
|
let maxSqDist = sqTolerance;
|
|
let index = first;
|
|
|
|
for (let i = first + 1; i < last; i++) {
|
|
const sqDist = getSqSegDist(points[i], points[first], points[last]);
|
|
|
|
if (sqDist > maxSqDist) {
|
|
index = i;
|
|
maxSqDist = sqDist;
|
|
}
|
|
}
|
|
|
|
if (maxSqDist > sqTolerance) {
|
|
if (index - first > 1) simplifyDPStep(points, first, index, sqTolerance, simplified);
|
|
simplified.push(points[index]);
|
|
if (last - index > 1) simplifyDPStep(points, index, last, sqTolerance, simplified);
|
|
}
|
|
}
|
|
|
|
// simplification using Ramer-Douglas-Peucker algorithm
|
|
function simplifyDouglasPeucker(points, sqTolerance) {
|
|
const last = points.length - 1;
|
|
|
|
const simplified = [points[0]];
|
|
simplifyDPStep(points, 0, last, sqTolerance, simplified);
|
|
simplified.push(points[last]);
|
|
|
|
return simplified;
|
|
}
|
|
|
|
// both algorithms combined for awesome performance
|
|
function simplify(points, tolerance, highestQuality = false) {
|
|
if (points.length <= 2) return points;
|
|
|
|
const sqTolerance = tolerance * tolerance;
|
|
|
|
points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
|
|
points = simplifyDouglasPeucker(points, sqTolerance);
|
|
|
|
return points;
|
|
}
|
|
|
|
window.simplify = simplify;
|
|
}
|