< Summary

Class:UtilsScene
Assembly:ECS7Plugin.Utils
File(s):File 1: /tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Utils/Scene/Bounds.cs
File 2: /tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Utils/Scene/Convert.cs
File 3: /tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Utils/Scene/Media.cs
Covered lines:9
Uncovered lines:54
Coverable lines:63
Total lines:202
Line coverage:14.2% (9 of 63)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:8
Method coverage:25% (2 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
File 1: CalculateOuterBounds(...)0%6200%
File 1: IsInsideSceneInnerBounds(...)0%72800%
File 1: IsInsideSceneOuterBounds(...)0%2100%
File 1: IsInsideSceneInnerBounds(...)0%12300%
File 2: GlobalToScenePosition(...)0%110100%
File 3: HasRequiredPermission(...)0%12300%
File 3: IsUrlDomainAllowed(...)0%20400%
File 3: TryGetMediaUrl(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Utils/Scene/Bounds.cs

#LineLine coverage
 1using DCL.Configuration;
 2using DCL.Helpers;
 3using System.Collections.Generic;
 4using UnityEngine;
 5
 6/*
 7* Scene utils file for scene bounds related stuff
 8*/
 9
 10public static partial class UtilsScene
 11{
 12    public static Bounds CalculateOuterBounds(IReadOnlyList<Vector2Int> parcels, Vector3 baseParcelWorldPos)
 13    {
 014        Bounds outerBounds = new Bounds();
 015        outerBounds.SetMinMax(new Vector3(baseParcelWorldPos.x, 0f, baseParcelWorldPos.z),
 16            new Vector3(baseParcelWorldPos.x + ParcelSettings.PARCEL_SIZE, 0f, baseParcelWorldPos.z + ParcelSettings.PAR
 17
 018        for (int i = 0; i < parcels.Count; i++)
 19        {
 20            // Update outer bounds with parcel's size
 021            var parcel = parcels[i];
 22
 023            Vector3 parcelWorldPos = PositionUtils.WorldToUnityPosition(Utils.GridToWorldPosition(parcel.x, parcel.y));
 024            outerBounds.Encapsulate(new Vector3(parcelWorldPos.x, 0, parcelWorldPos.z));
 025            outerBounds.Encapsulate(new Vector3(parcelWorldPos.x + ParcelSettings.PARCEL_SIZE, 0, parcelWorldPos.z + Par
 26        }
 27
 28        // Apply outer bounds extra threshold
 029        outerBounds.SetMinMax(new Vector3(outerBounds.min.x - ParcelSettings.PARCEL_BOUNDARIES_THRESHOLD, 0f, outerBound
 30            new Vector3(outerBounds.max.x + ParcelSettings.PARCEL_BOUNDARIES_THRESHOLD, 0f, outerBounds.max.z + ParcelSe
 31
 032        return outerBounds;
 33    }
 34
 35    public static bool IsInsideSceneInnerBounds(HashSet<Vector2Int> sceneParcels, float sceneHeightLimit, Vector3 target
 36    {
 037        if (sceneParcels.Count == 0)
 038            return false;
 39
 040        if (height > sceneHeightLimit)
 041            return false;
 42
 043        int noThresholdZCoordinate = Mathf.FloorToInt(targetWorldPosition.z / ParcelSettings.PARCEL_SIZE);
 044        int noThresholdXCoordinate = Mathf.FloorToInt(targetWorldPosition.x / ParcelSettings.PARCEL_SIZE);
 45
 46        // We check the target world position
 047        Vector2Int targetCoordinate = new Vector2Int(noThresholdXCoordinate, noThresholdZCoordinate);
 48
 049        if (sceneParcels.Contains(targetCoordinate))
 050            return true;
 51
 52        // We need to check using a threshold from the target point, in order to cover correctly the parcel "border/edge
 053        Vector2Int coordinateMin = new Vector2Int();
 054        coordinateMin.x = Mathf.FloorToInt((targetWorldPosition.x - ParcelSettings.PARCEL_BOUNDARIES_THRESHOLD) / Parcel
 055        coordinateMin.y = Mathf.FloorToInt((targetWorldPosition.z - ParcelSettings.PARCEL_BOUNDARIES_THRESHOLD) / Parcel
 56
 057        Vector2Int coordinateMax = new Vector2Int();
 058        coordinateMax.x = Mathf.FloorToInt((targetWorldPosition.x + ParcelSettings.PARCEL_BOUNDARIES_THRESHOLD) / Parcel
 059        coordinateMax.y = Mathf.FloorToInt((targetWorldPosition.z + ParcelSettings.PARCEL_BOUNDARIES_THRESHOLD) / Parcel
 60
 61        // We check the east/north-threshold position
 062        targetCoordinate.Set(coordinateMax.x, coordinateMax.y);
 63
 064        if (sceneParcels.Contains(targetCoordinate))
 065            return true;
 66
 67        // We check the east/south-threshold position
 068        targetCoordinate.Set(coordinateMax.x, coordinateMin.y);
 69
 070        if (sceneParcels.Contains(targetCoordinate))
 071            return true;
 72
 73        // We check the west/north-threshold position
 074        targetCoordinate.Set(coordinateMin.x, coordinateMax.y);
 75
 076        if (sceneParcels.Contains(targetCoordinate))
 077            return true;
 78
 79        // We check the west/south-threshold position
 080        targetCoordinate.Set(coordinateMin.x, coordinateMin.y);
 81
 082        if (sceneParcels.Contains(targetCoordinate))
 083            return true;
 84
 085        return false;
 86    }
 87
 88    public static bool IsInsideSceneOuterBounds(Bounds sceneOuterBounds, Vector3 targetUnityPosition)
 89    {
 090        targetUnityPosition.y = 0f;
 091        return sceneOuterBounds.Contains(targetUnityPosition);
 92    }
 93
 94    public static bool IsInsideSceneInnerBounds(HashSet<Vector2Int> sceneParcels, float sceneHeightLimit, Bounds targetB
 95    {
 096        var worldOffset = CommonScriptableObjects.worldOffset.Get();
 97
 098        if (!IsInsideSceneInnerBounds(sceneParcels, sceneHeightLimit, targetBounds.min + worldOffset, targetBounds.max.y
 099            return false;
 100
 0101        if (!IsInsideSceneInnerBounds(sceneParcels, sceneHeightLimit, targetBounds.max + worldOffset, targetBounds.max.y
 0102            return false;
 103
 0104        return true;
 105    }
 106}

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Utils/Scene/Convert.cs

#LineLine coverage
 1/*
 2* Scene utils file for type and unit convertion
 3*/
 4
 5using DCL.Configuration;
 6using UnityEngine;
 7
 8public static partial class UtilsScene
 9{
 10    public static Vector3 GlobalToScenePosition(ref Vector2Int parcelBasePosition, ref Vector3 position, ref Vector3 wor
 11    {
 812        return new Vector3(
 13            x: (position.x + worldOffset.x) - (parcelBasePosition.x * ParcelSettings.PARCEL_SIZE),
 14            y: (position.y + worldOffset.y),
 15            z: (position.z + worldOffset.z) - (parcelBasePosition.y * ParcelSettings.PARCEL_SIZE)
 16        );
 17    }
 18}

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Utils/Scene/Media.cs

#LineLine coverage
 1using DCL;
 2using DCL.Models;
 3using System;
 4using System.Collections.Generic;
 5using UnityEngine;
 6using DCL.Configuration;
 7
 8/*
 9* Scene utils file for media related stuff
 10*/
 11
 12public static partial class UtilsScene
 13{
 14    // We are currently accepting all scene's required permissions.
 15    // In the future we might want to replace this for user's accepted permissions.
 16    public static bool HasRequiredPermission(IReadOnlyList<string> requiredPermissions, string permission)
 17    {
 018        for (int i = 0; i < requiredPermissions.Count; i++)
 19        {
 020            if (requiredPermissions[i] == permission)
 021                return true;
 22        }
 23
 024        return false;
 25    }
 26
 27    public static bool IsUrlDomainAllowed(IReadOnlyList<string> allowedDomains, string url)
 28    {
 029        if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri))
 30        {
 031            for (int i = 0; i < allowedDomains.Count; i++)
 32            {
 033                if (String.Equals(allowedDomains[i], uri.Host, StringComparison.OrdinalIgnoreCase))
 034                    return true;
 35            }
 36        }
 37
 038        return false;
 39    }
 40
 41    public static bool TryGetMediaUrl(string inputUrl, ContentProvider sceneContentProvider,
 42        IReadOnlyList<string> sceneRequiredPermissions, IReadOnlyList<string> sceneAllowedMediaHostnames,
 43        out string url)
 44    {
 3045        if (string.IsNullOrEmpty(inputUrl))
 46        {
 247            url = string.Empty;
 248            Debug.LogError("Media asset url error: media URL is empty.");
 249            return false;
 50        }
 51
 2852        if (sceneContentProvider.TryGetContentsUrl(inputUrl, out url))
 53        {
 2554            return true;
 55        }
 56
 57        if (ExternalDataFetchingSettings.CHECK_ALLOWED_MEDIA_HOSTNAMES
 58        && (sceneRequiredPermissions == null || sceneAllowedMediaHostnames == null))
 59        {
 60            url = string.Empty;
 61            Debug.LogError("External media asset url error: 'allowedMediaHostnames' missing in scene.json file.");
 62            return false;
 63        }
 64
 65        if (!ExternalDataFetchingSettings.CHECK_ALLOWED_MEDIA_HOSTNAMES
 66            || (HasRequiredPermission(sceneRequiredPermissions, ScenePermissionNames.ALLOW_MEDIA_HOSTNAMES)
 67            && IsUrlDomainAllowed(sceneAllowedMediaHostnames, inputUrl)))
 68        {
 369            url = inputUrl;
 370            return true;
 71        }
 72
 73        Debug.LogError($"External media asset url error: '{inputUrl}' host name is not in 'allowedMediaHostnames' in sce
 74
 75        url = string.Empty;
 76        return false;
 77    }
 78}