mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
refactor: draw coastline
This commit is contained in:
parent
1888b04d54
commit
4833a8ab35
8 changed files with 422 additions and 371 deletions
50
src/layers/renderers/drawCoastline.ts
Normal file
50
src/layers/renderers/drawCoastline.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import * as d3 from "d3";
|
||||
|
||||
import {simplify} from "scripts/simplify";
|
||||
import {clipPoly} from "utils/lineUtils";
|
||||
import {round} from "utils/stringUtils";
|
||||
|
||||
export function drawCoastline(vertices: IGraphVertices, features: TPackFeatures) {
|
||||
const landMask = defs.select("#land");
|
||||
const waterMask = defs.select("#water");
|
||||
|
||||
const lineGen = d3.line().curve(d3.curveBasisClosed);
|
||||
const SIMPLIFICATION_TOLERANCE = 0.5; // px
|
||||
|
||||
for (const feature of features) {
|
||||
if (!feature) continue;
|
||||
|
||||
const points = clipPoly(feature.vertices.map(vertex => vertices.p[vertex]));
|
||||
const simplifiedPoints = simplify(points, SIMPLIFICATION_TOLERANCE);
|
||||
const path = round(lineGen(simplifiedPoints)!);
|
||||
|
||||
landMask
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("fill", "black")
|
||||
.attr("id", "land_" + feature.i);
|
||||
|
||||
if (feature.type === "lake") {
|
||||
lakes
|
||||
.select("#freshwater")
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("id", "lake_" + feature.i)
|
||||
.attr("data-f", feature.i);
|
||||
} else {
|
||||
waterMask
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("fill", "black")
|
||||
.attr("id", "water_" + feature.i);
|
||||
|
||||
const group = feature.group === "lake_island" ? "lake_island" : "sea_island";
|
||||
coastline
|
||||
.select("#" + group)
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("id", "island_" + feature.i)
|
||||
.attr("data-f", feature.i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ import {TIME} from "config/logging";
|
|||
import {drawBiomes} from "./drawBiomes";
|
||||
import {drawBorders} from "./drawBorders";
|
||||
import {drawCells} from "./drawCells";
|
||||
import {drawCoastline} from "./drawCoastline";
|
||||
import {drawCoordinates} from "./drawCoordinates";
|
||||
import {drawCultures} from "./drawCultures";
|
||||
import {drawEmblems} from "./drawEmblems";
|
||||
|
|
@ -23,6 +24,7 @@ const layerRenderersMap = {
|
|||
biomes: drawBiomes,
|
||||
borders: drawBorders,
|
||||
cells: drawCells,
|
||||
coastline: drawCoastline,
|
||||
coordinates: drawCoordinates,
|
||||
cultures: drawCultures,
|
||||
emblems: drawEmblems,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue