Skip to content

Commit

Permalink
Revert "FIX: Fixes dot() returning NaN. (#26)" (#29)
Browse files Browse the repository at this point in the history
This reverts commit 007106a.
  • Loading branch information
quartercastle committed Jul 22, 2023
1 parent 866b2f4 commit 50708e3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
22 changes: 2 additions & 20 deletions arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,11 @@ func dot(a, b []float64) float64 {
result, dimA, dimB := 0., len(a), len(b)

if dimA == 2 && dimB == 2 {
result = a[x]*b[x] + a[y]*b[y]
if result > 1 {
result = 1
} else if result < -1 {
result = -1
}
return result
return a[x]*b[x] + a[y]*b[y]
}

if dimA == 3 && dimB == 3 {
result = a[x]*b[x] + a[y]*b[y] + a[z]*b[z]
if result > 1 {
result = 1
} else if result < -1 {
result = -1
}
return result
return a[x]*b[x] + a[y]*b[y] + a[z]*b[z]
}

if dimA > dimB {
Expand All @@ -258,12 +246,6 @@ func dot(a, b []float64) float64 {
result += a[i] * b[i]
}

if result > 1 {
result = 1
} else if result < -1 {
result = -1
}

return result
}

Expand Down
17 changes: 0 additions & 17 deletions vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,3 @@ func TestSwizzling(t *testing.T) {
}

}

func TestDotNaN(t *testing.T) {
v1 := vec{1, 0, 0}
v2 := vec{0, 1, 0}

if v1.Dot(v2) != 0 {
t.Error("dot function did not return values expected")
}

v1 = vector.Vector{-0.9040721420170615, 0, 0.4273798802338293}
v2 = v1.Invert()

if math.IsNaN(v1.Dot(v2)) {
t.Error("dot function returned NaN")
}

}

0 comments on commit 50708e3

Please sign in to comment.