Code/Demos/TarkovInventory/GridGeometry.cs
using System;

namespace Sandbox.TarkovInventory;

// Pure cursor→cell mapping. Uses the zone's RENDERED size (engine frame), not the authored
// slot size, so it stays correct under UI scaling. See engine-fact-sbox-ui-drop-dispatch.
public static class GridGeometry
{
    public static (int x, int y) CellAt( Vector2 local, Vector2 zoneSize, int cols, int rows )
    {
        int x = Math.Clamp( (int)(local.x / (zoneSize.x / cols)), 0, cols - 1 );
        int y = Math.Clamp( (int)(local.y / (zoneSize.y / rows)), 0, rows - 1 );
        return (x, y);
    }
}