< Summary

Class:DCL.Components.BoxShape
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/ParametrizedShapes/BoxShape.cs
Covered lines:25
Uncovered lines:4
Coverable lines:29
Total lines:80
Line coverage:86.2% (25 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%220100%
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
 10815            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 16        }
 17
 28218        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        {
 9427            var model = (Model) this.model;
 28
 9429            if (cubeMesh == null)
 5230                cubeMesh = PrimitiveMeshBuilder.BuildCube(1f);
 31
 9432            if (model.uvs != null && model.uvs.Length > 0)
 33            {
 134                cubeMesh.uv = Utils.FloatArrayToV2List(model.uvs);
 35            }
 36
 9437            cubeMeshRefCount++;
 9438            return cubeMesh;
 39        }
 40
 41        protected override void DestroyGeometry()
 42        {
 9343            cubeMeshRefCount--;
 44
 9345            if (cubeMeshRefCount == 0)
 46            {
 5147                GameObject.Destroy(cubeMesh);
 5148                cubeMesh = null;
 49            }
 9350        }
 51
 52        protected override bool ShouldGenerateNewMesh(BaseShape.Model previousModel)
 53        {
 11254            if (currentMesh == null)
 9655                return true;
 56
 1657            BoxShape.Model newBoxModel = (BoxShape.Model) this.model;
 1658            BoxShape.Model oldBoxModel = (BoxShape.Model) previousModel;
 59
 1660            if (newBoxModel.uvs != null && oldBoxModel.uvs != null)
 61            {
 1062                if (newBoxModel.uvs.Length != oldBoxModel.uvs.Length)
 063                    return true;
 64
 2065                for (int i = 0; i < newBoxModel.uvs.Length; i++)
 66                {
 067                    if (newBoxModel.uvs[i] != oldBoxModel.uvs[i])
 068                        return true;
 69                }
 1070            }
 71            else
 72            {
 673                if (newBoxModel.uvs != oldBoxModel.uvs)
 274                    return true;
 75            }
 76
 1477            return false;
 78        }
 79    }
 80}