< Summary

Class:GDX.BoxColliderExtensions
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/BoxColliderExtensions.cs
Covered lines:0
Uncovered lines:8
Coverable lines:8
Total lines:40
Line coverage:0% (0 of 8)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:1
Method coverage:0% (0 of 1)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ContainsPosition(...)0%42600%

File(s)

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

#LineLine coverage
 1// Copyright (c) 2020-2024 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
 5#if !UNITY_DOTSRUNTIME
 6
 7using UnityEngine;
 8
 9namespace GDX
 10{
 11    /// <summary>
 12    ///     <see cref="UnityEngine.BoxCollider" /> Based Extension Methods
 13    /// </summary>
 14    /// <exception cref="UnsupportedRuntimeException">Not supported on DOTS Runtime.</exception>
 15    [VisualScriptingCompatible(2)]
 16    public static class BoxColliderExtensions
 17    {
 18        /// <summary>
 19        ///     Is the <paramref name="worldPosition" /> inside of the <paramref name="targetBoxCollider" />?
 20        /// </summary>
 21        /// <param name="targetBoxCollider">The <see cref="BoxCollider" /> to use for evaluation.</param>
 22        /// <param name="worldPosition">A <see cref="Vector3" /> point in world space.</param>
 23        /// <returns>true/false if the world position is contained within the <paramref name="targetBoxCollider" />.</re
 24        public static bool ContainsPosition(this BoxCollider targetBoxCollider, Vector3 worldPosition)
 025        {
 026            worldPosition = targetBoxCollider.transform.InverseTransformPoint(worldPosition) - targetBoxCollider.center;
 27
 028            Vector3 cachedSize = targetBoxCollider.size;
 29
 030            float halfX = cachedSize.x * 0.5f;
 031            float halfY = cachedSize.y * 0.5f;
 032            float halfZ = cachedSize.z * 0.5f;
 33
 034            return worldPosition.x < halfX && worldPosition.x > -halfX &&
 35                   worldPosition.y < halfY && worldPosition.y > -halfY &&
 36                   worldPosition.z < halfZ && worldPosition.z > -halfZ;
 037        }
 38    }
 39}
 40#endif // !UNITY_DOTSRUNTIME