< Summary

Class:RectTransformExtensions
Assembly:Utils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/RectTransformExtensions.cs
Covered lines:16
Uncovered lines:1
Coverable lines:17
Total lines:40
Line coverage:94.1% (16 of 17)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CountCornersVisibleFrom(...)0%8.018095.65%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/RectTransformExtensions.cs

#LineLine coverage
 1using UnityEngine;
 2
 3public static class RectTransformExtensions
 4{
 5    public static int CountCornersVisibleFrom(this RectTransform rectTransform, RectTransform viewport)
 6    {
 17        Vector3[] viewCorners = new Vector3[4];
 18        viewport.GetWorldCorners(viewCorners);
 9
 110        Vector2 size = new Vector2(viewport.rect.size.x * viewport.lossyScale.x, viewport.rect.size.y * viewport.lossySc
 111        Rect screenBounds = new Rect(viewCorners[0], size); // Screen space bounds (assumes camera renders across the en
 12
 113        Vector3[] objectCorners = new Vector3[4];
 114        rectTransform.GetWorldCorners(objectCorners);
 15
 116        int visibleCorners = 0;
 17
 1018        for (var i = 0; i < viewCorners.Length; i++)
 19        {
 420            if (i != viewCorners.Length - 1)
 321                Debug.DrawLine(viewCorners[i], viewCorners[i + 1], Color.blue, 1.0f);
 22        }
 23
 1024        for (var i = 0; i < objectCorners.Length; i++) // For each corner in rectTransform
 25        {
 426            if (screenBounds.Contains(objectCorners[i])) // If the corner is inside the screen
 27            {
 028                visibleCorners++;
 29            }
 30        }
 31
 1032        for (var i = 0; i < objectCorners.Length; i++) // For each corner in rectTransform
 33        {
 434            if (i != objectCorners.Length - 1)
 335                Debug.DrawLine(objectCorners[i], objectCorners[i + 1], visibleCorners > 0 ? Color.green : Color.red, 1.0
 36        }
 37
 138        return visibleCorners;
 39    }
 40}