Please explain the following source code:

public Vector2Int ToHexGrid(Vector2 position)
{
    // Convert to hex grid coordinates
    float x = position.x / (HexMetrics.innerRadius * 2f);
    float y = -x;

    float offset = position.y / (HexMetrics.outerRadius * 3f);
    x -= offset;
    y -= offset;

    int iX = Mathf.RoundToInt(x);
    int iY = Mathf.RoundToInt(y);
    int iZ = Mathf.RoundToInt(-x - y);

    if (iX + iY + iZ != 0)
    {
        float dX = Mathf.Abs(x - iX);
        float dY = Mathf.Abs(y - iY);
        float dZ = Mathf.Abs(-x - y - iZ);

        if (dX > dY && dX > dZ)
        {
            iX = -iY - iZ;
        }
        else if (dZ > dY)
        {
            iZ = -iX - iY;
        }
    }

    return new Vector2Int(iX, iZ);
}

public static class HexMetrics
{
    public const float outerRadius = 10f;

    public const float innerRadius = outerRadius * 0.866025404f;
}