Skip to content

Commit

Permalink
fix(map,data): fix outlier systems considered when finding cluster ce…
Browse files Browse the repository at this point in the history
…nters
  • Loading branch information
MichaelMakesGames committed Feb 27, 2024
1 parent e929f12 commit 5a96dab
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/renderer/src/lib/map/data/processCircularGalaxyBorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function processCircularGalaxyBorders(
systems: Set<number>;
outliers: Set<number>;
bBox: { xMin: number; xMax: number; yMin: number; yMax: number };
points: turf.FeatureCollection<turf.Point>;
nonOutlierPoints: turf.FeatureCollection<turf.Point>;
}[] = [];

for (const go of Object.values(gameState.galactic_object)) {
Expand All @@ -51,7 +51,9 @@ export default function processCircularGalaxyBorders(
yMin: getSystemCoordinates(go.id)[1],
yMax: getSystemCoordinates(go.id)[1],
},
points: turf.featureCollection([turf.point(pointToGeoJSON(getSystemCoordinates(go.id)))]),
nonOutlierPoints: turf.featureCollection([
turf.point(pointToGeoJSON(getSystemCoordinates(go.id))),
]),
};
const edge = go.hyperlane.map((hyperlane) => hyperlane.to);
const edgeSet = new Set(edge);
Expand All @@ -62,12 +64,16 @@ export default function processCircularGalaxyBorders(
const next = gameState.galactic_object[nextId];
if (next != null && !cluster.systems.has(nextId)) {
cluster.systems.add(nextId);
cluster.points.features.push(turf.point(pointToGeoJSON(getSystemCoordinates(nextId))));
const nextHyperlanes = next.hyperlane;
const isOutlier =
nextHyperlanes.length === 1 &&
nextHyperlanes[0] != null &&
nextHyperlanes[0].length > OUTLIER_DISTANCE;
if (!isOutlier) {
cluster.nonOutlierPoints.features.push(
turf.point(pointToGeoJSON(getSystemCoordinates(nextId))),
);
}
if (isOutlier) {
cluster.outliers.add(nextId);
} else {
Expand Down Expand Up @@ -156,7 +162,7 @@ export default function processCircularGalaxyBorders(
cx = 0;
cy = 0;
} else {
const hull = turf.convex(cluster.points);
const hull = turf.convex(cluster.nonOutlierPoints);
if (hull) {
const hullCenter = turf.centerOfMass(hull);
const point = pointFromGeoJSON(hullCenter.geometry.coordinates);
Expand Down

0 comments on commit 5a96dab

Please sign in to comment.