< 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:17
Uncovered lines:2
Coverable lines:19
Total lines:50
Line coverage:89.4% (17 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%2100%
ShouldIgnoreInputValue(...)0%6200%
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 = 0.5f;
 9        private readonly Func<CursorLockMode> getLockMode;
 10
 11        private CursorLockMode lastLockState;
 12        private bool isLockStateDirty;
 13
 16614        public InputSpikeFixer(Func<CursorLockMode> getLockMode)
 15        {
 16616            this.getLockMode = getLockMode;
 16617            lastLockState = getLockMode();
 16618            isLockStateDirty = false;
 16619        }
 20        public float GetValue(float currentValue)
 21        {
 3801122            CheckLockState();
 23
 3801124            float absoluteValue = Mathf.Abs(currentValue);
 25
 3801126            if (ShouldIgnoreInputValue(absoluteValue))
 27            {
 228                if (IsInputValueTolerable(absoluteValue))
 129                    isLockStateDirty = false;
 230                return 0;
 31            }
 32
 3800933            return currentValue;
 34        }
 035        private static bool IsInputValueTolerable(float value) { return value < INPUT_SPIKE_TOLERANCE; }
 036        private bool ShouldIgnoreInputValue(float value) { return value > 0 && isLockStateDirty; }
 37
 38        private void CheckLockState()
 39        {
 3801140            var currentLockState = getLockMode();
 41
 3801142            if (currentLockState != lastLockState)
 43            {
 244                isLockStateDirty = true;
 45            }
 46
 3801147            lastLockState = currentLockState;
 3801148        }
 49    }
 50}