< Summary

Class:DCL.Controllers.DCLVideoTextureUtils
Assembly:DCL.Components.Video
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/DCLVideoTextureUtils.cs
Covered lines:42
Uncovered lines:2
Coverable lines:44
Total lines:96
Line coverage:95.4% (42 of 44)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:5
Method coverage:100% (5 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetClosestDistanceSqr(...)0%5.015091.67%
IsComponentVisible(...)0%440100%
IsEntityVisible(...)0%3.073080%
UnsubscribeToEntityShapeUpdate(...)0%330100%
SubscribeToEntityUpdates(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/DCLVideoTextureUtils.cs

#LineLine coverage
 1using DCL.Components;
 2using DCL.Models;
 3using UnityEngine;
 4
 5namespace DCL.Controllers
 6{
 7    public static class DCLVideoTextureUtils
 8    {
 9        public static float GetClosestDistanceSqr(ISharedComponent disposableComponent, Vector3 fromPosition)
 10        {
 911            float dist = int.MaxValue;
 12
 913            if (disposableComponent.GetAttachedEntities().Count <= 0)
 014                return dist;
 15
 916            using (var iterator = disposableComponent.GetAttachedEntities().GetEnumerator())
 17            {
 1818                while (iterator.MoveNext())
 19                {
 920                    IDCLEntity entity = iterator.Current;
 21
 922                    if (IsEntityVisible(iterator.Current))
 23                    {
 924                        var entityDist = (entity.meshRootGameObject.transform.position - fromPosition).sqrMagnitude;
 925                        if (entityDist < dist)
 926                            dist = entityDist;
 27                    }
 28                }
 929            }
 30
 931            return dist;
 32        }
 33
 34        public static bool IsComponentVisible(ISharedComponent disposableComponent)
 35        {
 3236            if (disposableComponent.GetAttachedEntities().Count <= 0)
 1137                return false;
 38
 2139            using (var iterator = disposableComponent.GetAttachedEntities().GetEnumerator())
 40            {
 3341                while (iterator.MoveNext())
 42                {
 2143                    bool isEntityVisible = IsEntityVisible(iterator.Current);
 44
 2145                    if (isEntityVisible)
 946                        return true;
 47                }
 1248            }
 49
 1250            return false;
 951        }
 52
 53        public static bool IsEntityVisible(IDCLEntity entity)
 54        {
 3055            if (entity.meshesInfo == null)
 056                return false;
 57
 3058            if (entity.meshesInfo.currentShape == null)
 1059                return false;
 60
 2061            return entity.meshesInfo.currentShape.IsVisible();
 62        }
 63
 64        public static void UnsubscribeToEntityShapeUpdate(ISharedComponent component,
 65            System.Action<IDCLEntity> OnUpdate)
 66        {
 367            if (component.GetAttachedEntities().Count <= 0)
 168                return;
 69
 270            using (var iterator = component.GetAttachedEntities().GetEnumerator())
 71            {
 472                while (iterator.MoveNext())
 73                {
 274                    var entity = iterator.Current;
 275                    entity.OnShapeUpdated -= OnUpdate;
 76                }
 277            }
 278        }
 79
 80        public static void SubscribeToEntityUpdates(ISharedComponent component, System.Action<IDCLEntity> OnUpdate)
 81        {
 1382            if (component.GetAttachedEntities().Count <= 0)
 283                return;
 84
 1185            using (var iterator = component.GetAttachedEntities().GetEnumerator())
 86            {
 2287                while (iterator.MoveNext())
 88                {
 1189                    var entity = iterator.Current;
 1190                    entity.OnShapeUpdated -= OnUpdate;
 1191                    entity.OnShapeUpdated += OnUpdate;
 92                }
 1193            }
 1194        }
 95    }
 96}