diff --git a/Bonk/AABB.cs b/Bonk/AABB.cs
index 0074d01..d29f86b 100644
--- a/Bonk/AABB.cs
+++ b/Bonk/AABB.cs
@@ -6,6 +6,9 @@ using MoonTools.Core.Structs;
namespace MoonTools.Core.Bonk
{
+ ///
+ /// Axis-aligned bounding box.
+ ///
public struct AABB
{
public float MinX { get; private set; }
diff --git a/Bonk/BroadPhase/SpatialHash.cs b/Bonk/BroadPhase/SpatialHash.cs
index cb45db0..f29edd8 100644
--- a/Bonk/BroadPhase/SpatialHash.cs
+++ b/Bonk/BroadPhase/SpatialHash.cs
@@ -4,6 +4,10 @@ using MoonTools.Core.Structs;
namespace MoonTools.Core.Bonk
{
+ ///
+ /// Used to quickly check if two shapes are potentially overlapping.
+ ///
+ /// The type that will be used to uniquely identify shape-transform pairs.
public class SpatialHash where T : IEquatable
{
private readonly int cellSize;
@@ -21,6 +25,12 @@ namespace MoonTools.Core.Bonk
return ((int)Math.Floor(x / cellSize), (int)Math.Floor(y / cellSize));
}
+ ///
+ /// Inserts an element into the SpatialHash.
+ ///
+ /// A unique ID for the shape-transform pair.
+ ///
+ ///
public void Insert(T id, IShape2D shape, Transform2D transform2D)
{
var box = shape.AABB(transform2D);
@@ -47,6 +57,9 @@ 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, IShape2D shape, Transform2D transform2D)
{
var box = shape.AABB(transform2D);
@@ -69,6 +82,9 @@ namespace MoonTools.Core.Bonk
}
}
+ ///
+ /// Removes everything that has been inserted into the SpatialHash.
+ ///
public void Clear()
{
foreach (var innerDict in hashDictionary.Values)
diff --git a/Bonk/IShape2D.cs b/Bonk/IShape2D.cs
index cffbfe2..7a34782 100644
--- a/Bonk/IShape2D.cs
+++ b/Bonk/IShape2D.cs
@@ -6,10 +6,19 @@ namespace MoonTools.Core.Bonk
{
public interface IShape2D : IEquatable
{
- // A Support function for a Minkowski sum.
- // A Support function gives the point on the edge of a shape based on a direction.
+ ///
+ /// A Minkowski support function. Gives the farthest point on the edge of a shape along the given direction.
+ ///
+ /// A normalized Vector2.
+ /// A Transform for transforming the shape vertices.
+ /// The farthest point on the edge of the shape along the given direction.
Vector2 Support(Vector2 direction, Transform2D transform);
+ ///
+ /// Returns a bounding box based on the shape.
+ ///
+ /// A Transform for transforming the shape vertices.
+ /// Returns a bounding box based on the shape.
AABB AABB(Transform2D transform);
}
}
diff --git a/Bonk/MinkowskiDifference.cs b/Bonk/MinkowskiDifference.cs
index bee297a..e6772eb 100644
--- a/Bonk/MinkowskiDifference.cs
+++ b/Bonk/MinkowskiDifference.cs
@@ -4,6 +4,9 @@ using MoonTools.Core.Structs;
namespace MoonTools.Core.Bonk
{
+ ///
+ /// A Minkowski difference between two shapes.
+ ///
public struct MinkowskiDifference : IEquatable
{
private IShape2D shapeA;
diff --git a/Bonk/NarrowPhase/EPA2D.cs b/Bonk/NarrowPhase/EPA2D.cs
index 9b04e43..a3b58bb 100644
--- a/Bonk/NarrowPhase/EPA2D.cs
+++ b/Bonk/NarrowPhase/EPA2D.cs
@@ -19,7 +19,11 @@ namespace MoonTools.Core.Bonk
public static class EPA2D
{
- // vector returned gives direction from A to B
+ ///
+ /// Returns a minimum separating vector in the direction from A to B.
+ ///
+ /// A simplex returned by the GJK algorithm.
+ ///
public static Vector2 Intersect(IShape2D shapeA, Transform2D Transform2DA, IShape2D shapeB, Transform2D Transform2DB, Simplex simplex)
{
var simplexVertices = new PooledList(36, ClearMode.Always);
diff --git a/Bonk/NarrowPhase/GJK2D.cs b/Bonk/NarrowPhase/GJK2D.cs
index 417b071..0176a96 100644
--- a/Bonk/NarrowPhase/GJK2D.cs
+++ b/Bonk/NarrowPhase/GJK2D.cs
@@ -6,6 +6,9 @@ namespace MoonTools.Core.Bonk
{
public static class GJK2D
{
+ ///
+ /// Tests if the two shape-transform pairs are overlapping.
+ ///
public static bool TestCollision(IShape2D shapeA, Transform2D transformA, IShape2D shapeB, Transform2D transformB)
{
var minkowskiDifference = new MinkowskiDifference(shapeA, transformA, shapeB, transformB);
@@ -29,6 +32,9 @@ namespace MoonTools.Core.Bonk
return (b - a) == Vector2.Zero || (axb.Y > 0 != bxc.Y > 0 ? CheckSimplex(simplex.WithDirections(b, c)) : (axc.Y > 0 != cxb.Y > 0 ? CheckSimplex(simplex.WithDirections(a, c)) : true));
}
+ ///
+ /// Tests if the two shape-transform pairs are overlapping, and returns a simplex that can be used by the EPA algorithm to determine a miminum separating vector.
+ ///
public static (bool, Simplex) FindCollisionSimplex(IShape2D shapeA, Transform2D transformA, IShape2D shapeB, Transform2D transformB)
{
var minkowskiDifference = new MinkowskiDifference(shapeA, transformA, shapeB, transformB);
diff --git a/Bonk/Shapes/Circle.cs b/Bonk/Shapes/Circle.cs
index 334e504..8e286d5 100644
--- a/Bonk/Shapes/Circle.cs
+++ b/Bonk/Shapes/Circle.cs
@@ -4,6 +4,9 @@ using MoonTools.Core.Structs;
namespace MoonTools.Core.Bonk
{
+ ///
+ /// A Circle is a shape defined by a radius.
+ ///
public struct Circle : IShape2D, IEquatable
{
public int Radius { get; private set; }
diff --git a/Bonk/Shapes/Line.cs b/Bonk/Shapes/Line.cs
index 62456d3..b927719 100644
--- a/Bonk/Shapes/Line.cs
+++ b/Bonk/Shapes/Line.cs
@@ -5,6 +5,9 @@ using MoonTools.Core.Structs;
namespace MoonTools.Core.Bonk
{
+ ///
+ /// A line is a shape defined by exactly two points in space.
+ ///
public struct Line : IShape2D, IEquatable
{
private Position2D v0;
diff --git a/Bonk/Shapes/Polygon.cs b/Bonk/Shapes/Polygon.cs
index d9ef67f..8a4232d 100644
--- a/Bonk/Shapes/Polygon.cs
+++ b/Bonk/Shapes/Polygon.cs
@@ -4,6 +4,9 @@ using MoonTools.Core.Structs;
namespace MoonTools.Core.Bonk
{
+ ///
+ /// A Shape defined by an arbitrary collection of vertices. WARNING: Polygon must use an Array internally and therefore will create GC pressure.
+ ///
public struct Polygon : IShape2D, IEquatable
{
public Position2D[] Vertices { get; private set; }
@@ -48,7 +51,7 @@ namespace MoonTools.Core.Bonk
for (int i = 0; i < Vertices.Length; i++)
{
- if (Vertices[i].ToVector2() != otherPolygon.Vertices[i].ToVector2()) { return false;}
+ if (Vertices[i].ToVector2() != otherPolygon.Vertices[i].ToVector2()) { return false; }
}
return true;
diff --git a/Bonk/Shapes/Rectangle.cs b/Bonk/Shapes/Rectangle.cs
index fb44184..3a6b2f5 100644
--- a/Bonk/Shapes/Rectangle.cs
+++ b/Bonk/Shapes/Rectangle.cs
@@ -7,6 +7,9 @@ using MoreLinq;
namespace MoonTools.Core.Bonk
{
+ ///
+ /// A rectangle is a shape defined by a minimum and maximum X value and a minimum and maximum Y value.
+ ///
public struct Rectangle : IShape2D, IEquatable
{
public int MinX { get; }
diff --git a/Bonk/Shapes/Simplex.cs b/Bonk/Shapes/Simplex.cs
index 3eb8dc2..7562d73 100644
--- a/Bonk/Shapes/Simplex.cs
+++ b/Bonk/Shapes/Simplex.cs
@@ -5,6 +5,9 @@ using MoonTools.Core.Bonk.Extensions;
namespace MoonTools.Core.Bonk
{
+ ///
+ /// A simplex is a shape used to calculate overlap. It is defined by a Minkowski difference and two direction vectors.
+ ///
public struct Simplex : IShape2D
{
MinkowskiDifference minkowskiDifference;