-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathconv_test.go
152 lines (115 loc) · 3.5 KB
/
conv_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// This file is generated from mgl32/conv_test.go; DO NOT EDIT
// Copyright 2014 The go-gl 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 mgl64
import (
"math"
"testing"
)
func TestCartesianToSphere(t *testing.T) {
t.Parallel()
v := Vec3{5, 12, 9}
r, theta, phi := CartesianToSpherical(v)
if !FloatEqualThreshold(r, 15.8114, 1e-4) {
t.Errorf("Got incorrect value for radius. Got: %f, expected: %f", r, 15.8114)
}
if !FloatEqualThreshold(theta, 0.965250852, 1e-4) {
t.Errorf("Got incorrect value for theta. Got: %f, expected: %f", theta, 0.965250852)
}
if !FloatEqualThreshold(phi, 1.1760046, 1e-4) {
t.Errorf("Got incorrect value for phi. Got: %f, expected: %f", phi, 1.1760046)
}
}
func TestSphereToCartesian(t *testing.T) {
t.Parallel()
v := Vec3{5, 12, 9}
result := SphericalToCartesian(15.8114, 0.965250852, 1.1760046)
if !v.ApproxEqualThreshold(result, 1e-4) {
t.Errorf("Got incorrect vector. Got: %v, Expected: %v", result, v)
}
}
func TestCartesianToCylinder(t *testing.T) {
t.Parallel()
v := Vec3{5, 12, 9}
rho, phi, z := CartesianToCylindical(v)
if !FloatEqualThreshold(rho, 13, 1e-4) {
t.Errorf("Got incorrect value for radius. Got: %f, expected: %f", rho, 13.)
}
if !FloatEqualThreshold(phi, 1.17601, 1e-4) {
t.Errorf("Got incorrect value for theta. Got: %f, expected: %f", phi, 1.17601)
}
if !FloatEqualThreshold(z, 9, 1e-4) {
t.Errorf("Got incorrect value for phi. Got: %f, expected: %f", z, 9.)
}
}
func TestCylinderToCartesian(t *testing.T) {
t.Parallel()
v := Vec3{5, 12, 9}
result := CylindricalToCartesian(13, 1.17601, 9)
if !v.ApproxEqualThreshold(result, 1e-4) {
t.Errorf("Got incorrect vector. Got: %v, expected: %v", result, v)
}
}
func TestCylinderToSphere(t *testing.T) {
t.Parallel()
r, theta, phi := CylindircalToSpherical(13, 1.17601, 9)
if !FloatEqualThreshold(r, 15.8114, 1e-4) {
t.Errorf("Got incorrect value for radius. Got: %f, expected: %f", r, 15.8114)
}
if !FloatEqualThreshold(theta, 0.965250852, 1e-4) {
t.Errorf("Got incorrect value for theta. Got: %f, expected: %f", theta, 0.965250852)
}
if !FloatEqualThreshold(phi, 1.1760046, 1e-4) {
t.Errorf("Got incorrect value for phi. Got: %f, expected: %f", phi, 1.1760046)
}
}
func TestSphereToCylinder(t *testing.T) {
t.Parallel()
rho, phi, z := SphericalToCylindrical(15.8114, 0.965250852, 1.1760046)
if !FloatEqualThreshold(rho, 13, 1e-4) {
t.Errorf("Got incorrect value for radius. Got: %f, expected: %f", rho, 13.)
}
if !FloatEqualThreshold(phi, 1.17601, 1e-4) {
t.Errorf("Got incorrect value for theta. Got: %f, expected: %f", phi, 1.17601)
}
if !FloatEqualThreshold(z, 9, 1e-4) {
t.Errorf("Got incorrect value for phi. Got: %f, expected: %f", z, 9.)
}
}
func TestDegToRad(t *testing.T) {
tests := []struct {
Deg, Rad float64
}{
{0, 0},
{90, math.Pi / 2},
{180, math.Pi},
{270, math.Pi + math.Pi/2},
{360, math.Pi * 2},
{-90, -math.Pi / 2},
{-360, -math.Pi * 2},
}
for _, c := range tests {
if r := DegToRad(c.Deg); r != c.Rad {
t.Errorf("DegToRad(%v) != %v (got %v)", c.Deg, c.Rad, r)
}
}
}
func TestRadToDeg(t *testing.T) {
tests := []struct {
Deg, Rad float64
}{
{0, 0},
{90, math.Pi / 2},
{180, math.Pi},
{270, math.Pi + math.Pi/2},
{360, math.Pi * 2},
{-90, -math.Pi / 2},
{-360, -math.Pi * 2},
}
for _, c := range tests {
if r := RadToDeg(c.Rad); r != c.Deg {
t.Errorf("RadToDeg(%v) != %v (got %v)", c.Rad, c.Deg, r)
}
}
}