< Summary

Class:DCL.Camera.InputSpikeFixer
Assembly:Camera
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/InputSpikeFixer.cs
Covered lines:19
Uncovered lines:0
Coverable lines:19
Total lines:50
Line coverage:100% (19 of 19)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputSpikeFixer(...)0%110100%
GetValue(...)0%330100%
IsInputValueTolerable(...)0%110100%
ShouldIgnoreInputValue(...)0%220100%
CheckLockState()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/InputSpikeFixer.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL.Camera
 5{
 6    public class InputSpikeFixer
 7    {
 8        private const float INPUT_SPIKE_TOLERANCE = 10f;
 9        private readonly Func<CursorLockMode> getLockMode;
 10
 11        private CursorLockMode lastLockState;
 12        private bool isLockStateDirty;
 13
 125714        public InputSpikeFixer(Func<CursorLockMode> getLockMode)
 15        {
 125716            this.getLockMode = getLockMode;
 125717            lastLockState = getLockMode();
 125718            isLockStateDirty = false;
 125719        }
 20        public float GetValue(float currentValue)
 21        {
 3176722            CheckLockState();
 23
 3176724            float absoluteValue = Mathf.Abs(currentValue);
 25
 3176726            if (ShouldIgnoreInputValue(absoluteValue))
 27            {
 228                if (IsInputValueTolerable(absoluteValue))
 129                    isLockStateDirty = false;
 230                return 0;
 31            }
 32
 3176533            return currentValue;
 34        }
 235        private static bool IsInputValueTolerable(float value) { return value < INPUT_SPIKE_TOLERANCE; }
 3176736        private bool ShouldIgnoreInputValue(float value) { return value > 0 && isLockStateDirty; }
 37
 38        private void CheckLockState()
 39        {
 3176740            var currentLockState = getLockMode();
 41
 3176742            if (currentLockState != lastLockState)
 43            {
 244                isLockStateDirty = true;
 45            }
 46
 3176747            lastLockState = currentLockState;
 3176748        }
 49    }
 50}