mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
fix: clip by bbox
This commit is contained in:
parent
392cc24f7c
commit
9bd90e51d9
6 changed files with 7 additions and 19 deletions
|
|
@ -18,10 +18,7 @@ export function drawBiomes() {
|
||||||
const edgeVerticle = cells.v[i].find(v => vertices.c[v].some(i => cells.biome[i] !== b));
|
const edgeVerticle = cells.v[i].find(v => vertices.c[v].some(i => cells.biome[i] !== b));
|
||||||
const chain = connectVertices(edgeVerticle, b);
|
const chain = connectVertices(edgeVerticle, b);
|
||||||
if (chain.length < 3) continue;
|
if (chain.length < 3) continue;
|
||||||
const points = clipPoly(
|
const points = clipPoly(chain.map(v => vertices.p[v]));
|
||||||
chain.map(v => vertices.p[v]),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
paths[b] += "M" + points.join("L") + "Z";
|
paths[b] += "M" + points.join("L") + "Z";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,7 @@ export function drawCoastline() {
|
||||||
let vchain = connectVertices(start, type);
|
let vchain = connectVertices(start, type);
|
||||||
if (features[f].type === "lake") relax(vchain, 1.2);
|
if (features[f].type === "lake") relax(vchain, 1.2);
|
||||||
used[f] = 1;
|
used[f] = 1;
|
||||||
let points = clipPoly(
|
let points = clipPoly(vchain.map(v => vertices.p[v]));
|
||||||
vchain.map(v => vertices.p[v]),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
const area = d3.polygonArea(points); // area with lakes/islands
|
const area = d3.polygonArea(points); // area with lakes/islands
|
||||||
if (area > 0 && features[f].type === "lake") {
|
if (area > 0 && features[f].type === "lake") {
|
||||||
points = points.reverse();
|
points = points.reverse();
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,7 @@ window.OceanLayers = (function () {
|
||||||
const relax = 1 + t * -2; // select only n-th point
|
const relax = 1 + t * -2; // select only n-th point
|
||||||
const relaxed = chain.filter((v, i) => !(i % relax) || vertices.c[v].some(c => c >= pointsN));
|
const relaxed = chain.filter((v, i) => !(i % relax) || vertices.c[v].some(c => c >= pointsN));
|
||||||
if (relaxed.length < 4) continue;
|
if (relaxed.length < 4) continue;
|
||||||
const points = clipPoly(
|
const points = clipPoly(relaxed.map(v => vertices.p[v]));
|
||||||
relaxed.map(v => vertices.p[v]),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
chains.push([t, points]);
|
chains.push([t, points]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,10 +90,7 @@ export function editCoastline(node = d3.event.target) {
|
||||||
function redrawCoastline() {
|
function redrawCoastline() {
|
||||||
const f = +elSelected.attr("data-f");
|
const f = +elSelected.attr("data-f");
|
||||||
const vertices = pack.features[f].vertices;
|
const vertices = pack.features[f].vertices;
|
||||||
const points = clipPoly(
|
const points = clipPoly(vertices.map(v => pack.vertices.p[v]));
|
||||||
vertices.map(v => pack.vertices.p[v]),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
const d = round(lineGen(points));
|
const d = round(lineGen(points));
|
||||||
elSelected.attr("d", d);
|
elSelected.attr("d", d);
|
||||||
defs.select("mask#land > path#land_" + f).attr("d", d); // update land mask
|
defs.select("mask#land > path#land_" + f).attr("d", d); // update land mask
|
||||||
|
|
|
||||||
4
src/types/modules.d.ts
vendored
4
src/types/modules.d.ts
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
declare module "lineclip" {
|
declare module "lineclip" {
|
||||||
export function polygon(points: number[][], bbox: number[], result?: number[][]): number[][];
|
export function polygon(points: number[][], bbox: number[]): number[][];
|
||||||
export function lineclip(points: number[][], bbox: number[]): number[][];
|
export function lineclip(points: number[][], bbox: number[], result: number[][]): number[][];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import {polygon} from "lineclip";
|
||||||
|
|
||||||
// clip polygon by graph bbox
|
// clip polygon by graph bbox
|
||||||
export function clipPoly(points: TPoints) {
|
export function clipPoly(points: TPoints) {
|
||||||
return polygon(points, [0, 0, graphWidth, graphWidth]);
|
return polygon(points, [0, 0, graphWidth, graphHeight]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get segment of any point on polyline
|
// get segment of any point on polyline
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue