mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
fix: skip coastline out points wip
This commit is contained in:
parent
3215b6f0d2
commit
19d7f239c1
9 changed files with 262 additions and 64 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import * as d3 from "d3";
|
||||
|
||||
import {simplify} from "scripts/simplify";
|
||||
import {clipPoly} from "utils/lineUtils";
|
||||
import {filterOutOfCanvasPoints} from "utils/lineUtils";
|
||||
import {round} from "utils/stringUtils";
|
||||
|
||||
export function drawCoastline(vertices: IGraphVertices, features: TPackFeatures) {
|
||||
|
|
@ -11,14 +11,38 @@ export function drawCoastline(vertices: IGraphVertices, features: TPackFeatures)
|
|||
const lineGen = d3.line().curve(d3.curveBasisClosed);
|
||||
const SIMPLIFICATION_TOLERANCE = 0.5; // px
|
||||
|
||||
// map edge rectangle
|
||||
debug
|
||||
.append("rect")
|
||||
.attr("x", 0)
|
||||
.attr("y", 0)
|
||||
.attr("width", graphWidth)
|
||||
.attr("height", graphHeight)
|
||||
.attr("fill", "none")
|
||||
.attr("stroke", "black")
|
||||
.attr("stroke-width", 0.1);
|
||||
|
||||
for (const feature of features) {
|
||||
if (!feature) continue;
|
||||
if (feature.type === "ocean") continue;
|
||||
|
||||
const points = clipPoly(feature.vertices.map(vertex => vertices.p[vertex]));
|
||||
const simplifiedPoints = simplify(points, SIMPLIFICATION_TOLERANCE);
|
||||
const points = feature.vertices.map(vertex => vertices.p[vertex]);
|
||||
const filteredPoints = filterOutOfCanvasPoints(points);
|
||||
const simplifiedPoints = simplify(filteredPoints, SIMPLIFICATION_TOLERANCE);
|
||||
const path = round(lineGen(simplifiedPoints)!);
|
||||
|
||||
points.forEach(([x, y]) => {
|
||||
debug.append("circle").attr("cx", x).attr("cy", y).attr("r", 0.3).attr("fill", "red");
|
||||
});
|
||||
|
||||
filteredPoints.forEach(([x, y]) => {
|
||||
debug.append("circle").attr("cx", x).attr("cy", y).attr("r", 0.3).attr("fill", "blue");
|
||||
});
|
||||
|
||||
simplifiedPoints.forEach(([x, y]) => {
|
||||
debug.append("circle").attr("cx", x).attr("cy", y).attr("r", 0.3).attr("fill", "green");
|
||||
});
|
||||
|
||||
if (feature.type === "lake") {
|
||||
landMask
|
||||
.append("path")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue