Merge pull request #55 from duckietm/Dev

🆙 Fix background clipping
This commit is contained in:
DuckieTM
2026-04-24 14:18:03 +02:00
committed by GitHub
+6 -35
View File
@@ -378,49 +378,20 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
let leftIdx = 0; let leftIdx = 0;
let rightIdx = 0; let rightIdx = 0;
let maxY = hull[0].y;
for(let i = 1; i < hull.length; i++) for(let i = 1; i < hull.length; i++)
{ {
if(hull[i].x < hull[leftIdx].x) leftIdx = i; if(hull[i].x < hull[leftIdx].x) leftIdx = i;
if(hull[i].x > hull[rightIdx].x) rightIdx = i; if(hull[i].x > hull[rightIdx].x) rightIdx = i;
if(hull[i].y > maxY) maxY = hull[i].y;
} }
const n = hull.length;
// Collect arc going CCW: leftIdx → rightIdx via increasing indices
const arcCCW: { x: number; y: number }[] = [];
let idx = leftIdx;
while(idx !== rightIdx)
{
arcCCW.push(hull[idx]);
idx = (idx + 1) % n;
}
arcCCW.push(hull[rightIdx]);
// Collect arc going CW: leftIdx → rightIdx via decreasing indices
const arcCW: { x: number; y: number }[] = [];
idx = leftIdx;
while(idx !== rightIdx)
{
arcCW.push(hull[idx]);
idx = (idx - 1 + n) % n;
}
arcCW.push(hull[rightIdx]);
// Bottom arc = the arc with larger average Y (floor/front tiles)
const avgCCW = arcCCW.reduce((s, p) => s + p.y, 0) / arcCCW.length;
const avgCW = arcCW.reduce((s, p) => s + p.y, 0) / arcCW.length;
const bottomArc = avgCCW >= avgCW ? arcCCW : arcCW;
// Build polygon: extend upward far above walls, then trace bottom boundary
return [ return [
{ x: hull[leftIdx].x, y: -extension }, { x: hull[leftIdx].x - extension, y: -extension },
{ x: hull[rightIdx].x, y: -extension }, { x: hull[rightIdx].x + extension, y: -extension },
...bottomArc.slice().reverse() { x: hull[rightIdx].x + extension, y: maxY + extension },
{ x: hull[leftIdx].x - extension, y: maxY + extension }
]; ];
} }