fix: virtual grid-snapped tail anchor prevents corner diagonals
Body path now goes: interp_tail → grid_tail → segment[N-2] → ... → head. The short leg from interpolated to grid-snapped tail is always straight (same direction), and from grid_tail onward the path strictly follows the grid — preserving sharp corners while tail stays smooth.
This commit is contained in:
@@ -135,18 +135,23 @@ public sealed class SnakeRenderer : Control
|
||||
var segmentsList = Segments;
|
||||
var count = segmentsList.Count;
|
||||
|
||||
// === Body path: from segment[Count-1] (tail) through segment[0] (head) ===
|
||||
// All segments use GetVisualPosition — middle/body returns grid-snapped,
|
||||
// head returns interpolated. Tail is grid-snapped, giving sharp corners
|
||||
// with full body thickness.
|
||||
// === Body path: from interp tail → grid tail (virtual corner anchor) → body → head ===
|
||||
// The virtual grid-snapped tail prevents diagonal shortcuts at corners:
|
||||
// the short leg from interp_tail to grid_tail is always straight (same direction),
|
||||
// and from grid_tail onward the path strictly follows the grid.
|
||||
if (count >= 2)
|
||||
{
|
||||
var bodyGeometry = new StreamGeometry();
|
||||
using (var ctx = bodyGeometry.Open())
|
||||
{
|
||||
// Start at tail (last segment, grid-snapped)
|
||||
var (startX, startY) = GetVisualPosition(segmentsList[count - 1], count - 1, t);
|
||||
ctx.BeginFigure(new Point(startX, startY), false);
|
||||
// Start at interpolated tail
|
||||
var (tailX, tailY) = GetVisualPosition(segmentsList[count - 1], count - 1, t);
|
||||
ctx.BeginFigure(new Point(tailX, tailY), false);
|
||||
|
||||
// Virtual corner anchor: grid-snapped tail position
|
||||
var lastPos = segmentsList[count - 1];
|
||||
var (gridTailX, gridTailY) = (lastPos.X * CellSize + CellSize * 0.5, lastPos.Y * CellSize + CellSize * 0.5);
|
||||
ctx.LineTo(new Point(gridTailX, gridTailY));
|
||||
|
||||
// Draw through middle segments down to head
|
||||
for (var i = count - 2; i >= 0; i--)
|
||||
|
||||
Reference in New Issue
Block a user