diff --git a/collision.go b/collision.go index dc808c7..58f03a1 100644 --- a/collision.go +++ b/collision.go @@ -245,7 +245,7 @@ func (v0 MinkowskiPoint) ClosestPoints(v1 MinkowskiPoint) ClosestPoints { // Vertex/vertex collisions need special treatment since the MSA won't be shared with an axis of the minkowski difference. d2 := p.Length() - n2 := p.Mult(1 / (d2 + math.SmallestNonzeroFloat64)) + n2 := p.Mult(1 / (d2 + 1e-15)) return ClosestPoints{pa, pb, n2, d2, id} } @@ -325,8 +325,8 @@ func ContactPoints(e1, e2 Edge, points ClosestPoints, info *CollisionInfo) { dE2B := e2.b.p.Cross(n) // TODO + min isn't a complete fix - e1Denom := 1 / (dE1B - dE1A + math.SmallestNonzeroFloat64) - e2Denom := 1 / (dE2B - dE2A + math.SmallestNonzeroFloat64) + e1Denom := 1 / (dE1B - dE1A + 1e-15) + e2Denom := 1 / (dE2B - dE2A + 1e-15) // Project the endpoints of the two edges onto the opposing edge, clamping them as necessary. // Compare the projected points to the collision normal to see if the shapes overlap there. diff --git a/vector.go b/vector.go index 09049bd..cea4a8c 100644 --- a/vector.go +++ b/vector.go @@ -86,7 +86,7 @@ func (v Vector) Lerp(other Vector, t float64) Vector { } func (v Vector) Normalize() Vector { - return v.Mult(1.0 / (v.Length() + math.SmallestNonzeroFloat64)) + return v.Mult(1.0 / (v.Length() + 1e-15)) } func (v Vector) SLerp(other Vector, t float64) Vector { diff --git a/vector_test.go b/vector_test.go new file mode 100644 index 0000000..7974c62 --- /dev/null +++ b/vector_test.go @@ -0,0 +1,13 @@ +package cp + +import ( + "testing" +) + +func TestVector_Normalize(t *testing.T) { + v := Vector{} + u := v.Normalize() + if u.X != 0.0 || u.Y != 0.0 { + t.Errorf("Expected zero vector, got %v", u) + } +}