fix: features - define first cell

This commit is contained in:
Azgaar 2024-09-22 13:04:22 +02:00
parent 6d3b88b36f
commit 97e504d2aa
3 changed files with 27 additions and 11 deletions

View file

@ -8115,7 +8115,7 @@
<script defer src="modules/io/cloud.js?v=1.99.00"></script>
<script defer src="modules/io/export.js?v=1.100.00"></script>
<script defer src="modules/renderers/draw-features.js?v=1.104.0"></script>
<script defer src="modules/renderers/draw-features.js?v=1.104.15"></script>
<script defer src="modules/renderers/draw-borders.js?v=1.104.0"></script>
<script defer src="modules/renderers/draw-heightmap.js?v=1.104.0"></script>
<script defer src="modules/renderers/draw-markers.js?v=1.104.0"></script>

View file

@ -129,7 +129,6 @@ window.Features = (function () {
}
features.push(addFeature({firstCell, land, border, featureId, totalCells}));
queue[0] = featureIds.findIndex(f => f === UNMARKED); // find unmarked cell
}
@ -155,7 +154,7 @@ window.Features = (function () {
function addFeature({firstCell, land, border, featureId, totalCells}) {
const type = land ? "island" : border ? "ocean" : "lake";
const featureVertices = type === "ocean" ? [] : getFeatureVertices(firstCell);
const [startCell, featureVertices] = getCellsData(type, firstCell);
const points = clipPoly(featureVertices.map(vertex => vertices.p[vertex]));
const area = d3.polygonArea(points); // feature perimiter area
const absArea = Math.abs(rn(area));
@ -165,8 +164,8 @@ window.Features = (function () {
type,
land,
border,
firstCell,
cells: totalCells,
firstCell: startCell,
vertices: featureVertices,
area: absArea
};
@ -179,19 +178,36 @@ window.Features = (function () {
return feature;
function getFeatureVertices(firstCell) {
function getCellsData(featureType, firstCell) {
if (featureType === "ocean") return [firstCell, []];
const getType = cellId => featureIds[cellId];
const type = getType(firstCell);
const ofSameType = cellId => getType(cellId) === type;
const ofDifferentType = cellId => getType(cellId) !== type;
const isOnBorder = borderCells[firstCell] || neighbors[firstCell].some(ofDifferentType);
if (!isOnBorder) throw new Error(`Markup: firstCell ${firstCell} is not on the feature or map border`);
const startCell = findOnBorderCell(firstCell);
const featureVertices = getFeatureVertices(startCell);
return [startCell, featureVertices];
const startingVertex = cells.v[firstCell].find(v => vertices.c[v].some(ofDifferentType));
if (startingVertex === undefined) throw new Error(`Markup: startingVertex for cell ${firstCell} is not found`);
function findOnBorderCell(firstCell) {
const isOnBorder = cellId => borderCells[cellId] || neighbors[cellId].some(ofDifferentType);
if (isOnBorder(firstCell)) return firstCell;
return connectVertices({vertices, startingVertex, ofSameType, closeRing: false});
const startCell = cells.i.filter(ofSameType).find(isOnBorder);
if (startCell === undefined)
throw new Error(`Markup: firstCell ${firstCell} is not on the feature or map border`);
return startCell;
}
function getFeatureVertices(startCell) {
const startingVertex = cells.v[startCell].find(v => vertices.c[v].some(ofDifferentType));
if (startingVertex === undefined)
throw new Error(`Markup: startingVertex for cell ${startCell} is not found`);
return connectVertices({vertices, startingVertex, ofSameType, closeRing: false});
}
}
}
}

View file

@ -12,7 +12,7 @@
*
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
*/
const VERSION = "1.104.14";
const VERSION = "1.104.15";
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
{