< Summary

Class:CoordinateUtils
Assembly:HUDUtils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Utils/CoordinateUtils.cs
Covered lines:7
Uncovered lines:11
Coverable lines:18
Total lines:50
Line coverage:38.8% (7 of 18)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:5
Method coverage:60% (3 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CoordinateUtils()0%110100%
IsCoordinateInRange(...)0%440100%
ReplaceTextCoordinates(...)0%110100%
HasValidTextCoordinates(...)0%30500%
ParseCoordinatesString(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Utils/CoordinateUtils.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2
 3public class CoordinateUtils
 4{
 5    private const string COORDINATE_MATCH_REGEX = @"(?<!\w)(?<!<\/noparse>)[-]?\d{1,3},[-]?\d{1,3}(?!\w)(?!<\/\/noparse>
 6    private const int MAX_X_COORDINATE = 163;
 7    private const int MIN_X_COORDINATE = -150;
 8    private const int MAX_Y_COORDINATE = 158;
 9    private const int MIN_Y_COORDINATE = -150;
 10
 111    private static readonly Regex REGEX = new (COORDINATE_MATCH_REGEX, RegexOptions.IgnoreCase);
 12
 13    public static bool IsCoordinateInRange(int x, int y) =>
 514        x is <= MAX_X_COORDINATE and >= MIN_X_COORDINATE && y is <= MAX_Y_COORDINATE and >= MIN_Y_COORDINATE;
 15
 16    public delegate string CoordinatesReplacementDelegate(string matchedText, (int x, int y) coordinates);
 17
 18    public static string ReplaceTextCoordinates(string text, CoordinatesReplacementDelegate replacementCallback)
 19    {
 1220        return REGEX.Replace(text, match =>
 21        {
 522            string value = match.Value;
 523            int.TryParse(value.Split(',')[0], out int x);
 524            int.TryParse(value.Split(',')[1], out int y);
 25
 526            return IsCoordinateInRange(x, y) ? replacementCallback.Invoke(value, (x, y)) : value;
 27        });
 28    }
 29
 30    public static bool HasValidTextCoordinates(string text)
 31    {
 032        MatchCollection matches = REGEX.Matches(text);
 33
 034        foreach (Match match in matches)
 35        {
 036            if (!match.Success) continue;
 037            string value = match.Value;
 038            int.TryParse(value.Split(',')[0], out int x);
 039            int.TryParse(value.Split(',')[1], out int y);
 40
 041            if (IsCoordinateInRange(x, y))
 042                return true;
 43        }
 44
 045        return false;
 046    }
 47
 48    public static ParcelCoordinates ParseCoordinatesString(string coordinates) =>
 049        new (int.Parse(coordinates.Split(',')[0]), int.Parse(coordinates.Split(',')[1]));
 50}