FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Netduino-gcode/gcodeviewer/MathTestForm.cs at master · luyeh68/Netduino-gcode · GitHub
luyeh68
Netduino-gcode
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Netduino-gcode
/
gcodeviewer
/
MathTestForm.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
138 lines (106 loc) · 3.38 KB
Breadcrumbs
Netduino-gcode
/
gcodeviewer
/
MathTestForm.cs
Copy path
File metadata and controls
138 lines (106 loc) · 3.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
ComponentModel
;
using
System
.
Data
;
using
System
.
Drawing
;
using
System
.
Linq
;
using
System
.
Text
;
using
System
.
Windows
.
Forms
;
namespace
gcodeparser
{
public
partial
class
MathTestForm
:
Form
{
private
float
Tolerance
=
0.00001f
;
private
StringBuilder
mResult
=
new
StringBuilder
(
)
;
public
MathTestForm
(
)
{
InitializeComponent
(
)
;
}
private
void
MathTestForm_Load
(
object
sender
,
EventArgs
e
)
{
mResult
.
AppendFormat
(
"Tolerance: {0}
\r
\n
"
,
Tolerance
)
;
RunTest
(
)
;
ResultTextbox
.
Text
=
mResult
.
ToString
(
)
;
}
private
void
RunTest
(
)
{
TestCos
(
)
;
TestSin
(
)
;
TestAtan2
(
)
;
TestSqrt
(
)
;
}
private
void
TestSqrt
(
)
{
mResult
.
Append
(
"Testing Sqrt function
\r
\n
"
)
;
for
(
float
x
=
0
;
x
<
2000
;
x
+=
3.243f
)
{
Check
(
(
float
)
Math
.
Sqrt
(
x
)
,
Math2
.
Sqrt
(
x
)
,
"Sqrt: {0} != {1}"
)
;
}
}
private
void
TestCos
(
)
{
mResult
.
Append
(
"Testing Cos function
\r
\n
"
)
;
for
(
float
x
=
0
;
x
<
10f
;
x
+=
0.021f
)
{
Check
(
(
float
)
Math
.
Cos
(
x
)
,
Math2
.
Cos
(
x
)
,
"Cos: {0} != {1}"
)
;
}
}
private
void
TestSin
(
)
{
mResult
.
Append
(
"Testing Sin function
\r
\n
"
)
;
for
(
float
x
=
0
;
x
<
10f
;
x
+=
0.021f
)
{
Check
(
(
float
)
Math
.
Sin
(
x
)
,
Math2
.
Sin
(
x
)
,
"Sin: {0} != {1}"
)
;
}
}
private
void
TestAtan2
(
)
{
mResult
.
Append
(
"Testing Atan2 function
\r
\n
"
)
;
int
correct
=
0
;
int
total
=
0
;
for
(
float
x
=
0
;
x
<
5f
;
x
+=
0.11f
)
{
for
(
float
y
=
-
20f
;
y
<
20f
;
y
+=
0.105f
)
{
float
m
=
(
float
)
Math
.
Atan2
(
y
,
x
)
;
float
m2
=
Math2
.
Atan2
(
y
,
x
)
;
const
float
rad
=
180
/
3.141592654f
;
float
dm
=
m
*
rad
;
float
dm2
=
m2
*
rad
;
if
(
Check
(
x
,
y
,
dm
,
dm2
,
"Atan2: x {0}, y {1} | {2} != {3}"
)
)
correct
++
;
total
++
;
}
}
mResult
.
AppendFormat
(
"Atan2: Total: {0}, OK: {1}
\r
\n
"
,
total
,
correct
)
;
}
private
bool
Check
(
float
v1
,
float
v2
,
string
errorMsg
)
{
float
diff
=
(
float
)
Math
.
Abs
(
v1
-
v2
)
;
if
(
diff
>
Tolerance
)
{
PrintError
(
v1
,
v2
,
errorMsg
)
;
return
false
;
}
return
true
;
}
private
bool
Check
(
float
x
,
float
y
,
float
v1
,
float
v2
,
string
errorMsg
)
{
float
diff
=
(
float
)
Math
.
Abs
(
v1
-
v2
)
;
if
(
diff
>
Tolerance
)
{
PrintError
(
x
,
y
,
v1
,
v2
,
errorMsg
)
;
return
false
;
}
return
true
;
}
private
void
PrintError
(
float
x
,
float
y
,
float
v1
,
float
v2
,
string
message
)
{
mResult
.
AppendFormat
(
message
+
"
\r
\n
"
,
x
,
y
,
v1
,
v2
)
;
}
private
void
PrintError
(
float
v1
,
float
v2
,
string
message
)
{
//MessageBox.Show(string.Format(message, v1, v2));
mResult
.
AppendFormat
(
message
+
"
\r
\n
"
,
v1
,
v2
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL