< Summary

Class:DCL.Models.MeshesInfoUtils
Assembly:MeshesInfo
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Scene/MeshesInfo/MeshesInfoUtils.cs
Covered lines:9
Uncovered lines:1
Coverable lines:10
Total lines:43
Line coverage:90% (9 of 10)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BuildMergedBounds(...)0%440100%
GetSafeBounds(...)0%2.152066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Scene/MeshesInfo/MeshesInfoUtils.cs

#LineLine coverage
 1using UnityEngine;
 2
 3namespace DCL.Models
 4{
 5    public static class MeshesInfoUtils
 6    {
 7        public static Bounds BuildMergedBounds(Renderer[] renderers)
 8        {
 2789            Bounds bounds = new Bounds();
 10
 122011            for (int i = 0; i < renderers.Length; i++)
 12            {
 33213                if (renderers[i] == null)
 14                    continue;
 15
 33216                if (i == 0)
 27817                    bounds = renderers[i].GetSafeBounds();
 18                else
 5419                    bounds.Encapsulate(renderers[i].GetSafeBounds());
 20            }
 21
 27822            return bounds;
 23        }
 24
 25        /// <summary>
 26        /// This get the renderer bounds with a check to ensure the renderer is at a safe position.
 27        /// If the renderer is too far away from 0,0,0, wasm target ensures a crash.
 28        /// </summary>
 29        /// <param name="renderer"></param>
 30        /// <returns>The bounds value if the value is correct, or a mocked bounds object with clamped values if its too 
 31        public static Bounds GetSafeBounds( this Renderer renderer )
 32        {
 33            // World extents are of 4800 world mts, so this limit far exceeds the world size.
 34            const float POSITION_OVERFLOW_LIMIT = 10000;
 35            const float POSITION_OVERFLOW_LIMIT_SQR = POSITION_OVERFLOW_LIMIT * POSITION_OVERFLOW_LIMIT;
 36
 277137            if ( renderer.transform.position.sqrMagnitude > POSITION_OVERFLOW_LIMIT_SQR )
 038                return new Bounds( Vector3.one * POSITION_OVERFLOW_LIMIT, Vector3.one * 0.1f );
 39
 277140            return renderer.bounds;
 41        }
 42    }
 43}