<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using UniRx;
using UnityEngine;
using UnityEngine.Assertions;
using static UnityEngine.Input;

namespace Alensia.Core.Input
{
    public class AxisInput : ModifierInput<float>, IAxisInput
    {
        public string Axis { get; }

        public float? Smoothing { get; }

        public AxisInput(string axis) :
            this(axis, null, Enumerable.Empty<ITrigger>().ToList())
        {
        }

        public AxisInput(string axis, float? smoothing) :
            this(axis, smoothing, Enumerable.Empty<ITrigger>().ToList())
        {
        }

        public AxisInput(string axis, float? smoothing, IList<ITrigger> modifiers) : base(modifiers)
        {
            Assert.IsNotNull(axis, "axis != null");

            Axis = axis;
            Smoothing = smoothing;
        }

        protected override IObservable<float> Observe(IObservable<long> onTick)
        {
            if (Smoothing.HasValue)
            {
                return onTick
                    .Select(_ => GetAxis(Axis))
                    .Scan((previous, current) =>
                        Mathf.Lerp(previous, current, Time.deltaTime / Smoothing.Value));
            }

            return onTick.Select(_ => GetAxis(Axis));
        }
    }
}<commit_msg>Use input value as seed in AxisInput to prevent initial spike<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using UniRx;
using UnityEngine;
using UnityEngine.Assertions;
using static UnityEngine.Input;

namespace Alensia.Core.Input
{
    public class AxisInput : ModifierInput<float>, IAxisInput
    {
        public string Axis { get; }

        public float? Smoothing { get; }

        public AxisInput(string axis) :
            this(axis, null, Enumerable.Empty<ITrigger>().ToList())
        {
        }

        public AxisInput(string axis, float? smoothing) :
            this(axis, smoothing, Enumerable.Empty<ITrigger>().ToList())
        {
        }

        public AxisInput(string axis, float? smoothing, IList<ITrigger> modifiers) : base(modifiers)
        {
            Assert.IsTrue(!smoothing.HasValue || smoothing.Value > 0, "smoothing > 0");
            Assert.IsNotNull(axis, "axis != null");

            Axis = axis;
            Smoothing = smoothing;
        }

        protected override IObservable<float> Observe(IObservable<long> onTick)
        {
            if (!Smoothing.HasValue)
            {
                return onTick.Select(_ => GetAxis(Axis));
            }

            var smoothing = Smoothing.Value;

            return onTick
                .Select(_ => GetAxis(Axis))
                .Scan(GetAxis(Axis), (previous, current) =>
                    Mathf.Lerp(previous, current, Time.deltaTime / smoothing));
        }
    }
}
{'fraction_non_alphanumeric': 0.10548823948681398, 'fraction_numerical': 0.0007127583749109052, 'mean_word_length': 2.018279569892473, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1869825', 'n_tokens_mistral': 823, 'n_tokens_neox': 769, 'n_words': 173}