Skip to content

Commit

Permalink
Use Euler characteristic for array bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed May 12, 2024
1 parent 493996b commit 4a8dad3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/GJKEPA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class GJKEPA
{
private const double NumericEpsilon = 1e-24d;
private const double CollideEpsilon = 1e-6d;
private const int MaxIter = 85;
private const int MaxIter = 84;

public struct Statistics { public double Accuracy; public int Iterations; }

Expand Down Expand Up @@ -112,15 +112,19 @@ public static bool Equals(in Edge a, in Edge b)
}
}

// (*) Euler-characteristic: V (vertices) - E (edges) + F (faces) = 2
// We have triangles T instead of faces: F = T
// and every edge shares two triangles -> T = 2*V - 4
private const int MaxVertices = MaxIter + 4;
private const int MaxTriangles = 3 * MaxVertices;
private const int MaxTriangles = 2 * MaxVertices;

private readonly Triangle[] Triangles = new Triangle[MaxTriangles];
private readonly JVector[] Vertices = new JVector[MaxVertices];
private readonly JVector[] VerticesA = new JVector[MaxVertices];
private readonly JVector[] VerticesB = new JVector[MaxVertices];

private readonly Edge[] edges = new Edge[256];
// see (*)
private readonly Edge[] edges = new Edge[MaxVertices * 3 / 2];

private short vPointer = 0;
private short tCount = 0;
Expand Down

0 comments on commit 4a8dad3

Please sign in to comment.