splittintting

This commit is contained in:
33333-33333 2026-05-28 02:47:33 +09:00
commit d2e7a80e72
11 changed files with 1341 additions and 1349 deletions

View file

@ -52,6 +52,81 @@ export function pathAverageField(path, field) {
return n ? sum / n : 0;
}
export function markPathInfluence(field, path, radius = 5, strength = 1, sea = null) {
for (const [px, py] of path || []) {
for (let dy = -radius; dy <= radius; dy++) {
for (let dx = -radius; dx <= radius; dx++) {
if (dx * dx + dy * dy > radius * radius) continue;
const x = px + dx;
const y = py + dy;
if (!inside(x, y)) continue;
const i = indexOf(x, y);
if (sea?.[i]) continue;
const d = Math.hypot(dx, dy);
const v = strength * Math.pow(1 - d / Math.max(1, radius), 1.35);
if (v > field[i]) field[i] = v;
}
}
}
}
export function sampledNetworkCells(paths, step = 2, sea = null) {
const cells = [];
for (let pathId = 0; pathId < (paths || []).length; pathId++) {
const path = paths[pathId];
for (let k = 0; k < (path?.length || 0); k += step) {
const [x, y] = path[k];
if (inside(x, y) && !sea?.[indexOf(x, y)]) cells.push({ x, y, pathId });
}
}
return cells;
}
export function pathCumulativeLengths(path) {
const cum = [0];
for (let k = 1; k < (path?.length || 0); k++) {
cum.push(cum[cum.length - 1] + Math.hypot(path[k][0] - path[k - 1][0], path[k][1] - path[k - 1][1]));
}
return cum;
}
export function pointAtPathDistance(path, cum, dist) {
if (!path?.length) return null;
if (dist <= 0) return { x: path[0][0], y: path[0][1], s: 0 };
const total = cum[cum.length - 1] || 0;
if (dist >= total) {
const p = path[path.length - 1];
return { x: p[0], y: p[1], s: total };
}
let k = 1;
while (k < cum.length && cum[k] < dist) k++;
const a = path[k - 1];
const b = path[k];
const seg = Math.max(0.0001, cum[k] - cum[k - 1]);
const t = clamp((dist - cum[k - 1]) / seg);
return { x: Math.round(a[0] + (b[0] - a[0]) * t), y: Math.round(a[1] + (b[1] - a[1]) * t), s: dist };
}
export function meanFieldAround(field, x, y, radius = 8, sea = null) {
let sum = 0;
let n = 0;
const r = Math.ceil(radius);
for (let dy = -r; dy <= r; dy++) {
for (let dx = -r; dx <= r; dx++) {
if (dx * dx + dy * dy > radius * radius) continue;
const nx = x + dx;
const ny = y + dy;
if (!inside(nx, ny)) continue;
const i = indexOf(nx, ny);
if (sea?.[i]) continue;
const w = 1 - Math.hypot(dx, dy) / Math.max(1, radius);
sum += (field?.[i] || 0) * (0.35 + w);
n += 0.35 + w;
}
}
return n ? sum / n : 0;
}
export function routeQualityStats(path, fields = {}) {
if (!path?.length) return { length: 0, compactness: Infinity, highElevationShare: 1, steepShare: 1, waterShare: 1, avgPotential: 0, avgPenalty: 0 };
const length = pathLengthCells(path);