feat: NotNullWhen to TryDetect

This commit is contained in:
Syntriax 2024-01-25 18:32:13 +03:00
parent f7467a62ee
commit f5be49609b
2 changed files with 12 additions and 3 deletions

View File

@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Syntriax.Engine.Core; using Syntriax.Engine.Core;
using Syntriax.Engine.Physics2D.Abstract; using Syntriax.Engine.Physics2D.Abstract;
@ -5,7 +7,7 @@ namespace Syntriax.Engine.Physics2D;
public class CollisionDetector : ICollisionDetector public class CollisionDetector : ICollisionDetector
{ {
public bool TryDetect<T1, T2>(T1 left, T2 right, out CollisionDetectionInformation? collisionInformation) public bool TryDetect<T1, T2>(T1 left, T2 right, [NotNullWhen(true)] out CollisionDetectionInformation? collisionInformation)
where T1 : ICollider2D where T1 : ICollider2D
where T2 : ICollider2D where T2 : ICollider2D
{ {
@ -20,7 +22,7 @@ public class CollisionDetector : ICollisionDetector
else if (left is ICircleCollider2D circleColliderLeft) else if (left is ICircleCollider2D circleColliderLeft)
{ {
if (right is IShapeCollider2D shapeColliderRight) if (right is IShapeCollider2D shapeColliderRight)
return DetectShapeCircle(shapeColliderRight, circleColliderLeft, out collisionInformation); return DetectCircleShape(circleColliderLeft, shapeColliderRight, out collisionInformation);
else if (right is ICircleCollider2D circleColliderRight) else if (right is ICircleCollider2D circleColliderRight)
return DetectCircleCircle(circleColliderLeft, circleColliderRight, out collisionInformation); return DetectCircleCircle(circleColliderLeft, circleColliderRight, out collisionInformation);
} }
@ -28,6 +30,11 @@ public class CollisionDetector : ICollisionDetector
return false; return false;
} }
private bool DetectCircleShape(ICircleCollider2D circleCollider, IShapeCollider2D shapeCollider, out CollisionDetectionInformation? collisionInformation)
{
throw new System.NotImplementedException();
}
private static bool DetectShapeShape(IShapeCollider2D left, IShapeCollider2D right, out CollisionDetectionInformation? collisionInformation) private static bool DetectShapeShape(IShapeCollider2D left, IShapeCollider2D right, out CollisionDetectionInformation? collisionInformation)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();

View File

@ -1,8 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using Syntriax.Engine.Physics2D.Abstract; using Syntriax.Engine.Physics2D.Abstract;
namespace Syntriax.Engine.Physics2D; namespace Syntriax.Engine.Physics2D;
public interface ICollisionDetector public interface ICollisionDetector
{ {
bool TryDetect<T1, T2>(T1 left, T2 right, out CollisionDetectionInformation? collisionInformation) where T1 : ICollider2D where T2 : ICollider2D; bool TryDetect<T1, T2>(T1 left, T2 right, [NotNullWhen(returnValue: true)] out CollisionDetectionInformation? collisionInformation) where T1 : ICollider2D where T2 : ICollider2D;
} }