-
Notifications
You must be signed in to change notification settings - Fork 2
/
vecang_test.go
83 lines (79 loc) · 2.14 KB
/
vecang_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2019, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mat32
import (
"testing"
)
func TestV3AngleTo(t *testing.T) {
ref := V3(1, 0, 0)
for ang := float32(0); ang < Pi*2; ang += Pi / 10 {
cos := Cos(ang)
sin := Sin(ang)
v := V3(cos, sin, 0)
vang := v.AngleTo(ref)
vcos := Cos(vang)
vsin := Sin(vang)
// cross := v.Cross(ref)
// fmt.Printf("ang: %v cross: %v\n", ang, cross)
if Abs(vcos-cos) > 1.0e-6 {
t.Errorf("Vec3.AngleTo: Cos: %v != orig Cos: %v\n", vcos, cos)
}
if Abs(vsin-sin) > 1.0e-6 {
t.Errorf("Vec3.AngleTo: Sin: %v != orig Sin: %v\n", vsin, sin)
}
}
ref = V3(0, 1, 0)
for ang := float32(0); ang < Pi*2; ang += Pi / 10 {
cos := Cos(ang)
sin := Sin(ang)
v := V3(0, cos, sin)
vang := v.AngleTo(ref)
vcos := Cos(vang)
vsin := Sin(vang)
// cross := v.Cross(ref)
// fmt.Printf("ang: %v cross: %v\n", ang, cross)
if Abs(vcos-cos) > 1.0e-6 {
t.Errorf("Vec3.AngleTo: Cos: %v != orig Cos: %v\n", vcos, cos)
}
if Abs(vsin-sin) > 1.0e-6 {
t.Errorf("Vec3.AngleTo: Sin: %v != orig Sin: %v\n", vsin, sin)
}
}
ref = V3(0, 0, 1)
for ang := float32(0); ang < Pi*2; ang += Pi / 10 {
cos := Cos(ang)
sin := Sin(ang)
v := V3(sin, 0, cos)
vang := v.AngleTo(ref)
vcos := Cos(vang)
vsin := Sin(vang)
// cross := v.Cross(ref)
// fmt.Printf("ang: %v cross: %v\n", ang, cross)
if Abs(vcos-cos) > 1.0e-6 {
t.Errorf("Vec3.AngleTo: Cos: %v != orig Cos: %v\n", vcos, cos)
}
if Abs(vsin-sin) > 1.0e-6 {
t.Errorf("Vec3.AngleTo: Sin: %v != orig Sin: %v\n", vsin, sin)
}
}
}
func TestV2AngleTo(t *testing.T) {
ref := V2(1, 0)
for ang := float32(0); ang < Pi*2; ang += Pi / 10 {
cos := Cos(ang)
sin := Sin(ang)
v := V2(cos, sin)
vang := v.AngleTo(ref)
vcos := Cos(vang)
vsin := Sin(vang)
// cross := v.Cross(ref)
// fmt.Printf("ang: %v cross: %v\n", ang, cross)
if Abs(vcos-cos) > 1.0e-6 {
t.Errorf("Vec2.AngleTo: Cos: %v != orig Cos: %v\n", vcos, cos)
}
if Abs(vsin-sin) > 1.0e-6 {
t.Errorf("Vec2.AngleTo: Sin: %v != orig Sin: %v\n", vsin, sin)
}
}
}