< Summary

Class:DCL.Components.BoxShape
Assembly:DCL.Components.ParametrizedShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/ParametrizedShapes/BoxShape.cs
Covered lines:23
Uncovered lines:6
Coverable lines:29
Total lines:80
Line coverage:79.3% (23 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetDataFromJSON(...)0%110100%
BoxShape()0%110100%
GetClassId()0%2100%
GenerateGeometry()0%440100%
DestroyGeometry()0%2.262060%
ShouldGenerateNewMesh(...)0%98075%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/ParametrizedShapes/BoxShape.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Helpers;
 3using DCL.Models;
 4using UnityEngine;
 5
 6namespace DCL.Components
 7{
 8    public class BoxShape : ParametrizedShape<BoxShape.Model>
 9    {
 10        [System.Serializable]
 11        new public class Model : BaseShape.Model
 12        {
 13            public float[] uvs;
 14
 12215            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 16        }
 17
 31818        public BoxShape() { model = new Model(); }
 19
 20        public static Mesh cubeMesh = null;
 21        private static int cubeMeshRefCount = 0;
 22
 023        public override int GetClassId() { return (int) CLASS_ID.BOX_SHAPE; }
 24
 25        public override Mesh GenerateGeometry()
 26        {
 10727            var model = (Model) this.model;
 28
 10729            if (cubeMesh == null)
 130                cubeMesh = PrimitiveMeshBuilder.BuildCube(1f);
 31
 10732            if (model.uvs != null && model.uvs.Length > 0)
 33            {
 134                cubeMesh.uv = Utils.FloatArrayToV2List(model.uvs);
 35            }
 36
 10737            cubeMeshRefCount++;
 10738            return cubeMesh;
 39        }
 40
 41        protected override void DestroyGeometry()
 42        {
 1843            cubeMeshRefCount--;
 44
 1845            if (cubeMeshRefCount == 0)
 46            {
 047                GameObject.Destroy(cubeMesh);
 048                cubeMesh = null;
 49            }
 1850        }
 51
 52        protected override bool ShouldGenerateNewMesh(BaseShape.Model previousModel)
 53        {
 12654            if (currentMesh == null)
 10855                return true;
 56
 1857            BoxShape.Model newBoxModel = (BoxShape.Model) this.model;
 1858            BoxShape.Model oldBoxModel = (BoxShape.Model) previousModel;
 59
 1860            if (newBoxModel.uvs != null && oldBoxModel.uvs != null)
 61            {
 1162                if (newBoxModel.uvs.Length != oldBoxModel.uvs.Length)
 063                    return true;
 64
 2265                for (int i = 0; i < newBoxModel.uvs.Length; i++)
 66                {
 067                    if (newBoxModel.uvs[i] != oldBoxModel.uvs[i])
 068                        return true;
 69                }
 1170            }
 71            else
 72            {
 773                if (newBoxModel.uvs != oldBoxModel.uvs)
 374                    return true;
 75            }
 76
 1577            return false;
 78        }
 79    }
 80}