-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtools.go
51 lines (44 loc) · 974 Bytes
/
tools.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
package gcode
// StripComments will remove all inline and line comments from file.
func StripComments(f *File) {
cl := 0
for i := range f.Lines {
j := i - cl
l := f.Lines[j]
cd := 0
for ii := range l.Codes {
jj := ii - cd
c := l.Codes[jj]
// remove codes with comments
if c.Comment != "" {
l.Codes = append(l.Codes[:jj], l.Codes[jj+1:]...)
cd++
continue
}
}
// remove lines with comments or no codes
if l.Comment != "" || len(l.Codes) == 0 {
f.Lines = append(f.Lines[:j], f.Lines[j+1:]...)
cl++
continue
}
// update line
f.Lines[j] = l
}
}
// OffsetXYZ will offset all X, Y and Z G-Code values by the specified values.
func OffsetXYZ(f *File, x, y, z float64) {
for _, l := range f.Lines {
for i, c := range l.Codes {
if c.Letter == "X" {
c.Value += x
} else if c.Letter == "Y" {
c.Value += y
} else if c.Letter == "Z" {
c.Value += z
}
// update code
l.Codes[i] = c
}
}
}