From 5306d2cc3e30121dbe9394d1201661600242441e Mon Sep 17 00:00:00 2001
From: Evan Hemsley <2342303+ehemsley@users.noreply.github.com>
Date: Sun, 8 Dec 2019 20:30:21 -0800
Subject: [PATCH] revert generification + add null validation
---
Bonk/BroadPhase/SpatialHash.cs | 10 +++++++---
Bonk/NarrowPhase/EPA2D.cs | 5 ++++-
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/Bonk/BroadPhase/SpatialHash.cs b/Bonk/BroadPhase/SpatialHash.cs
index f87b53f..9e5b953 100644
--- a/Bonk/BroadPhase/SpatialHash.cs
+++ b/Bonk/BroadPhase/SpatialHash.cs
@@ -31,8 +31,10 @@ namespace MoonTools.Core.Bonk
/// A unique ID for the shape-transform pair.
///
///
- public void Insert(T id, TShape2D shape, Transform2D transform2D) where TShape2D : struct, IShape2D
+ public void Insert(T id, IShape2D shape, Transform2D transform2D)
{
+ if (shape == null) { throw new ArgumentNullException(nameof(shape)); }
+
var box = shape.AABB(transform2D);
var minHash = Hash(box.MinX, box.MinY);
var maxHash = Hash(box.MaxX, box.MaxY);
@@ -60,9 +62,11 @@ namespace MoonTools.Core.Bonk
///
/// Retrieves all the potential collisions of a shape-transform pair. Excludes any shape-transforms with the given ID.
///
- public IEnumerable<(T, IShape2D, Transform2D)> Retrieve(T id, TShape2D shape, Transform2D transform2D) where TShape2D : struct, IShape2D
+ public IEnumerable<(T, IShape2D, Transform2D)> Retrieve(T id, IShape2D shape, Transform2D transform2D)
{
- var box = shape.AABB(transform2D);
+ if (shape == null) { throw new ArgumentNullException(paramName: nameof(shape)); }
+
+ AABB box = shape.AABB(transform2D);
var minHash = Hash(box.MinX, box.MinY);
var maxHash = Hash(box.MaxX, box.MaxY);
diff --git a/Bonk/NarrowPhase/EPA2D.cs b/Bonk/NarrowPhase/EPA2D.cs
index 5bb5715..5860d2f 100644
--- a/Bonk/NarrowPhase/EPA2D.cs
+++ b/Bonk/NarrowPhase/EPA2D.cs
@@ -24,8 +24,11 @@ namespace MoonTools.Core.Bonk
/// Returns a minimum separating vector in the direction from A to B.
///
/// A simplex returned by the GJK algorithm.
- public static Vector2 Intersect(TShapeA shapeA, Transform2D Transform2DA, TShapeB shapeB, Transform2D Transform2DB, Simplex2D simplex) where TShapeA : struct, IShape2D where TShapeB : struct, IShape2D
+ public static Vector2 Intersect(IShape2D shapeA, Transform2D Transform2DA, IShape2D shapeB, Transform2D Transform2DB, Simplex2D simplex)
{
+ if (shapeA == null) { throw new ArgumentNullException(nameof(shapeA)); }
+ if (shapeB == null) { throw new ArgumentNullException(nameof(shapeB)); }
+
var simplexVertices = simplex.Vertices.Select(vertex => vertex.ToVector2()).ToImmutableArray();
var e0 = (simplexVertices[1].X - simplexVertices[0].X) * (simplexVertices[1].Y + simplexVertices[0].Y);