mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
fix: drawCoastline - detect first vertex based on neibs first
This commit is contained in:
parent
cc3c06f595
commit
4a15dc3243
5 changed files with 31 additions and 23 deletions
|
|
@ -71,20 +71,20 @@ function findStartingVertex({
|
|||
const neibCells = cells.c[startingCell];
|
||||
const cellVertices = cells.v[startingCell];
|
||||
|
||||
const otherFeatureNeibs = neibCells.filter(neibCell => featureIds[neibCell] !== featureId);
|
||||
if (otherFeatureNeibs.length) {
|
||||
const index = neibCells.indexOf(Math.min(...otherFeatureNeibs)!);
|
||||
return cellVertices[index];
|
||||
}
|
||||
|
||||
const externalVertex = cellVertices.find(vertex => {
|
||||
const [x, y] = vertices.p[vertex];
|
||||
if (x < 0 || y < 0) return true;
|
||||
if (x < 0 || y < 0 || x > graphWidth || y > graphHeight) return true;
|
||||
return vertices.c[vertex].some((cellId: number) => cellId >= packCellsNumber);
|
||||
});
|
||||
if (externalVertex !== undefined) return externalVertex;
|
||||
|
||||
const otherFeatureNeibs = neibCells.filter(neibCell => featureIds[neibCell] !== featureId);
|
||||
if (!otherFeatureNeibs.length) {
|
||||
throw new Error(`Markup: firstCell ${startingCell} of feature ${featureId} has no neighbors of other features`);
|
||||
}
|
||||
|
||||
const index = neibCells.indexOf(Math.min(...otherFeatureNeibs)!);
|
||||
return cellVertices[index];
|
||||
throw new Error(`Markup: firstCell of feature ${featureId} has no neighbors of other features or external vertices`);
|
||||
}
|
||||
|
||||
const CONNECT_VERTICES_MAX_ITERATIONS = 50000;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ async function generate(options?: IGenerationOptions) {
|
|||
pack = newPack;
|
||||
|
||||
// temp rendering for debug
|
||||
renderLayer("cells");
|
||||
renderLayer("coastline", pack.vertices, pack.features);
|
||||
renderLayer("heightmap");
|
||||
renderLayer("rivers", pack);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue