< Summary

Class:GDX.Space
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Space.cs
Covered lines:0
Uncovered lines:55
Coverable lines:55
Total lines:134
Line coverage:0% (0 of 55)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:4
Method coverage:0% (0 of 4)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Space()0%2100%
GetDirection(...)0%1821300%
ToRotation(...)0%72800%
ToRotation(...)0%1321100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Space.cs

#LineLine coverage
 1// Copyright (c) 2020-2023 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using UnityEngine;
 6
 7namespace GDX
 8{
 9    public static class Space
 10    {
 11        public enum Direction
 12        {
 13            /// <summary>
 14            /// An undetermined direction.
 15            /// </summary>
 16            Undefined,
 17            /// <summary>
 18            /// Z axis.
 19            /// </summary>
 20            Forward,
 21            /// <summary>
 22            /// -Z axis.
 23            /// </summary>
 24            Backward,
 25            /// <summary>
 26            /// -X axis.
 27            /// </summary>
 28            Left,
 29            /// <summary>
 30            /// X axis.
 31            /// </summary>
 32            Right,
 33            /// <summary>
 34            /// Y axis.
 35            /// </summary>
 36            Up,
 37            /// <summary>
 38            /// -Y axis.
 39            /// </summary>
 40            Down
 41        }
 42        public enum Axis
 43        {
 44            Undefined,
 45            X,
 46            Y,
 47            Z
 48        }
 49
 50#if !UNITY_DOTSRUNTIME
 051        static readonly Quaternion k_RotationLeft = Quaternion.Euler(-90, 0, 0);
 052        static readonly Quaternion k_RotationRight = Quaternion.Euler(90, 0, 0);
 053        static readonly Quaternion k_RotationUp = Quaternion.Euler(0, 90, 0);
 054        static readonly Quaternion k_RotationDown = Quaternion.Euler(0, -90, 0);
 055        static readonly Quaternion k_RotationForward = Quaternion.Euler(0, 0, 90);
 056        static readonly Quaternion k_RotationBackward = Quaternion.Euler(0, 0, -90);
 57
 58        /// <summary>
 59        ///     Get the corresponding <see cref="Direction"/> for a <see cref="Vector3"/> provided direction.
 60        /// </summary>
 61        /// <remarks>Only works with deterministic directions builtin to Unity.</remarks>
 62        /// <param name="direction">The given direction.</param>
 63        /// <returns>A qualified <see cref="Direction"/> equivalent to the <paramref name="direction"/>.</returns>
 64        public static Direction GetDirection(Vector3 direction)
 065        {
 66            // Left/Right
 067            if (direction.y == 0 && direction.z == 0)
 068            {
 069                if (direction.x > 0)
 070                {
 071                    return Direction.Right;
 72                }
 073                if(direction.x < 0 )
 074                {
 075                    return Direction.Left;
 76                }
 077            }
 78
 79            // Forward / Backward
 080            if (direction.x == 0 && direction.y == 0)
 081            {
 082                if (direction.z > 0)
 083                {
 084                    return Direction.Forward;
 85                }
 086                if (direction.z < 0)
 087                {
 088                    return Direction.Backward;
 89                }
 090            }
 91
 92            // Up / Down
 093            if (direction.x == 0 && direction.z == 0)
 094            {
 095                if (direction.y > 0)
 096                {
 097                    return Direction.Up;
 98                }
 099                if (direction.y < 0)
 0100                {
 0101                    return Direction.Down;
 102                }
 0103            }
 0104            return Direction.Undefined;
 0105        }
 106
 107        public static Quaternion ToRotation(this Axis axis)
 0108        {
 0109            return axis switch
 110            {
 0111                Axis.Undefined => Quaternion.identity,
 0112                Axis.X => k_RotationRight,
 0113                Axis.Y => k_RotationUp,
 0114                Axis.Z => k_RotationForward,
 0115                _ => Quaternion.identity
 116            };
 0117        }
 118        public static Quaternion ToRotation(this Direction direction)
 0119        {
 0120            return direction switch
 121            {
 0122                Direction.Undefined => Quaternion.identity,
 0123                Direction.Left => k_RotationLeft,
 0124                Direction.Right => k_RotationRight,
 0125                Direction.Up => k_RotationUp,
 0126                Direction.Down => k_RotationDown,
 0127                Direction.Backward => k_RotationBackward,
 0128                Direction.Forward => k_RotationForward,
 0129                _ => Quaternion.identity,
 130            };
 0131        }
 132#endif // !UNITY_DOTSRUNTIME
 133    }
 134}