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 * refactor: Migrate features to a new module and remove legacy script reference * refactor: Update feature interfaces and improve type safety in FeatureModule * refactor: Add documentation for markupPack and defineGroups methods in FeatureModule * refactor: Remove legacy ocean-layers.js and migrate functionality to ocean-layers.ts * refactor: Remove river-generator.js script reference and migrate river generation logic to river-generator.ts * refactor: Remove river-generator.js reference and add biomes module * refactor: Migrate lakes functionality to lakes.ts and update related interfaces * refactor: clean up global variable declarations and improve type definitions * refactor: update shoreline calculation and improve type imports in PackedGraph * fix: e2e tests * chore: add biome for linting/formatting * chore: add linting workflow using Biome * refactor: improve code readability by standardizing string quotes and simplifying function calls --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <maxganiev@yandex.com> Co-authored-by: Azgaar <azgaar.fmg@yandex.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
138 lines
3.8 KiB
TypeScript
138 lines
3.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { getCoordinates, getLatitude, getLongitude } from "./commonUtils";
|
|
|
|
describe("getLongitude", () => {
|
|
const mapCoordinates = { lonW: -10, lonT: 20 };
|
|
const graphWidth = 1000;
|
|
|
|
it("should calculate longitude at the left edge (x=0)", () => {
|
|
expect(getLongitude(0, mapCoordinates, graphWidth, 2)).toBe(-10);
|
|
});
|
|
|
|
it("should calculate longitude at the right edge (x=graphWidth)", () => {
|
|
expect(getLongitude(1000, mapCoordinates, graphWidth, 2)).toBe(10);
|
|
});
|
|
|
|
it("should calculate longitude at the center (x=graphWidth/2)", () => {
|
|
expect(getLongitude(500, mapCoordinates, graphWidth, 2)).toBe(0);
|
|
});
|
|
|
|
it("should respect decimal precision", () => {
|
|
// 333/1000 * 20 = 6.66, -10 + 6.66 = -3.34
|
|
expect(getLongitude(333, mapCoordinates, graphWidth, 4)).toBe(-3.34);
|
|
});
|
|
|
|
it("should handle different map coordinate ranges", () => {
|
|
const wideMap = { lonW: -180, lonT: 360 };
|
|
expect(getLongitude(500, wideMap, graphWidth, 2)).toBe(0);
|
|
expect(getLongitude(0, wideMap, graphWidth, 2)).toBe(-180);
|
|
expect(getLongitude(1000, wideMap, graphWidth, 2)).toBe(180);
|
|
});
|
|
});
|
|
|
|
describe("getLatitude", () => {
|
|
const mapCoordinates = { latN: 60, latT: 40 };
|
|
const graphHeight = 800;
|
|
|
|
it("should calculate latitude at the top edge (y=0)", () => {
|
|
expect(getLatitude(0, mapCoordinates, graphHeight, 2)).toBe(60);
|
|
});
|
|
|
|
it("should calculate latitude at the bottom edge (y=graphHeight)", () => {
|
|
expect(getLatitude(800, mapCoordinates, graphHeight, 2)).toBe(20);
|
|
});
|
|
|
|
it("should calculate latitude at the center (y=graphHeight/2)", () => {
|
|
expect(getLatitude(400, mapCoordinates, graphHeight, 2)).toBe(40);
|
|
});
|
|
|
|
it("should respect decimal precision", () => {
|
|
// 60 - (333/800 * 40) = 60 - 16.65 = 43.35
|
|
expect(getLatitude(333, mapCoordinates, graphHeight, 4)).toBe(43.35);
|
|
});
|
|
|
|
it("should handle equator-centered maps", () => {
|
|
const equatorMap = { latN: 45, latT: 90 };
|
|
expect(getLatitude(400, equatorMap, graphHeight, 2)).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe("getCoordinates", () => {
|
|
const mapCoordinates = { lonW: -10, lonT: 20, latN: 60, latT: 40 };
|
|
const graphWidth = 1000;
|
|
const graphHeight = 800;
|
|
|
|
it("should return [longitude, latitude] tuple", () => {
|
|
const result = getCoordinates(
|
|
500,
|
|
400,
|
|
mapCoordinates,
|
|
graphWidth,
|
|
graphHeight,
|
|
2,
|
|
);
|
|
expect(result).toEqual([0, 40]);
|
|
});
|
|
|
|
it("should calculate coordinates at top-left corner", () => {
|
|
const result = getCoordinates(
|
|
0,
|
|
0,
|
|
mapCoordinates,
|
|
graphWidth,
|
|
graphHeight,
|
|
2,
|
|
);
|
|
expect(result).toEqual([-10, 60]);
|
|
});
|
|
|
|
it("should calculate coordinates at bottom-right corner", () => {
|
|
const result = getCoordinates(
|
|
1000,
|
|
800,
|
|
mapCoordinates,
|
|
graphWidth,
|
|
graphHeight,
|
|
2,
|
|
);
|
|
expect(result).toEqual([10, 20]);
|
|
});
|
|
|
|
it("should respect decimal precision for both coordinates", () => {
|
|
const result = getCoordinates(
|
|
333,
|
|
333,
|
|
mapCoordinates,
|
|
graphWidth,
|
|
graphHeight,
|
|
4,
|
|
);
|
|
expect(result[0]).toBe(-3.34); // longitude
|
|
expect(result[1]).toBe(43.35); // latitude
|
|
});
|
|
|
|
it("should use default precision of 2 decimals", () => {
|
|
const result = getCoordinates(
|
|
333,
|
|
333,
|
|
mapCoordinates,
|
|
graphWidth,
|
|
graphHeight,
|
|
);
|
|
expect(result[0]).toBe(-3.34);
|
|
expect(result[1]).toBe(43.35);
|
|
});
|
|
|
|
it("should handle global map coordinates", () => {
|
|
const globalMap = { lonW: -180, lonT: 360, latN: 90, latT: 180 };
|
|
const result = getCoordinates(
|
|
500,
|
|
400,
|
|
globalMap,
|
|
graphWidth,
|
|
graphHeight,
|
|
2,
|
|
);
|
|
expect(result).toEqual([0, 0]); // center of the world
|
|
});
|
|
});
|