spatial/r3: implement Vec.Dot

This commit is contained in:
Sebastien Binet
2020-03-25 15:22:51 +01:00
parent c5a3c90294
commit 2321f504d0
2 changed files with 40 additions and 0 deletions

View File

@@ -77,3 +77,38 @@ func TestScale(t *testing.T) {
})
}
}
func TestDot(t *testing.T) {
for _, test := range []struct {
u, v Vec
want float64
}{
{Vec{1, 2, 3}, Vec{1, 2, 3}, 14},
{Vec{1, 0, 0}, Vec{1, 0, 0}, 1},
{Vec{1, 0, 0}, Vec{0, 1, 0}, 0},
{Vec{1, 0, 0}, Vec{0, 1, 1}, 0},
{Vec{1, 1, 1}, Vec{-1, -1, -1}, -3},
{Vec{1, 2, 2}, Vec{-0.3, 0.4, -1.2}, -1.9},
} {
t.Run("", func(t *testing.T) {
{
got := test.u.Dot(test.v)
if got != test.want {
t.Fatalf(
"error: %v · %v: got=%v, want=%v",
test.u, test.v, got, test.want,
)
}
}
{
got := test.v.Dot(test.u)
if got != test.want {
t.Fatalf(
"error: %v · %v: got=%v, want=%v",
test.v, test.u, got, test.want,
)
}
}
})
}
}